Browse Source

History/most played queries

Update history service draft.
master
Kevin Mok 5 years ago
parent
commit
1d9583489f
Signed by: Kevin-Mok GPG Key ID: AEA75288DC135CF5
  1. 3
      .gitignore
  2. 11
      scripts/history.sql
  3. 12
      scripts/most-played.sql
  4. 10
      scripts/systemd-timer/cp-update-history.sh
  5. 9
      scripts/systemd-timer/ln-update-history.sh
  6. 6
      scripts/systemd-timer/update-history.service
  7. 10
      scripts/systemd-timer/update-history.timer
  8. 14
      scripts/update-history.service
  9. 10
      scripts/update-history.sh

3
.gitignore

@ -11,7 +11,8 @@ spotifyvis/static/graphs/sass/*
*.pyc *.pyc
*.txt *.txt
api-keys.sh
api-keys*
db.sqlite3 db.sqlite3
Pipfile Pipfile
scrap.py scrap.py

11
scripts/history.sql

@ -0,0 +1,11 @@
-- select t.name as track, a.name as artist
select timestamp, substring(t.name for 50) as track, a.name as artist
from api_history as h
join api_track as t
on h.track_id = t.id
join api_track_artists ta
on ta.track_id = t.id
join api_artist a
on a.id = ta.artist_id
-- limit 10;
;

12
scripts/most-played.sql

@ -0,0 +1,12 @@
-- select t.name as track, a.name as artist
select substring(t.name for 50) as track, a.name as artist, count(t.id)
from api_history as h
join api_track as t
on h.track_id = t.id
join api_track_artists ta
on ta.track_id = t.id
join api_artist a
on a.id = ta.artist_id
group by t.id, a.id
order by count(t.id) desc;
-- limit 10;

10
scripts/systemd-timer/cp-update-history.sh

@ -0,0 +1,10 @@
#!/bin/bash
sv_scripts_dir="/home/kevin/coding/spotify-lib-vis/src/scripts"
systemd_dir="/etc/systemd/system"
script_name="update-history"
for ext in "service" "timer" ; do
filename="$script_name"."$ext"
sudo ln -s "$sv_scripts_dir"/"$filename" "$systemd_dir"/"$filename"
done

9
scripts/systemd-timer/ln-update-history.sh

@ -0,0 +1,9 @@
#!/bin/bash
sv_scripts_dir="/home/kevin/coding/spotify-lib-vis/src/scripts"
systemd_dir="/etc/systemd/system"
script_name="update-history"
for ext in "service" "timer" ; do
sudo cp "$sv_scripts_dir"/"$script_name"."$ext" "$systemd_dir"
done

6
scripts/systemd-timer/update-history.service

@ -0,0 +1,6 @@
[Unit]
Description=Update my Spotify listening history job.
[Service]
Type=simple
ExecStart=/usr/bin/bash /home/kevin/coding/spotify-lib-vis/src/scripts/update-history.sh

10
scripts/systemd-timer/update-history.timer

@ -0,0 +1,10 @@
[Unit]
Description=Update my Spotify listening history.
Requires=update-history.service
[Timer]
OnUnitInactiveSec=2h
Persistent=true
[Install]
WantedBy=timers.target

14
scripts/update-history.service

@ -1,14 +0,0 @@
[Unit]
Description=Update my Spotify listening history.
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec="15m"
User=kevin
ExecStart=/usr/bin/bash /home/kevin/coding/spotify-lib-vis/src/update-history.sh
[Install]
WantedBy=multi-user.target

10
scripts/update-history.sh

@ -1,3 +1,11 @@
#!/bin/bash #!/bin/bash
/home/kevin/coding/spotify-lib-vis/bin/python /home/kevin/coding/spotify-lib-vis/src/manage.py update-history >> /home/kevin/coding/spotify-lib-vis/src/api/management/commands/update-history.log 2>&1
spv_dir="/home/kevin/coding/spotify-lib-vis"
src_dir="$spv_dir"/src
python="$spv_dir"/bin/python
log_file="$src_dir"/api/management/commands/update-history.log
source "$src_dir"/scripts/api-keys.sh
"$python" "$src_dir"/manage.py update-history >> "$log_file" 2>&1
# "$python" "$src_dir"/manage.py update-history
Loading…
Cancel
Save