diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 698a289b7..0c3d9dde2 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1560,7 +1560,7 @@ class UserAgent(BaseType): # To update the following list of user agents, run the script 'ua_fetch.py'. # Vim-protip: Place your cursor below this comment and run - # :r!python scripts/ua_fetch.py + # :r!python scripts/dev/ua_fetch.py def complete(self): """Complete a list of common user agents.""" out = [ diff --git a/scripts/dev/ua_fetch.py b/scripts/dev/ua_fetch.py new file mode 100644 index 000000000..26aba6d10 --- /dev/null +++ b/scripts/dev/ua_fetch.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 lamarpavel +# Copyright 2015 Alexey Nabrodov (Averrin) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + + +"""Fetch list of popular user-agents. + +The script is based on a gist posted by github.com/averrin, the ouput of this +script is formatted to be pasted into configtypes.py. +""" + +import requests +from lxml import html # pylint: disable=import-error + +# Fetch list of popular user-agents and store the relevant strings +url = 'https://techblog.willshouse.com/2012/01/03/most-common-user-agents/' +page = requests.get(url) +page = html.fromstring(page.text) +path = '//*[@id="post-2229"]/div[2]/table/tbody' +table = page.xpath(path)[0] +indent = " " + +# Print function defition followed by an automatically fetched list of popular +# user agents and a few additional entries for diversity. +print("%sdef complete(self):" % indent) +print("%s\"\"\"Complete a list of common user agents.\"\"\"" % (2 * indent)) +print("%sout = [" % (2 * indent)) +for row in table[:12]: + ua = row[1].text_content() + browser = row[2].text_content() + print("%s(\'%s\',\n%s \"%s\")," % (3 * indent, ua, 3 * indent, browser)) +print(""" + ('Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) ' + 'AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 ' + 'Mobile/12B440 Safari/600.1.4', + "Mobile Safari 8.0 iOS"), + ('Mozilla/5.0 (Android; Mobile; rv:35.0) Gecko/35.0 Firefox/35.0', + "Firefox 35, Android"), + ('Mozilla/5.0 (Linux; Android 5.0.2; One Build/KTU84L.H4) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 ' + 'Chrome/37.0.0.0 Mobile Safari/537.36', + "Android Browser") +""") +print("%s]\n%sreturn out\n" % (2 * indent, 2 * indent)) diff --git a/scripts/ua_fetch.py b/scripts/ua_fetch.py deleted file mode 100644 index 9f3ab785e..000000000 --- a/scripts/ua_fetch.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: - -"""Fetch list of popular user-agents. - -The script is based on a gist posted by github.com/averrin, the ouput of this -script is formatted to be pasted into configtypes.py. -""" - -import requests -from lxml import html - -url = 'https://techblog.willshouse.com/2012/01/03/most-common-user-agents/' -page = requests.get(url) -page = html.fromstring(page.text) -path = '//*[@id="post-2229"]/div[2]/table/tbody' -table = page.xpath(path)[0] - -indent = " " -print("%sdef complete(self):" % indent) -print("%s\"\"\"Complete a list of common user agents.\"\"\"" % (2 * indent)) -print("%sout = [" % (2 * indent)) -for row in table[:12]: - ua = row[1].text_content() - browser = row[2].text_content() - print("%s(\'%s\',\n%s \"%s\")," % (3 * indent, ua, 3 * indent, browser)) -print("%s]\n%sreturn out\n" % (2 * indent, 2 * indent))