Skip to content

Commit

Permalink
update cron pocketbase
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Dec 3, 2024
1 parent e319b84 commit 241105c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions app/cron_pocketbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -109,4 +108,23 @@ async def update_free_trial():
print(e)


asyncio.run(update_free_trial())
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())

0 comments on commit 241105c

Please sign in to comment.