minimum viable product
This commit is contained in:
53
populater/src/app.py
Executable file
53
populater/src/app.py
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
|
||||
from common import Db, PlaylistUpdater
|
||||
|
||||
|
||||
INTERVAL = int(os.environ.get('INTERVAL', '0')) or 3600
|
||||
|
||||
CLIENT_ID = os.environ.get('CLIENT_ID', None)
|
||||
if CLIENT_ID is None:
|
||||
raise ValueError("CLIENT_ID cannot be None, set using environment variable")
|
||||
CLIENT_SECRET = os.environ.get('CLIENT_SECRET', None)
|
||||
if CLIENT_SECRET is None:
|
||||
raise ValueError("CLIENT_SECRET cannot be None, set using environment variable")
|
||||
|
||||
db = Db('localhost', 6379, 0, CLIENT_ID, CLIENT_SECRET)
|
||||
|
||||
|
||||
def get_args():
|
||||
""" Get command line arguments """
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main(args):
|
||||
""" Entry point for script """
|
||||
users = db.get_all_users()
|
||||
print(f"{users=}")
|
||||
for user_id in users:
|
||||
playlists = db.get_user_playlists(user_id)
|
||||
if len(playlists) == 0:
|
||||
continue
|
||||
|
||||
auth_token = db.get_user_auth_token(user_id)
|
||||
updater = PlaylistUpdater(db, auth_token)
|
||||
|
||||
for playlist_id in playlists:
|
||||
updater.update_playlist(playlist_id)
|
||||
return 0
|
||||
|
||||
print(f"{__name__}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
while True:
|
||||
print("executing...")
|
||||
main(get_args())
|
||||
print(f"done. sleeping for {INTERVAL} seconds...")
|
||||
time.sleep(INTERVAL)
|
1
populater/src/common
Symbolic link
1
populater/src/common
Symbolic link
@@ -0,0 +1 @@
|
||||
../../common/
|
Reference in New Issue
Block a user