Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mymusiclist
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Brian Guadalupe
mymusiclist
Commits
f988e490
Commit
f988e490
authored
Nov 15, 2017
by
Brian Guadalupe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix populate songs script, add time remaining info
parent
39588f24
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
11 deletions
+58
-11
populate_songs.py
SQL/populate_songs.py
+58
-11
No files found.
SQL/populate_songs.py
View file @
f988e490
# -*- coding: utf-8 -*-
# run in Django shell ONLY!!!
# python manage.py shell
#
>>> exec(open('./SQL/populate_songs.py').read())
#
copy-paste everything then
# >>> run()
import
time
from
core.models
import
*
def
extract_song_title
(
s
):
...
...
@@ -20,13 +21,59 @@ def extract_song_title(s):
def
prettify_genre
(
g
):
return
', '
.
join
([
h
.
replace
(
'_'
,
' '
)
for
h
in
g
.
split
()])
for
i
in
Song
.
objects
.
filter
(
song_name__startswith
=
"."
):
songlst
=
extract_song_title
(
i
.
song_name
)
for
e
in
songlst
:
Song
.
objects
.
create
(
song_name
=
e
,
genre
=
prettify_genre
(
i
.
genre
),
artist
=
i
.
artist
,
album
=
i
.
album
)
# uncomment the next line if you want to delete the original entry after parsing
i
.
delete
()
def
parse_raw
(
n_albums
):
idx
=
1
total_time
=
0
for
i
in
Song
.
objects
.
filter
(
song_name__startswith
=
"."
):
print
(
'Processing entry
%
d of
%
d...'
%
(
idx
,
n_albums
))
t0
=
time
.
time
()
songlst
=
extract_song_title
(
i
.
song_name
)
for
e
in
songlst
:
# print(' FOUND: ' + e)
Song
.
objects
.
create
(
song_name
=
e
,
genre
=
prettify_genre
(
i
.
genre
),
artist
=
i
.
artist
,
album
=
i
.
album
)
tf
=
time
.
time
()
delta
=
tf
-
t0
total_time
+=
delta
# time remaining = (avg time per album)*(# remaining albums)
trem
=
(
total_time
/
idx
)
*
(
n_albums
-
idx
)
print
(
'[INFO] Parsing entry
%
d took
%.3
fs'
%
(
idx
,
delta
))
print
(
'[INFO] Approx. time remaining:
%
d:
%02
d'
%
(
trem
//
60
,
int
(
trem
)
%
60
))
idx
+=
1
def
cleanup
(
n_albums
):
print
(
'Deleting original raw entries...'
)
didx
=
1
for
i
in
Song
.
objects
.
filter
(
song_name__startswith
=
"."
):
print
(
'Deleting raw entry
%
d of
%
d...'
%
(
didx
,
n_albums
))
i
.
delete
()
didx
+=
1
# if something messed up above, run this
def
revert
():
rm
=
len
(
Song
.
objects
.
exclude
(
song_name__startswith
=
"."
))
ridx
=
1
ttime
=
0
for
song
in
Song
.
objects
.
exclude
(
song_name__startswith
=
"."
):
t0
=
time
.
time
()
song
.
delete
()
tf
=
time
.
time
()
delta
=
tf
-
t0
ttime
+=
delta
trem
=
(
ttime
/
ridx
)
*
(
rm
-
ridx
)
print
(
'[INFO] Approx. time remaining:
%
d:
%02
d'
%
(
trem
//
60
,
int
(
trem
)
%
60
))
ridx
+=
1
def
purge_all
():
resp
=
input
(
'[WARN] Delete ALL entries? [y/N] '
)
if
resp
==
'y'
:
for
song
in
Song
.
objects
.
all
():
song
.
delete
()
print
(
'[INFO] All entries deleted!'
)
# if something messed up above, uncomment these lines
# for song in Song.objects.exclude(song_name__startswith="."):
# song.delete()
\ No newline at end of file
def
run
():
print
(
'Populate songs'
)
qu
=
Song
.
objects
.
filter
(
song_name__startswith
=
"."
)
n_albums
=
len
(
qu
)
print
(
'Found
%
d entries yet to be parsed'
%
n_albums
)
parse_raw
(
n_albums
)
cleanup
(
n_albums
)
\ No newline at end of file
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