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.
This commit is contained in:
parent
d447126db1
commit
00d217f453
16
code/bot.py
16
code/bot.py
@ -6,6 +6,7 @@ import sqlite3
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from validate_config import create_config
|
from validate_config import create_config
|
||||||
|
from func.jellyfin import delete_jellyfin_account
|
||||||
from global_variables import LOG, BOT_TOKEN
|
from global_variables import LOG, BOT_TOKEN
|
||||||
|
|
||||||
|
|
||||||
@ -35,16 +36,15 @@ async def on_ready():
|
|||||||
|
|
||||||
@tasks.loop(seconds=60)
|
@tasks.loop(seconds=60)
|
||||||
async def delete_old_temp_accounts():
|
async def delete_old_temp_accounts():
|
||||||
# Delete all of the temporary Jellyfin accounts that have passed
|
# Get all jellyfin user IDs that have passed their deletion time
|
||||||
# their expiration time
|
|
||||||
db = sqlite3.connect("cordarr.db")
|
db = sqlite3.connect("cordarr.db")
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute(
|
cursor.execute("SELECT jellyfin_user_id FROM jellyfin_accounts WHERE deletion_time < ?", (datetime.datetime.now(),))
|
||||||
"DELETE FROM jellyfin_accounts WHERE deletion_time < ?",
|
jellyfin_user_ids = cursor.fetchall()
|
||||||
(datetime.datetime.now(),),
|
|
||||||
)
|
# Delete the Jellyfin accounts
|
||||||
db.commit()
|
for jellyfin_user_id in jellyfin_user_ids:
|
||||||
db.close()
|
delete_jellyfin_account(jellyfin_user_id[0])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -46,9 +46,6 @@ def create_jellyfin_account(user_id):
|
|||||||
json=account_policy,
|
json=account_policy,
|
||||||
)
|
)
|
||||||
if request_3.status_code != 204:
|
if request_3.status_code != 204:
|
||||||
print(request_3.json())
|
|
||||||
print(request_3.status_code)
|
|
||||||
print("BROKEN AT REQUEST 3")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Add the information to the database
|
# Add the information to the database
|
||||||
@ -62,3 +59,29 @@ def create_jellyfin_account(user_id):
|
|||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
return username, password
|
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
|
Loading…
x
Reference in New Issue
Block a user