From 024552f2df990ed02b5cb4442f26542fc2ba90db Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Thu, 16 Apr 2020 10:01:02 -0600 Subject: [PATCH] Minor refactor of filter class, updated tests, fixed html/css, added ua to config --- app/filter.py | 13 ++++--------- app/routes.py | 21 +++++++++++++-------- app/static/css/main.css | 11 +++++++++++ app/templates/index.html | 33 +++++++++++++++++++-------------- test/test_results.py | 2 -- test/test_routes.py | 8 ++++---- 6 files changed, 51 insertions(+), 37 deletions(-) diff --git a/app/filter.py b/app/filter.py index 1fd8c1b..3c21bf8 100644 --- a/app/filter.py +++ b/app/filter.py @@ -6,18 +6,13 @@ from urllib.parse import parse_qs class Filter: def __init__(self, mobile=False, config=None): - self.mobile = False - self.dark_mode = False - self.nojs = False - self.near_city = None - if config is None: config = {} - near_city = config['near'] if 'near' in config else None - dark_mode = config['dark_mode'] if 'dark_mode' in config else False - nojs = config['nojs'] if 'nojs' in config else False - mobile = mobile + self.near_city = config['near'] if 'near' in config else None + self.dark_mode = config['dark_mode'] if 'dark_mode' in config else False + self.nojs = config['nojs'] if 'nojs' in config else False + self.mobile = mobile def reskin(self, page): # Aesthetic only re-skinning diff --git a/app/routes.py b/app/routes.py index ac82867..39e4089 100644 --- a/app/routes.py +++ b/app/routes.py @@ -11,12 +11,8 @@ import urllib.parse as urlparse app.config['APP_ROOT'] = os.getenv('APP_ROOT', os.path.dirname(os.path.abspath(__file__))) app.config['STATIC_FOLDER'] = os.getenv('STATIC_FOLDER', os.path.join(app.config['APP_ROOT'], 'static')) -# Get Mozilla Firefox rhyme (important) and form a new user agent -mozilla = rhyme.get_rhyme('Mo') + 'zilla' -firefox = rhyme.get_rhyme('Fire') + 'fox' - -MOBILE_UA = mozilla + '/5.0 (Android 4.20; Mobile; rv:54.0) Gecko/54.0 ' + firefox + '/59.0' -DESKTOP_UA = mozilla + '/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Mobile ' + firefox + '/59.0' +MOBILE_UA = '{}/5.0 (Android 0; Mobile; rv:54.0) Gecko/54.0 {}/59.0' +DESKTOP_UA = '{}/5.0 (X11; {} x86_64; rv:75.0) Gecko/20100101 {}/75.0' # Base search url SEARCH_URL = 'https://www.google.com/search?gbv=1&q=' @@ -25,7 +21,16 @@ user_config = json.load(open(app.config['STATIC_FOLDER'] + '/config.json')) def get_ua(user_agent): - return MOBILE_UA if ('Android' in user_agent or 'iPhone' in user_agent) else DESKTOP_UA + is_mobile = 'Android' in user_agent or 'iPhone' in user_agent + + mozilla = rhyme.get_rhyme('Mo') + rhyme.get_rhyme('zilla') + firefox = rhyme.get_rhyme('Fire') + rhyme.get_rhyme('fox') + linux = rhyme.get_rhyme('Lin') + 'ux' + + if is_mobile: + return MOBILE_UA.format(mozilla, firefox) + else: + return DESKTOP_UA.format(mozilla, linux, firefox) def send_request(curl_url, ua): @@ -47,7 +52,7 @@ def send_request(curl_url, ua): @app.route('/', methods=['GET']) def index(): bg = '#000' if 'dark' in user_config and user_config['dark'] else '#fff' - return render_template('index.html', bg=bg) + return render_template('index.html', bg=bg, ua=get_ua(request.headers.get('User-Agent'))) @app.route('/search', methods=['GET']) diff --git a/app/static/css/main.css b/app/static/css/main.css index eeb1fc3..f019a15 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -63,7 +63,12 @@ body { padding: 5px; } +button::-moz-focus-inner { + border: 0; +} + .collapsible { + outline: 0; background-color: rgba(0,0,0,0); color: #685e79; cursor: pointer; @@ -106,4 +111,10 @@ body { .open { padding-bottom: 20px; +} + +.ua-span { + color: white; + -webkit-box-decoration-break: clone; + box-decoration-break: clone; } \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html index a03cf77..0210c4f 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -33,20 +33,25 @@
-
- - -
-
- - -
-
- - -
-
- +
+ + User Agent: {{ ua }} +
+
+ + +
+
+ + +
+
+ + +
+
+ +
diff --git a/test/test_results.py b/test/test_results.py index e67f57a..18a0217 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -1,9 +1,7 @@ from bs4 import BeautifulSoup from app.filter import Filter -import json from datetime import datetime from dateutil.parser import * -from test.conftest import client def get_search_results(data): diff --git a/test/test_routes.py b/test/test_routes.py index bcf9991..525e029 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -1,10 +1,10 @@ import json -from test.conftest import client +import random demo_config = { - 'near': 'Seattle', - 'dark_mode': 0, - 'nojs': 0 + 'near': random.choice(['Seattle', 'New York', 'San Francisco']), + 'dark_mode': random.getrandbits(1), + 'nojs': random.getrandbits(1) }