Updated formatting and setup instructions

Switched encoding from utf-8 to unicode-escape in an effort to support multiple
languages besides English.

Updated image results page formatting to fix bad image links (added TODO
for adding full res image link for each image result).

Updated README to include libcurl and libssl install instructions for
manual setup.
main
Ben Busby 2020-05-03 19:32:47 -06:00
parent 39c475af21
commit 0300eab6df
3 changed files with 27 additions and 1 deletions

View File

@ -42,6 +42,10 @@ If deploying manually:
- Docker ([Windows](https://docs.docker.com/docker-for-windows/install/), [macOS](https://docs.docker.com/docker-for-mac/install/), [Ubuntu](https://docs.docker.com/engine/install/ubuntu/), [other Linux distros](https://docs.docker.com/engine/install/binaries/)) - Docker ([Windows](https://docs.docker.com/docker-for-windows/install/), [macOS](https://docs.docker.com/docker-for-mac/install/), [Ubuntu](https://docs.docker.com/engine/install/ubuntu/), [other Linux distros](https://docs.docker.com/engine/install/binaries/))
- Only needed if you intend on deploying the app as a Docker image - Only needed if you intend on deploying the app as a Docker image
- [Python3](https://www.python.org/downloads/) - [Python3](https://www.python.org/downloads/)
- `libcurl4-openssl-dev` and `libssl-dev`
- macOS: `brew install openssl curl-openssl`
- Ubuntu: `sudo apt-get install -y libcurl4-openssl-dev libssl-dev`
- Arch: `pacman -S curl openssl`
- [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) - [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli)
- Only needed if you want to deploy the app to Heroku but don't want to use the deploy button shortcut. - Only needed if you want to deploy the app to Heroku but don't want to use the deploy button shortcut.

View File

@ -6,6 +6,12 @@ import urllib.parse as urlparse
from urllib.parse import parse_qs from urllib.parse import parse_qs
SKIP_ARGS = ['ref_src', 'utm'] SKIP_ARGS = ['ref_src', 'utm']
FULL_RES_IMG = '<br/><a href="{}">Full Image</a>'
GOOG_IMG = '/images/branding/searchlogo/1x/googlelogo'
LOGO_URL = GOOG_IMG + '_desk'
BLANK_B64 = '''
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkwAIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC
'''
class Filter: class Filter:
@ -68,9 +74,21 @@ class Filter:
img_src = img['src'] img_src = img['src']
if img_src.startswith('//'): if img_src.startswith('//'):
img_src = 'https:' + img_src img_src = 'https:' + img_src
elif img_src.startswith(GOOG_IMG):
# Special rebranding for image search results
if img_src.startswith(LOGO_URL):
img['src'] = '/static/img/logo.png'
img['height'] = 40
else:
img['src'] = BLANK_B64
continue
enc_src = Fernet(self.secret_key).encrypt(img_src.encode()) enc_src = Fernet(self.secret_key).encrypt(img_src.encode())
img['src'] = '/tmp?image_url=' + enc_src.decode() img['src'] = '/tmp?image_url=' + enc_src.decode()
# TODO: Non-mobile image results link to website instead of image
# if not self.mobile:
# img.append(BeautifulSoup(FULL_RES_IMG.format(img_src), 'html.parser'))
def update_styling(self, soup): def update_styling(self, soup):
# Remove unnecessary button(s) # Remove unnecessary button(s)
@ -126,6 +144,10 @@ class Filter:
link_args = parse_qs(parsed_link.query) link_args = parse_qs(parsed_link.query)
safe_args = {} safe_args = {}
if len(link_args) == 0 and len(parsed_link) > 0:
a['href'] = query_link
continue
for arg in link_args.keys(): for arg in link_args.keys():
if arg in SKIP_ARGS: if arg in SKIP_ARGS:
continue continue

View File

@ -80,4 +80,4 @@ class Request:
if return_bytes: if return_bytes:
return b_obj.getvalue() return b_obj.getvalue()
else: else:
return b_obj.getvalue().decode('utf-8', 'ignore') return b_obj.getvalue().decode('unicode-escape', 'ignore')