update notification
This commit is contained in:
parent
4543846c2e
commit
e0d87557a9
48
app/cron_notification_channel.py
Normal file
48
app/cron_notification_channel.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
from tqdm import tqdm
|
||||||
|
import asyncio
|
||||||
|
from pocketbase import PocketBase # Client also works the same
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
pb_admin_email = os.getenv('POCKETBASE_ADMIN_EMAIL')
|
||||||
|
pb_password = os.getenv('POCKETBASE_PASSWORD')
|
||||||
|
|
||||||
|
|
||||||
|
pb = PocketBase('http://127.0.0.1:8090')
|
||||||
|
admin_data = pb.collection('_superusers').auth_with_password(pb_admin_email, pb_password)
|
||||||
|
|
||||||
|
|
||||||
|
#manually fix and fill the data for notificationChannels
|
||||||
|
#default setting is subscribed to all channels
|
||||||
|
|
||||||
|
async def subscribe(user_id):
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = pb.collection("notificationChannels").get_full_list(query_params={"filter": f"user='{user_id}'"})
|
||||||
|
exist = any(item.user == user_id for item in result)
|
||||||
|
|
||||||
|
if exist == False:
|
||||||
|
pb.collection("notificationChannels").create({
|
||||||
|
'user': user_id,
|
||||||
|
'earningsSurprise': True,
|
||||||
|
'wiim': True,
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def run():
|
||||||
|
all_users = pb.collection("users").get_full_list()
|
||||||
|
for item in tqdm(all_users):
|
||||||
|
user_id = item.id
|
||||||
|
await subscribe(user_id=user_id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
asyncio.run(run())
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
@ -223,10 +223,21 @@ async def push_earnings_release(user_id):
|
|||||||
async def run():
|
async def run():
|
||||||
all_users = pb.collection("users").get_full_list()
|
all_users = pb.collection("users").get_full_list()
|
||||||
for item in tqdm(all_users):
|
for item in tqdm(all_users):
|
||||||
user_id = item.id
|
try:
|
||||||
#is_pro = True if item.tier == 'Pro' else False
|
user_id = item.id
|
||||||
await push_wiim(user_id=user_id)
|
#is_pro = True if item.tier == 'Pro' else False
|
||||||
await push_earnings_release(user_id=user_id)
|
result = pb.collection('notificationChannels').get_list(query_params={"filter": f"user='{user_id}'"})
|
||||||
|
channels = result.items
|
||||||
|
for channel in channels:
|
||||||
|
|
||||||
|
if channel.wiim == True:
|
||||||
|
await push_wiim(user_id=user_id)
|
||||||
|
|
||||||
|
if channel.earnings_surprise == True:
|
||||||
|
await push_earnings_release(user_id=user_id)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user