aboutsummaryrefslogtreecommitdiff
path: root/app/db_removal.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/db_removal.py')
-rw-r--r--app/db_removal.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/app/db_removal.py b/app/db_removal.py
index 1c49dd5..e9f6594 100644
--- a/app/db_removal.py
+++ b/app/db_removal.py
@@ -1,15 +1,16 @@
from apscheduler.schedulers.background import BackgroundScheduler
import sqlite3
import requests
+import datetime
-from initialize_variables import radarr_host_url, headers
+import initialize_variables
# Remove all entries from the database of movies that have already finished downloading
# This helps to stop from entries building up in the database and slowing down everything
sched = BackgroundScheduler(daemon=True)
@sched.scheduled_job('cron', hour='0', minute='0')
def clear_database():
- db = sqlite3.connect('/data/movies.db')
+ db = sqlite3.connect(initialize_variables.db_path)
cursor = db.cursor()
# First get all of the movie ids in the database
cursor.execute('''
@@ -17,7 +18,7 @@ def clear_database():
''')
movie_ids = cursor.fetchall()
# Get all of the movie_ids that are currently downloading/queued and/or missing
- response = requests.get(f'{radarr_host_url}/api/v3/queue/', headers=headers)
+ response = requests.get(f'{initialize_variables.radarr_host_url}/api/v3/queue/', headers=initialize_variables.headers)
current_movie_ids = []
for movie in response.json()['records']:
current_movie_ids.append(str(movie['movieId']))
@@ -30,4 +31,21 @@ def clear_database():
DELETE FROM movies WHERE movie_id = ?
''', (movie_id[0],))
db.commit()
+ db.close()
+
+@sched.scheduled_job('interval', seconds=10)
+def clear_jellyfin_accounts():
+ db = sqlite3.connect(initialize_variables.db_path)
+ cursor = db.cursor()
+ cursor.execute('''
+ SELECT user_id, deletion_time FROM jellyfin_accounts
+ ''')
+ data = cursor.fetchall()
+ for user_id, deletion_time in data:
+ if datetime.datetime.now() > datetime.datetime.strptime(deletion_time, '%Y-%m-%d %H:%M:%S.%f'):
+ requests.delete(f'{initialize_variables.jellyfin_url}/Users/{user_id}', headers=initialize_variables.jellyfin_headers)
+ cursor.execute('''
+ DELETE FROM jellyfin_accounts WHERE user_id = ?
+ ''', (user_id,))
+ db.commit()
db.close() \ No newline at end of file