Added tbm (images/news/etc) handling, updated front page and search controls

main
Ben Busby 2020-01-21 18:07:08 -07:00
parent 6e7eef165e
commit 1e1bb4a55a
4 changed files with 16 additions and 6 deletions

View File

@ -17,9 +17,13 @@ def search():
if q is None or len(q) <= 0: if q is None or len(q) <= 0:
return render_template('error.html') return render_template('error.html')
tbm = ''
if 'tbm' in request.args:
tbm = '&tbm=' + request.args.get('tbm')
b_obj = BytesIO() b_obj = BytesIO()
crl = pycurl.Curl() crl = pycurl.Curl()
crl.setopt(crl.URL, 'https://www.google.com/search?q=' + url_parse(q)) crl.setopt(crl.URL, 'https://www.google.com/search?q=' + url_parse(q) + tbm)
crl.setopt(crl.USERAGENT, 'Brozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 LizzieMcGuirefox/59.0') crl.setopt(crl.USERAGENT, 'Brozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 LizzieMcGuirefox/59.0')
crl.setopt(crl.WRITEDATA, b_obj) crl.setopt(crl.WRITEDATA, b_obj)
crl.perform() crl.perform()

View File

@ -2,6 +2,10 @@ document.addEventListener("DOMContentLoaded", function() {
const searchBar = document.getElementById("search-bar"); const searchBar = document.getElementById("search-bar");
const searchBtn = document.getElementById("search-submit"); const searchBtn = document.getElementById("search-submit");
// Automatically focus on search field
searchBar.focus();
searchBar.select();
searchBar.addEventListener("keyup", function(event) { searchBar.addEventListener("keyup", function(event) {
if (event.keyCode === 13) { if (event.keyCode === 13) {
event.preventDefault(); event.preventDefault();

View File

@ -1,5 +1,9 @@
<script src="/static/js/controller.js"></script> <script src="/static/js/controller.js"></script>
<link rel="stylesheet" href="/static/css/main.css">
<label for="search-bar">Search: </label> <div>
<input type="text" id="search-bar" name="search-bar"/> <h1>No-AMP Search</h1>
<button id="search-submit" type="submit">Go</button>
<input type="text" id="search-bar" name="search-bar"/>
<button id="search-submit" type="submit">Go</button>
</div>

View File

@ -1,3 +1 @@
<h1>Search</h1>
{{ response|safe }} {{ response|safe }}