fingerprint.py - dotfiles - These are my dotfiles. There are many like it, but these are mine.
 (HTM) git clone git://jay.scot/dotfiles
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
       fingerprint.py (1423B)
       ---
            1 import random
            2 import json
            3 import datetime
            4 
            5 from pathlib import Path
            6 from qutebrowser.api import message, interceptor
            7 
            8 home = str(config.configdir)
            9 agentfile = Path("{}/useragent_list.json".format(home))
           10 
           11 fp_timer = datetime.datetime.now() + datetime.timedelta(minutes=1)
           12 
           13 if agentfile.is_file():
           14     with open(agentfile, "r") as filehandle:
           15         agentList = json.load(filehandle)
           16 
           17 
           18 def fingerprint_getheader(agent):
           19 
           20     FP_HTTP_HEADER = {
           21         "Firefox": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
           22         "Chrome": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
           23         "Edge": "text/html, application/xhtml+xml, image/jxr, */*",
           24         "Opera": "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1",
           25         "Safari": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
           26     }
           27 
           28     for a, h in FP_HTTP_HEADER.items():
           29         if "{a}" in agent:
           30             return h
           31 
           32 
           33 def fingerprint(info: interceptor.Request):
           34     global fp_timer
           35 
           36     if fp_timer < datetime.datetime.now():
           37         fp_timer = datetime.datetime.now() + datetime.timedelta(minutes=1)
           38         agent = random.choice(tuple(agentList))
           39         c.content.headers.user_agent = agent
           40         c.content.headers.custom = {"accept": fingerprint_getheader(agent)}
           41 
           42 
           43 interceptor.register(fingerprint)