Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Base de données Mediatek
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mediatek
Base de données Mediatek
Commits
aa51a40c
Commit
aa51a40c
authored
Oct 03, 2020
by
ynerant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrong use of ISBNDB API
parent
263b4cff
Pipeline
#4241
failed with stages
in 3 minutes and 32 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
2 deletions
+7
-2
media/forms.py
media/forms.py
+6
-1
media/management/commands/import_future_media.py
media/management/commands/import_future_media.py
+1
-1
No files found.
media/forms.py
View file @
aa51a40c
...
@@ -96,8 +96,13 @@ class MediaAdminForm(ModelForm):
...
@@ -96,8 +96,13 @@ class MediaAdminForm(ModelForm):
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
:
with
urllib
.
request
.
urlopen
(
req
)
as
url
:
data
=
json
.
loads
(
url
.
read
().
decode
())
data
:
dict
=
json
.
loads
(
url
.
read
().
decode
())[
"book"
]
print
(
data
)
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
[
"title"
]
=
data
[
"title"
]
self
.
cleaned_data
[
"published_date"
]
=
data
[
"date_published"
][:
10
]
self
.
cleaned_data
[
"published_date"
]
=
data
[
"date_published"
][:
10
]
self
.
cleaned_data
[
"number_of_pages"
]
=
data
[
"pages"
]
self
.
cleaned_data
[
"number_of_pages"
]
=
data
[
"pages"
]
...
...
media/management/commands/import_future_media.py
View file @
aa51a40c
...
@@ -46,4 +46,4 @@ class Command(BaseCommand):
...
@@ -46,4 +46,4 @@ class Command(BaseCommand):
except
Exception
as
e
:
except
Exception
as
e
:
self
.
stderr
.
write
(
self
.
style
.
WARNING
(
self
.
stderr
.
write
(
self
.
style
.
WARNING
(
"An error occured while importing ISBN {isbn}: {error}"
"An error occured while importing ISBN {isbn}: {error}"
.
format
(
isbn
=
isbn
,
error
=
str
(
e
)
)))
.
format
(
isbn
=
isbn
,
error
=
str
(
e
.
__class__
)
+
"("
+
str
(
e
)
+
")"
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment