Improved handling of default country

Also added fallback 1px empty gif as a replacement for images that fail
to load
This commit is contained in:
Ben Busby 2020-05-23 14:23:20 -06:00
parent 387e19bba6
commit 4bf013ccd0
3 changed files with 21 additions and 11 deletions

View File

@ -51,6 +51,7 @@ class Config:
]
COUNTRIES = [
{'name': 'Default (use server location)', 'value': ''},
{'name': 'Afghanistan', 'value': 'countryAF'},
{'name': 'Albania', 'value': 'countryAL'},
{'name': 'Algeria', 'value': 'countryDZ'},

View File

@ -46,7 +46,7 @@ def gen_query(query, args, config, near_city=None):
param_dict['start'] = '&start=' + args.get('start')
# Search for results near a particular city, if available
if near_city is not None:
if near_city:
param_dict['near'] = '&near=' + urlparse.quote(near_city)
# Set language for results (lr) and interface (hl)

View File

@ -3,6 +3,7 @@ from app.filter import Filter, get_first_link
from app.models.config import Config
from app.request import Request, gen_query
import argparse
import base64
from bs4 import BeautifulSoup
from cryptography.fernet import Fernet, InvalidToken
from flask import g, make_response, request, redirect, render_template, send_file
@ -10,6 +11,7 @@ from functools import wraps
import io
import json
import os
from pycurl import error as pycurl_error
import urllib.parse as urlparse
import waitress
@ -163,6 +165,8 @@ def imgres():
def tmp():
cipher_suite = Fernet(app.secret_key)
img_url = cipher_suite.decrypt(request.args.get('image_url').encode()).decode()
try:
file_data = g.user_request.send(base_url=img_url, return_bytes=True)
tmp_mem = io.BytesIO()
tmp_mem.write(file_data)
@ -174,6 +178,11 @@ def tmp():
attachment_filename='tmp.png',
mimetype='image/png'
)
except pycurl_error:
pass
empty_gif = base64.b64decode('R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==')
return send_file(io.BytesIO(empty_gif), mimetype='image/gif')
@app.route('/window')