mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-12-25 06:22:23 +00:00
Too much 404...
This commit is contained in:
parent
aa51a40cf6
commit
dcba832549
@ -6,6 +6,7 @@ import json
|
||||
import os
|
||||
import re
|
||||
import unicodedata
|
||||
from urllib.error import HTTPError
|
||||
import urllib.request
|
||||
|
||||
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")
|
||||
req = urllib.request.Request(api_url)
|
||||
req.add_header("Authorization", os.getenv("ISBNDB_KEY"))
|
||||
with urllib.request.urlopen(req) as url:
|
||||
data: dict = json.loads(url.read().decode())["book"]
|
||||
try:
|
||||
with urllib.request.urlopen(req) as url:
|
||||
data: dict = json.loads(url.read().decode())["book"]
|
||||
except HTTPError:
|
||||
return False
|
||||
print(data)
|
||||
data.setdefault("title", "")
|
||||
data.setdefault("date_published", "1970-01-01")
|
||||
|
Loading…
Reference in New Issue
Block a user