21 lines
499 B
Python
21 lines
499 B
Python
from flask import Flask, request, redirect
|
|
from duckduckgo_search import DDGS
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/search')
|
|
def search():
|
|
query = request.args.get('q')
|
|
if not query:
|
|
return "Query parameter 'q' is missing.", 400
|
|
|
|
with DDGS() as ddgs:
|
|
results = ddgs.text(query, max_results=1)
|
|
for result in results:
|
|
return redirect(result['href'])
|
|
|
|
return "No results found.", 404
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5000)
|