-
Notifications
You must be signed in to change notification settings - Fork 0
/
manga_service.py
28 lines (23 loc) · 999 Bytes
/
manga_service.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
import requests
from bs4 import BeautifulSoup
def get_mangadex_covers(name="Naruto", id="6b1eb93e-473a-4ab3-9922-1a66d2a29a4a"):
base_url = "https://uploads.mangadex.org/covers"
r = requests.get('https://api.mangadex.org/cover?manga[]={0}&limit=100&order[volume]=asc'.format(id))
print(r.json()['data'])
filtered = list(filter(lambda x: str(x['attributes']['volume']).isnumeric() and x != "0", r.json()['data']))
nbVolumes = len(filtered)
covers = []
for cover in filtered:
covers.append({
"title": "{0} #{1}".format(name, cover['attributes']['volume']),
"volume": cover['attributes']['volume'],
"url": "{0}/{1}/{2}".format(base_url, id, cover['attributes']['fileName']),
"notes": {
"note_1": 0,
"note_2": 0,
"note_3": 0
},
"points": 0
})
print("{0} volumes fetched.".format(nbVolumes))
return name, nbVolumes, covers