-
Notifications
You must be signed in to change notification settings - Fork 3
/
populatedb.py
29 lines (25 loc) · 1008 Bytes
/
populatedb.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
import requests, time, json
with open("books.json", encoding = "utf-8") as file:
books = json.load(file)
baseurl = "http://localhost:3333"
for abbrev, (title, length) in books.items():
print(f"\nSending {title}[{abbrev}] with {length} chapters = ", end = "")
response = requests.post(
f"{baseurl}/books",
json = {
"title": title,
"abbrev": abbrev,
"length": length
})
print(response.json())
with open(f"chapters/{abbrev}.json", encoding = "utf-8") as book:
chapters = json.load(book)
for chapter in chapters:
print(f"Populating {abbrev}:{chapter} = ", end = "")
for verse, text in enumerate(chapters[chapter]):
response = requests.post(
f"{baseurl}/books/{abbrev}/verses/{chapter}/{verse + 1}/", json = {
"text": text
})
print(response.json())
time.sleep(0.5)