-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (24 loc) · 817 Bytes
/
main.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
import requests
import json
from Utils import printJSON
from Book import Book
def initBooks() -> []:
try:
response = requests.get("https://ahadith-api.herokuapp.com/api/books/en")
# print(response.status_code)
# printJSON(response.json())
booksText = json.dumps(response.json(), sort_keys=True, indent=4)
booksData = json.loads(booksText)
books = []
for bookData in booksData['Books']:
book = Book(bookData['Book_ID'], bookData['Book_Name'])
books.append(book)
except requests.exceptions.RequestException as e:
print(e)
raise SystemExit(e)
return books
books = initBooks()
ahadith = books[0].getChapter(1).getAhadith(1)
print(f"Hadith {ahadith.id}")
print(ahadith.sanad)
print(ahadith.text)