first commit

This commit is contained in:
Tomas Dvorak
2026-04-13 17:46:58 +02:00
commit 6e8fedf534
234 changed files with 53808 additions and 0 deletions
+32
View File
@@ -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)
+22
View File
@@ -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.
"""
...
+25
View File
@@ -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()