Minor refactor of filter class, updated tests, fixed html/css, added ua to config
parent
b5351c8502
commit
024552f2df
|
@ -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
|
||||
|
|
|
@ -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'])
|
||||
|
|
|
@ -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;
|
||||
|
@ -107,3 +112,9 @@ body {
|
|||
.open {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.ua-span {
|
||||
color: white;
|
||||
-webkit-box-decoration-break: clone;
|
||||
box-decoration-break: clone;
|
||||
}
|
|
@ -33,6 +33,10 @@
|
|||
<button id="config-collapsible" class="collapsible">Configuration</button>
|
||||
<div class="content">
|
||||
<div class="config-fields">
|
||||
<div class="config-div">
|
||||
<!-- TODO: Add option to regenerate user agent? -->
|
||||
<span class="ua-span">User Agent: {{ ua }}</span>
|
||||
</div>
|
||||
<div class="config-div">
|
||||
<label for="config-near">Near: </label>
|
||||
<input type="text" name="config-near" id="config-near" placeholder="City Name">
|
||||
|
@ -50,6 +54,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue