-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchinator.py
75 lines (62 loc) · 1.94 KB
/
searchinator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from GoogleNews import GoogleNews
from datetime import datetime as dt
import datetime
import json
categories = ["policies", "education", "biology", "economy", "statistics", "donations"]
def v1(county, state):
location = (county + ", " + state)
urls = [[],[],[],[],[],[]]
now = dt.now()
today_date = now.strftime("%m/%d/%Y")
week_ago_date = (now - datetime.timedelta(days = 7)).strftime("%m/%d/%Y")
googlenews = GoogleNews()
googlenews.setlang('en')
googlenews = GoogleNews(start=week_ago_date,end=today_date)
queries = [
str(location) + " COVID-19 " + categories[0] + " news",
str(location) + " COVID-19 " + categories[1] + " news",
"Global COVID-19 Vaccine",
str(location) + " COVID-19 " + categories[3] + " news",
str(location) + " COVID-19 " + categories[4] + " news",
str(location) + " COVID-19 " + categories[5]
]
for query in queries:
index = queries.index(query)
googlenews = GoogleNews()
googlenews.setlang('en')
googlenews = GoogleNews(start=week_ago_date,end=today_date)
googlenews.search(query)
results = googlenews.result()
res = results
for i in range(len(res)-1):
urls[index].append(results[i]['link'])
success_string = "True"
data = {
"county": county,
"state": state,
"success": success_string,
# "time": {
# "timestamp": now,
# },
"data": {
"policies": {
"urls": urls[0],
},
"education": {
"urls": urls[1],
},
"biology": {
"urls": urls[2],
},
"economy": {
"urls": urls[3],
},
"statistics": {
"urls": urls[4],
},
"donations": {
"urls": urls[5],
},
},
}
return data