aboutsummaryrefslogtreecommitdiff
path: root/code/func
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-06-19 11:08:37 -0500
committerParker <contact@pkrm.dev>2024-06-19 11:08:37 -0500
commit00d217f4539747171be4d865f9c277eb0c77b705 (patch)
tree9055c3f7f701ca9f47eebe3c251b49e953e946b9 /code/func
parentd447126db1196f7d55a982a2c23f795db8cf321b (diff)
Delete Jellyfin accounts when needed
Jellyfin accounts never actually got deleted from Jellyfin, I forgot to write that part. So now the accounts are properly deleted from both Jellyfin and the DB.
Diffstat (limited to 'code/func')
-rw-r--r--code/func/jellyfin.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/code/func/jellyfin.py b/code/func/jellyfin.py
index d434c17..c255ac2 100644
--- a/code/func/jellyfin.py
+++ b/code/func/jellyfin.py
@@ -46,9 +46,6 @@ def create_jellyfin_account(user_id):
json=account_policy,
)
if request_3.status_code != 204:
- print(request_3.json())
- print(request_3.status_code)
- print("BROKEN AT REQUEST 3")
return False
# Add the information to the database
@@ -62,3 +59,29 @@ def create_jellyfin_account(user_id):
db.close()
return username, password
+
+
+"""
+Delete a specific Jellyfin account and return True/False
+"""
+
+
+def delete_jellyfin_account(jellyfin_user_id):
+ request = requests.delete(
+ f"{JELLYFIN_URL}/Users/{jellyfin_user_id}",
+ headers=JELLYFIN_HEADERS,
+ )
+ # If 204 - account deleted
+ # If 404 - account not found
+ # Either way, remove account from database
+ if request.status_code in (404, 204):
+ db = sqlite3.connect("cordarr.db")
+ cursor = db.cursor()
+ cursor.execute(
+ "DELETE FROM jellyfin_accounts WHERE jellyfin_user_id = ?",
+ (jellyfin_user_id,),
+ )
+ db.commit()
+ db.close()
+ return True
+ return False \ No newline at end of file