Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
django-panik-emissions
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
radiopanik
django-panik-emissions
Commits
030b676f
Commit
030b676f
authored
Dec 26, 2019
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
load-from-drupal-json: adapt emission slug and do not duplicate soundfile
parent
22e81694
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
9 deletions
+22
-9
emissions/management/commands/load-from-drupal-json.py
emissions/management/commands/load-from-drupal-json.py
+22
-9
No files found.
emissions/management/commands/load-from-drupal-json.py
View file @
030b676f
import
datetime
import
isodate
import
json
import
os
import
requests
from
django.conf
import
settings
...
...
@@ -8,6 +9,7 @@ from django.core.files import File
from
django.core.files.base
import
ContentFile
from
django.core.files.storage
import
default_storage
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.utils.six
import
BytesIO
from
django.utils.text
import
slugify
from
django.utils.timezone
import
make_naive
...
...
@@ -19,6 +21,16 @@ class Command(BaseCommand):
parser
.
add_argument
(
'filename'
,
metavar
=
'FILENAME'
,
type
=
str
,
help
=
'name of file to import'
)
def
adjust_slug
(
self
,
title
):
slug
=
slugify
(
title
.
replace
(
"'"
,
" "
).
replace
(
"’"
,
" "
))
if
slug
==
'quand-la-musique-est-bof'
:
slug
=
'quand-la-musique-est-b-o-f'
elif
slug
==
'trad53-transmission-directe'
:
slug
=
'trad-53-transmission-directe'
elif
slug
==
'tranzistor'
:
slug
=
'tranzistor-l-emission'
return
slug
.
strip
(
'-'
)
def
handle
(
self
,
filename
,
verbosity
,
**
options
):
self
.
verbose
=
(
verbosity
>
1
)
for
episode_data
in
json
.
load
(
open
(
filename
)).
get
(
'episodes'
).
values
():
...
...
@@ -28,10 +40,12 @@ class Command(BaseCommand):
continue
if
not
episode_data
.
get
(
'text'
)
and
not
episode_data
.
get
(
'sound'
):
continue
emission_slug
=
self
.
adjust_slug
(
episode_data
[
'emission'
])
emission
,
created
=
Emission
.
objects
.
get_or_create
(
slug
=
slugify
(
episode_data
[
'emission'
])
,
slug
=
emission_slug
,
defaults
=
{
'title'
:
episode_data
[
'emission'
]})
if
created
:
emission
.
archived
=
True
emission
.
save
()
episode
,
created
=
Episode
.
objects
.
get_or_create
(
slug
=
episode_data
[
'path'
].
split
(
'/'
)[
-
1
],
...
...
@@ -80,16 +94,15 @@ class Command(BaseCommand):
diffusion
.
datetime
=
start_datetime
diffusion
.
save
()
if
episode_data
.
get
(
'sound'
)
and
not
episode
.
has_sound
():
orig_path
=
'media/sounds.orig/%s/%s'
%
(
emission
.
slug
,
episode_data
.
get
(
'sound'
).
split
(
'/'
)[
-
1
])
if
not
default_storage
.
exists
(
orig_path
):
orig_path
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'sounds.orig/%s/%s'
%
(
emission
.
slug
,
episode_data
.
get
(
'sound'
).
split
(
'/'
)[
-
1
]))
if
not
os
.
path
.
exists
(
orig_path
):
response
=
requests
.
get
(
episode_data
.
get
(
'sound'
))
if
response
.
status_code
==
200
:
path
=
default_storage
.
save
(
'sounds.orig/%s/%s'
%
(
emission
.
slug
,
episode_data
.
get
(
'sound'
).
split
(
'/'
)[
-
1
]),
ContentFile
(
response
.
content
))
bio
=
BytesIO
(
response
.
content
)
soundfile
=
SoundFile
(
episode
=
episode
,
podcastable
=
True
,
fragment
=
False
,
title
=
episode
.
title
)
soundfile
.
file
=
default_storage
.
open
(
path
)
soundfile
.
file
=
File
(
bio
)
soundfile
.
file
.
name
=
episode_data
.
get
(
'sound'
).
split
(
'/'
)[
-
1
]
soundfile
.
save
()
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