mirror of
https://github.com/Dvorinka/SpotifyRecAlg.git
synced 2026-06-03 20:13:03 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import time
|
||||
|
||||
import schedule
|
||||
|
||||
from swingmusic.crons.mixes import Mixes
|
||||
from swingmusic.lib.recipes.recents import RecentlyAdded, RecentlyPlayed
|
||||
from swingmusic.lib.recipes.topstreamed import TopArtists
|
||||
from swingmusic.utils.threading import background
|
||||
|
||||
|
||||
@background
|
||||
def start_cron_jobs():
|
||||
"""
|
||||
This is the function that triggers the cron jobs.
|
||||
"""
|
||||
# NOTE: RecentlyPlayed is not a CRON job, it's triggered here to
|
||||
# populate the values for the very first time.
|
||||
RecentlyPlayed()
|
||||
RecentlyAdded()
|
||||
|
||||
# Initialized CRON jobs
|
||||
TopArtists()
|
||||
TopArtists(duration="week")
|
||||
Mixes()
|
||||
|
||||
# Trigger all CRON jobs when the app is started.
|
||||
schedule.run_all()
|
||||
|
||||
# Run all CRON jobs on a loop.
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(1)
|
||||
@@ -0,0 +1,22 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import schedule
|
||||
|
||||
|
||||
class CronJob(ABC):
|
||||
"""
|
||||
A cron job that will be run on a regular interval.
|
||||
"""
|
||||
|
||||
name: str
|
||||
hours: int = 1
|
||||
|
||||
def __init__(self):
|
||||
schedule.every(self.hours).hours.do(self.run)
|
||||
|
||||
@abstractmethod
|
||||
def run(self):
|
||||
"""
|
||||
The function that will be called by the cron job.
|
||||
"""
|
||||
...
|
||||
@@ -0,0 +1,25 @@
|
||||
from swingmusic.crons.cron import CronJob
|
||||
from swingmusic.lib.recipes.artistmixes import ArtistMixes
|
||||
from swingmusic.lib.recipes.because import BecauseYouListened
|
||||
|
||||
|
||||
class Mixes(CronJob):
|
||||
"""
|
||||
This cron job creates mixes displayed on the homepage.
|
||||
"""
|
||||
|
||||
name: str = "mixes"
|
||||
hours: int = 12
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Creates the artist mixes
|
||||
"""
|
||||
ArtistMixes()
|
||||
|
||||
# INFO: Because you listened to artist items are generated using
|
||||
# the artist mixes, so run them after the artist mixes are created.
|
||||
BecauseYouListened()
|
||||
Reference in New Issue
Block a user