mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-11-26 20:47:10 +00:00
Too much 404...
This commit is contained in:
parent
aa51a40cf6
commit
dcba832549
@ -6,6 +6,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
from urllib.error import HTTPError
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
@ -95,8 +96,11 @@ class MediaAdminForm(ModelForm):
|
|||||||
api_url = "https://api2.isbndb.com/book/" + str(isbn) + "?Authorization=" + os.getenv("ISBNDB_KEY")
|
api_url = "https://api2.isbndb.com/book/" + str(isbn) + "?Authorization=" + os.getenv("ISBNDB_KEY")
|
||||||
req = urllib.request.Request(api_url)
|
req = urllib.request.Request(api_url)
|
||||||
req.add_header("Authorization", os.getenv("ISBNDB_KEY"))
|
req.add_header("Authorization", os.getenv("ISBNDB_KEY"))
|
||||||
with urllib.request.urlopen(req) as url:
|
try:
|
||||||
data: dict = json.loads(url.read().decode())["book"]
|
with urllib.request.urlopen(req) as url:
|
||||||
|
data: dict = json.loads(url.read().decode())["book"]
|
||||||
|
except HTTPError:
|
||||||
|
return False
|
||||||
print(data)
|
print(data)
|
||||||
data.setdefault("title", "")
|
data.setdefault("title", "")
|
||||||
data.setdefault("date_published", "1970-01-01")
|
data.setdefault("date_published", "1970-01-01")
|
||||||
|
Loading…
Reference in New Issue
Block a user