/
temp.py
58 lines (41 loc) · 1.09 KB
/
temp.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
from GoogleNews import GoogleNews
import requests
def getNews(query):
googleNews = GoogleNews()
googleNews.search(query)
news = []
i = 0
number = min([len(googleNews.result()), 6])
for result in googleNews.result():
if (i > number):
break
n = {}
n["title"] = result['title']
n["description"] = result['desc']
n["link"] = result['link']
if (i == 0):
n["image"] = result['img']
news.append(n)
i += 1
googleNews.clear()
return news
def getBooks(name):
r = requests.get("http://openlibrary.org/search.json", {'q': name})
data = r.json()
docs = data['docs']
num = min(data['num_found'], 2)
books = []
i = 0
for doc in docs:
if (i >= num):
break
book = {}
book['title'] = doc['title']
book['publisher'] = doc['publisher']
book['authors'] = doc['author_name']
books.append(book)
i += 1
return books
if __name__ == '__main__':
query = input()
print(getBooks(query))