From 241105cd46318f655f7e377b83aab22c19945106 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 3 Dec 2024 12:52:25 +0100 Subject: [PATCH] update cron pocketbase --- app/cron_pocketbase.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/cron_pocketbase.py b/app/cron_pocketbase.py index de6a9ee..cf1f49f 100644 --- a/app/cron_pocketbase.py +++ b/app/cron_pocketbase.py @@ -34,9 +34,8 @@ berlin_tz = pytz.timezone('Europe/Berlin') pb = PocketBase('http://127.0.0.1:8090') -admin_data = pb.admins.auth_with_password(pb_admin_email, pb_password) -pb_admin_email = os.getenv('POCKETBASE_ADMIN_EMAIL') -pb_password = os.getenv('POCKETBASE_PASSWORD') +admin_data = pb.collection('_superusers').auth_with_password(pb_admin_email, pb_password) + now = datetime.now() one_month_ago = now - timedelta(days=30) @@ -92,7 +91,7 @@ def send_email(recipient): async def update_free_trial(): - data = pb.collection("users").get_full_list(query_params = {"filter": f'freeTrial = True'}) + data = pb.collection("users").get_full_list(query_params = {"filter": f'freeTrial = True'}) for item in data: created_date = item.created @@ -109,4 +108,23 @@ async def update_free_trial(): print(e) -asyncio.run(update_free_trial()) \ No newline at end of file +async def downgrade_user(): + + user_data = pb.collection('users').get_full_list() + for item in user_data: + if item.tier != 'Pro': + stock_screener_data = pb.collection("stockscreener").get_full_list(query_params = {"filter": f"user = '{item.id}'"}) + for screener in stock_screener_data: + pb.collection('stockscreener').delete(screener.id); + + options_watchlist_data = pb.collection("optionsWatchlist").get_full_list(query_params = {"filter": f"user = '{item.id}'"}) + for watchlist in options_watchlist_data: + pb.collection('optionsWatchlist').delete(watchlist.id); + + +async def run(): + + await update_free_trial() + await downgrade_user() + +asyncio.run(run())