History/most played queries
Update history service draft.
This commit is contained in:
11
scripts/history.sql
Normal file
11
scripts/history.sql
Normal file
@@ -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
Normal file
12
scripts/most-played.sql
Normal file
@@ -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
Executable file
10
scripts/systemd-timer/cp-update-history.sh
Executable file
@@ -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
Executable file
9
scripts/systemd-timer/ln-update-history.sh
Executable file
@@ -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
Normal file
6
scripts/systemd-timer/update-history.service
Normal file
@@ -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
Normal file
10
scripts/systemd-timer/update-history.timer
Normal file
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Update my Spotify listening history.
|
||||
Requires=update-history.service
|
||||
|
||||
[Timer]
|
||||
OnUnitInactiveSec=2h
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -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
|
||||
@@ -1,3 +1,11 @@
|
||||
#!/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
|
||||
|
||||
Reference in New Issue
Block a user