Skip to content

Commit

Permalink
for first merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdlb committed Oct 23, 2022
1 parent 980e771 commit 3b1c6a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 5 additions & 0 deletions backend/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from backend


if __name__ == "__main__":
main()
21 changes: 8 additions & 13 deletions backend/src/model/decision_maker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from backend.src.config import settings
from backend.src.spotify_api.api_interface import SPOTIFY_API_INTERFACE
import pandas as pd

from pathlib import Path

class DecisionLoop:
def __init__(self):
Expand All @@ -16,7 +16,7 @@ def __init__(self):
self.all_non_skipped = []
self.next_song = None
self.to_skip_path=Path(settings.APP_PATH, "tmp", "to_skip")

self.to_skip_path.mkdir(parents=True, exist_ok= True)

def decision_maker(self):
while True:
Expand All @@ -28,28 +28,23 @@ def decision_maker(self):
with open(self.to_skip_path, "w") as writer:
writer.write(str(skip_decision))
sleep(5)


def main():
loop=DecisionLoop()
loop.decision_maker()

if __name__=="__main__":
main()


















sleep(5)




6 changes: 3 additions & 3 deletions backend/src/spotify_api/api_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def load_song_features(self, song_id) -> pd.Series:
features = json.load(reader)
return pd.Series(features)

def get_next_song(self, sp):
def get_next_song(self):
"""Get the next song in the currently playing playlist
Args:
Expand Down Expand Up @@ -138,7 +138,7 @@ def get_next_song(self, sp):
all_track_name.append(track_name)

# get currently playing song
current_song = sp.currently_playing()
current_song = self.sp.currently_playing()
current_song_id = current_song['item']['id']
idx_next_song = all_track_id.index(current_song_id) + 1
return all_track_id[idx_next_song]
Expand Down Expand Up @@ -220,5 +220,5 @@ def is_song_skipped(self, track_id):
return True

if __name__ == "__main__":
interface=SPOTIFY_API_INTERFACE()
interface = SPOTIFY_API_INTERFACE()
interface.is_song_skipped("6z8teIFzv6DFqsCfWfU425")
1 change: 1 addition & 0 deletions backend/src/spotify_api/skip_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def listen(self):
self.update_end_time()
while True:
if time.time() > self.end_time:

with open(self.to_skip_path, "r") as reader:
line = reader.readline()
if line == "True":
Expand Down

0 comments on commit 3b1c6a3

Please sign in to comment.