Minor fix for filtering by time range

main
Ben Busby 2020-04-05 16:37:35 -06:00
parent 254c987254
commit 9c0b4a7f58
1 changed files with 8 additions and 2 deletions

View File

@ -57,10 +57,16 @@ def search():
return render_template('error.html')
# Use :past(hour/day/week/month/year) if available
# example search "new restaurants :pastmonth"
# example search "new restaurants :past month"
tbs = ''
# if 'tbs' in request.args:
# tbs = '&tbs=' + request.args.get('tbs')
# q = q.replace(q.split(':past', 1)[-1], '').replace(':past', '')
if ':past' in q:
tbs = '&tbs=qdr:' + str.lower(q.split(':past', 1)[-1][0])
time_range = str.strip(q.split(':past', 1)[-1])
tbs = '&tbs=qdr:' + str.lower(time_range[0])
# Ensure search query is parsable
q = urlparse.quote(q)
# Pass along type of results (news, images, books, etc)