Spaces:
Runtime error
Runtime error
DevsDoCode
commited on
Upload 3 files
Browse files- WebScout_DDC.py +36 -0
- app_flask.py +46 -0
- requirements.txt +4 -0
WebScout_DDC.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from webscout import WEBS
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def websearch_ddc(query, max_results=5, time_limit=5):
|
5 |
+
response = requests.get(f"https://oevortex-webscout-api.hf.space/api/search?q={query}&max_results={max_results}&timelimit={time_limit}&safesearch=off®ion=wt-wt")
|
6 |
+
return response.json()['results']
|
7 |
+
|
8 |
+
def attributes_ext(json_data):
|
9 |
+
|
10 |
+
# Initialize empty lists for each key
|
11 |
+
title = []
|
12 |
+
href = []
|
13 |
+
body = []
|
14 |
+
|
15 |
+
# Iterate over each item in the list and extract values for each key
|
16 |
+
for item in json_data:
|
17 |
+
title.append(item['title'])
|
18 |
+
href.append(item['href'])
|
19 |
+
body.append(item['body'])
|
20 |
+
|
21 |
+
return title, href, body
|
22 |
+
|
23 |
+
def main(query, max_results=10):
|
24 |
+
|
25 |
+
raw_output = websearch_ddc(query, max_results=max_results)
|
26 |
+
|
27 |
+
titles_list, urls_list, text_list = attributes_ext(raw_output)
|
28 |
+
|
29 |
+
return titles_list, urls_list, text_list
|
30 |
+
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
# Prompt the user for a search query
|
34 |
+
query = "ipl 2024"
|
35 |
+
titles_list, urls_list, text_list = main(query)
|
36 |
+
print(titles_list)
|
app_flask.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import WebScout_DDC
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
@app.route('/search', methods=['GET'])
|
7 |
+
def search():
|
8 |
+
|
9 |
+
# Extract query parameter
|
10 |
+
query = request.args.get('query')
|
11 |
+
|
12 |
+
# Extract additional parameters
|
13 |
+
max_results = int(request.args.get('max_results', 10))
|
14 |
+
|
15 |
+
if query:
|
16 |
+
# Call the main function with the specified parameters
|
17 |
+
titles_list, urls_list, text_list = WebScout_DDC.main(
|
18 |
+
query,
|
19 |
+
max_results=max_results,
|
20 |
+
)
|
21 |
+
|
22 |
+
# Create a dictionary containing the extracted attributes
|
23 |
+
response = {
|
24 |
+
'titles': titles_list,
|
25 |
+
'urls': urls_list,
|
26 |
+
'text': text_list
|
27 |
+
}
|
28 |
+
|
29 |
+
# Return the response as prettified JSON
|
30 |
+
return jsonify(response), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
31 |
+
else:
|
32 |
+
error_message = {
|
33 |
+
'developer_contact': {
|
34 |
+
'telegram': 'https://t.me/DevsDoCode',
|
35 |
+
'instagram': 'https://www.instagram.com/sree.shades_/',
|
36 |
+
'discord': 'https://discord.gg/ehwfVtsAts',
|
37 |
+
'linkedin': 'https://www.linkedin.com/in/developer-sreejan/',
|
38 |
+
'twitter': 'https://twitter.com/Anand_Sreejan'
|
39 |
+
},
|
40 |
+
'error': 'Oops! Something went wrong. Please contact the developer for assistance.'
|
41 |
+
}
|
42 |
+
return jsonify(error_message), 400
|
43 |
+
|
44 |
+
if __name__ == '__main__':
|
45 |
+
app.run(debug=True)
|
46 |
+
# Example Usage : http://127.0.0.1:5000/search?query=python%20tutorial&result_num=20&safe=False&types=web&types=video&extract_webpage=False
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
webscout==1.2.3
|
2 |
+
flask==3.0.0
|
3 |
+
gunicorn
|
4 |
+
orjson
|