From 0300eab6dfe880d9745835510deab1a044854c21 Mon Sep 17 00:00:00 2001 From: Ben Busby <33362396+benbusby@users.noreply.github.com> Date: Sun, 3 May 2020 19:32:47 -0600 Subject: [PATCH] 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. --- README.md | 4 ++++ app/filter.py | 22 ++++++++++++++++++++++ app/request.py | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 616ccc4..d83baef 100644 --- a/README.md +++ b/README.md @@ -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/)) - Only needed if you intend on deploying the app as a Docker image - [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) - Only needed if you want to deploy the app to Heroku but don't want to use the deploy button shortcut. diff --git a/app/filter.py b/app/filter.py index efa786f..c2a4a13 100644 --- a/app/filter.py +++ b/app/filter.py @@ -6,6 +6,12 @@ import urllib.parse as urlparse from urllib.parse import parse_qs SKIP_ARGS = ['ref_src', 'utm'] +FULL_RES_IMG = '
Full Image' +GOOG_IMG = '/images/branding/searchlogo/1x/googlelogo' +LOGO_URL = GOOG_IMG + '_desk' +BLANK_B64 = ''' +data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkwAIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC +''' class Filter: @@ -68,9 +74,21 @@ class Filter: img_src = img['src'] if img_src.startswith('//'): 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()) 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): # Remove unnecessary button(s) @@ -126,6 +144,10 @@ class Filter: link_args = parse_qs(parsed_link.query) safe_args = {} + if len(link_args) == 0 and len(parsed_link) > 0: + a['href'] = query_link + continue + for arg in link_args.keys(): if arg in SKIP_ARGS: continue diff --git a/app/request.py b/app/request.py index 536b994..471f4f4 100644 --- a/app/request.py +++ b/app/request.py @@ -80,4 +80,4 @@ class Request: if return_bytes: return b_obj.getvalue() else: - return b_obj.getvalue().decode('utf-8', 'ignore') + return b_obj.getvalue().decode('unicode-escape', 'ignore')