Commit aa51a40c authored by ynerant's avatar ynerant

Wrong use of ISBNDB API

parent 263b4cff
Pipeline #4241 failed with stages
in 3 minutes and 32 seconds
......@@ -96,8 +96,13 @@ class MediaAdminForm(ModelForm):
req = urllib.request.Request(api_url)
req.add_header("Authorization", os.getenv("ISBNDB_KEY"))
with urllib.request.urlopen(req) as url:
data = json.loads(url.read().decode())
data: dict = json.loads(url.read().decode())["book"]
print(data)
data.setdefault("title", "")
data.setdefault("date_published", "1970-01-01")
data.setdefault("pages", 0)
data.setdefault("authors", [])
data.setdefault("image", "")
self.cleaned_data["title"] = data["title"]
self.cleaned_data["published_date"] = data["date_published"][:10]
self.cleaned_data["number_of_pages"] = data["pages"]
......
......@@ -46,4 +46,4 @@ class Command(BaseCommand):
except Exception as e:
self.stderr.write(self.style.WARNING(
"An error occured while importing ISBN {isbn}: {error}"
.format(isbn=isbn, error=str(e))))
.format(isbn=isbn, error=str(e.__class__) + "(" + str(e) + ")")))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment