flask_app.py
· 1.2 KiB · Python
Raw
from flask import Flask, send_file, request
from duckduckgo_search import DDGS
app = Flask(__name__)
@app.route('/use')
def ushome():
return send_file("use.html", mimetype='text/html')
@app.route('/use/search')
def usearch():
result = DDGS().text(request.args.get('q'))
html = """<!DOCTYPE html>
<html data-bs-theme="dark" class="container text-white bg-dark">
<head>
<title>""" + request.args.get('q') + """ - USE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name='description' content='Search engine with maximum compatibility.'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<head>
</head>
<body class="container text-white bg-dark">
<a href="/use"><img alt=UnnamedSearchEngine></a>
<form action=/use/search><input class="form-control bg-dark text-white" name=q type=text value=\"""" + request.args.get('q') + """\"><input class="btn btn-primary" type=submit value="Web search"></form><hr>"""
for i in result:
html += """<div class="container bg-dark text-white">
<a href=\""""+i['href']+"""\"><h3>"""+i['title']+"""</h3><p>"""+i['href']+"""</p></a>
<p>"""+i['body']+"""</p>
</div>"""
return html
| 1 | from flask import Flask, send_file, request |
| 2 | from duckduckgo_search import DDGS |
| 3 | app = Flask(__name__) |
| 4 | |
| 5 | @app.route('/use') |
| 6 | def ushome(): |
| 7 | return send_file("use.html", mimetype='text/html') |
| 8 | |
| 9 | @app.route('/use/search') |
| 10 | def usearch(): |
| 11 | result = DDGS().text(request.args.get('q')) |
| 12 | html = """<!DOCTYPE html> |
| 13 | <html data-bs-theme="dark" class="container text-white bg-dark"> |
| 14 | <head> |
| 15 | <title>""" + request.args.get('q') + """ - USE</title> |
| 16 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 17 | <meta name='description' content='Search engine with maximum compatibility.'> |
| 18 | <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"> |
| 19 | <head> |
| 20 | </head> |
| 21 | <body class="container text-white bg-dark"> |
| 22 | <a href="/use"><img alt=UnnamedSearchEngine></a> |
| 23 | <form action=/use/search><input class="form-control bg-dark text-white" name=q type=text value=\"""" + request.args.get('q') + """\"><input class="btn btn-primary" type=submit value="Web search"></form><hr>""" |
| 24 | for i in result: |
| 25 | html += """<div class="container bg-dark text-white"> |
| 26 | <a href=\""""+i['href']+"""\"><h3>"""+i['title']+"""</h3><p>"""+i['href']+"""</p></a> |
| 27 | <p>"""+i['body']+"""</p> |
| 28 | </div>""" |
| 29 | return html |
use.html
· 744 B · HTML
Raw
<!DOCTYPE html>
<html data-bs-theme="dark" class="container text-white bg-dark">
<head>
<title>UnnamedSearchEngine</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name='description' content='Search engine with maximum compatibility.'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<head>
</head>
<body class="container text-white bg-dark">
<center>
<center>
<img alt="Unnamed Search Engine">
<hr>
<form action=/use/search>
<input name=q class="form-control text-white bg-dark" placeholder=Search...>
<br>
<input type=submit value="Web Search" class="btn btn-primary">
</form>
</center>
</body>
</html>
| 1 | <!DOCTYPE html> |
| 2 | <html data-bs-theme="dark" class="container text-white bg-dark"> |
| 3 | <head> |
| 4 | <title>UnnamedSearchEngine</title> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | <meta name='description' content='Search engine with maximum compatibility.'> |
| 7 | <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"> |
| 8 | <head> |
| 9 | </head> |
| 10 | <body class="container text-white bg-dark"> |
| 11 | <center> |
| 12 | <center> |
| 13 | <img alt="Unnamed Search Engine"> |
| 14 | <hr> |
| 15 | <form action=/use/search> |
| 16 | <input name=q class="form-control text-white bg-dark" placeholder=Search...> |
| 17 | <br> |
| 18 | <input type=submit value="Web Search" class="btn btn-primary"> |
| 19 | </form> |
| 20 | </center> |
| 21 | </body> |
| 22 | </html> |