-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaterial_suggestions.py
More file actions
98 lines (72 loc) · 2.36 KB
/
Copy pathmaterial_suggestions.py
File metadata and controls
98 lines (72 loc) · 2.36 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import arxiv
import requests
from dateutil.parser import parse
from gnews import GNews
MAX_RESULTS = 10
def arxiv_sample(query):
print('arxiv_sample')
search = arxiv.Search(
query = query,
max_results = MAX_RESULTS,
sort_by = arxiv.SortCriterion.SubmittedDate
)
ret = []
for result in search.results():
ret.append({'title':result.title, 'published':result.published, 'link':result.entry_id, 'summary':result.summary})
return ret
def patents_view_sample(query):
print('patents_view_sample')
url = "https://api.patentsview.org/patents/query"
# Set the parameters for the API request
params = {
"q": '{"_text_any":{"patent_abstract":"%s"}}' % query,
"f": '["patent_title", "patent_date", "patent_abstract", "patent_number"]',
"o": '{"per_page": %d}' % MAX_RESULTS,
"s": '[{"patent_date":"desc"}]',
}
response = requests.get(url, params=params)
if response.status_code == 200:
data = response.json()
results = data.get('patents', [])
ret = []
for patent in results:
ret.append({
'title':patent.get('patent_title', 'Not Found'),
'date':patent.get('patent_date', 'Not Found'),
'number':patent.get('patent_number', 'Not Found'),
'summary':patent.get('patent_abstract', 'Not Found')
})
return ret
else:
raise f"Error fetching data from PatentsView API: {response.status_code}"
def arxiv_explorer_sample(query):
print('arxiv_explorer_sample')
url = 'https://us-west1-semanticxplorer.cloudfunctions.net/semantic-xplorer-db'
resp = requests.get(url, params={'query': query})
elems = []
for el in resp.json():
url = 'https://arxiv.org/abs/' + el['id']
el = el['metadata']
elems.append({'title': el['title'], 'date': parse(el['date']), 'url': url, 'abstract': el['abstract']})
elems.sort(key=lambda el: el['date'], reverse=True)
elems = elems[:MAX_RESULTS]
return elems
def google_news_sample(query):
print('google_news_sample')
google_news = GNews()
google_news.max_results = MAX_RESULTS
news = google_news.get_news(query)
ret = []
for new in news:
ret.append({
'title':new['title'], 'date':new['published date'],
'description':new['description'], 'url':new['url']}
)
return ret
def main():
print(arxiv_sample('quantum'))
print(arxiv_explorer_sample('trying something unusual'))
print(patents_view_sample('electric car'))
print(google_news_sample('distributed databases'))
if __name__ == '__main__':
main()