Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- #Access token:
- #7mbNq6GVWo0LiEQS7GCc
- address_id = 'https://the-one-api.dev/v2/book/5cf5805fb53e011a64671582/chapter'
- book_id = requests.get(address_id)
- if book_id.status_code == requests.codes.ok:
- #print("OK")
- book_id = book_id.json()
- with open("book_id.json", 'w', encoding = 'utf-8') as fl:
- fl.write(json.dumps(book_id, ensure_ascii = False, indent = 4))
- #"_id": "5cf5805fb53e011a64671582",
- # "name": "The Fellowship Of The Ring"
- from requests.structures import CaseInsensitiveDict
- url = "https://the-one-api.dev/v2/book/5cf5805fb53e011a64671582/chapter" #/5cf5805fb53e011a64671582/chapter
- headers = CaseInsensitiveDict()
- headers["Accept"] = "application/json"
- headers["Authorization"] = "Bearer 7mbNq6GVWo0LiEQS7GCc"
- resp = requests.get(url, headers=headers)
- #print(resp.status_code)
- if resp.status_code == requests.codes.ok:
- chapt = resp.json()
- all_chapt = {}
- cnt = 1
- for ch in chapt["docs"]:
- # if ch["book"] == "5cf5805fb53e011a64671582":
- all_chapt[cnt] = ch["chapterName"]
- cnt += 1
- chapt_num = len(all_chapt)
- ans_1 = {}
- ans_1["chapters"] = all_chapt
- ans_1["num_of_chapters"] = len(all_chapt)
- with open("N1.json", 'w', encoding = 'utf-8') as fl:
- fl.write(json.dumps(ans_1, ensure_ascii = False, indent = 4))
Add Comment
Please, Sign In to add comment