user_agent.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
       ---
       user_agent.py (892B)
       ---
            1 # qutebrowser script to set a random user-agent on launch. Add the following to
            2 # your qutebrowser config.py file:
            3 #
            4 #        config.source('scripts/user_agent.py')
            5 #
            6 # You can download the most common user-agents with a script like this, I run
            7 # mine on cron every 3 days. :
            8 #
            9 # #!/bin/bash
           10 #
           11 # url='https://raw.githubusercontent.com/Kikobeats/top-user-agents/master/index.json'
           12 # path="$HOME/.config/qutebrowser/useragent_list.json"
           13 #
           14 # curl "$url" -o "$path"
           15 # awk '!/Firefox/' "$path" > /tmp/1 && mv /tmp/1 "$path"
           16 
           17 import random
           18 import json
           19 
           20 from pathlib import Path
           21 from qutebrowser.api import message
           22 
           23 home = str(config.configdir)
           24 agentfile = Path("{}/useragent_list.json".format(home))
           25 
           26 if agentfile.is_file():
           27     with open(agentfile, "r") as filehandle:
           28         agentList = json.load(filehandle)
           29 
           30     agent = random.choice(tuple(agentList))
           31     c.content.headers.user_agent = agent