-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregret_scheduler.py
More file actions
30 lines (27 loc) · 1.21 KB
/
regret_scheduler.py
File metadata and controls
30 lines (27 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from apscheduler.schedulers.background import BackgroundScheduler
from firebase_admin import db
from datetime import datetime
import pytz
def update_pending_to_regret():
ist = pytz.timezone('Asia/Kolkata')
today = datetime.now(ist).date()
trips_ref = db.reference('/trips', url='https://fill-it-19a6e-default-rtdb.asia-southeast1.firebasedatabase.app/')
all_trips = trips_ref.get()
if not all_trips:
return
for trip_id, trip in all_trips.items():
status = trip.get('status', {}).get('status')
booking_date = trip.get('date')
if status == 'pending' and booking_date:
try:
booking_date_obj = datetime.strptime(booking_date, "%Y-%m-%d").date()
if booking_date_obj < today:
trips_ref.child(trip_id).child('status').update({
'status': 'regret',
'updated_at': datetime.now(ist).isoformat()
})
except Exception as e:
print(f"Error updating trip {trip_id}: {e}")
scheduler = BackgroundScheduler()
scheduler.add_job(update_pending_to_regret, 'interval', hours=1)
scheduler.start()