Initial commit
commit
6e7eef165e
|
@ -0,0 +1,3 @@
|
|||
venv/
|
||||
__pycache__/
|
||||
*.pyc
|
|
@ -0,0 +1,6 @@
|
|||
from flask import Flask
|
||||
import os
|
||||
|
||||
app = Flask(__name__, static_folder=os.path.dirname(os.path.abspath(__file__)) + '/static')
|
||||
|
||||
from app import routes
|
|
@ -0,0 +1,41 @@
|
|||
from app import app
|
||||
from flask import request, redirect, Response, render_template
|
||||
import os
|
||||
import pycurl
|
||||
from .url import url_parse
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/search', methods=['GET'])
|
||||
def search():
|
||||
q = request.args.get('q')
|
||||
if q is None or len(q) <= 0:
|
||||
return render_template('error.html')
|
||||
|
||||
b_obj = BytesIO()
|
||||
crl = pycurl.Curl()
|
||||
crl.setopt(crl.URL, 'https://www.google.com/search?q=' + url_parse(q))
|
||||
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.perform()
|
||||
crl.close()
|
||||
get_body = b_obj.getvalue()
|
||||
return render_template('search.html', response=get_body.decode("utf-8", 'ignore'))
|
||||
|
||||
|
||||
@app.route('/url', methods=['GET'])
|
||||
def url():
|
||||
q = request.args.get('q')
|
||||
if len(q) > 0 and 'http' in q:
|
||||
return redirect(q)
|
||||
else:
|
||||
return render_template('error.html')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0')
|
|
@ -0,0 +1,15 @@
|
|||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const searchBar = document.getElementById("search-bar");
|
||||
const searchBtn = document.getElementById("search-submit");
|
||||
|
||||
searchBar.addEventListener("keyup", function(event) {
|
||||
if (event.keyCode === 13) {
|
||||
event.preventDefault();
|
||||
searchBtn.click();
|
||||
}
|
||||
});
|
||||
|
||||
searchBtn.onclick = function() {
|
||||
window.location.href = '/search?q=' + encodeURI(searchBar.value);
|
||||
}
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
error parsing url
|
|
@ -0,0 +1,5 @@
|
|||
<script src="/static/js/controller.js"></script>
|
||||
|
||||
<label for="search-bar">Search: </label>
|
||||
<input type="text" id="search-bar" name="search-bar"/>
|
||||
<button id="search-submit" type="submit">Go</button>
|
|
@ -0,0 +1,3 @@
|
|||
<h1>Search</h1>
|
||||
|
||||
{{ response|safe }}
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
|
||||
def url_parse(str):
|
||||
return str.replace(' ', '+')
|
|
@ -0,0 +1,7 @@
|
|||
Click==7.0
|
||||
Flask==1.1.1
|
||||
itsdangerous==1.1.0
|
||||
Jinja2==2.10.3
|
||||
MarkupSafe==1.1.1
|
||||
pycurl==7.43.0.4
|
||||
Werkzeug==0.16.0
|
Loading…
Reference in New Issue