1
1
#!/usr/bin/env python3
2
2
3
3
import arrow
4
+ import os
4
5
import pandas as pd
5
6
import sys
6
7
import time
18
19
from meetup_query import *
19
20
from passlib .context import CryptContext
20
21
from pathlib import Path
21
- from pony .orm import Database , Required , Optional , PrimaryKey , Set , db_session
22
+ from pony .orm import Database , Optional , PrimaryKey , Required , Set , db_session
22
23
from pydantic import BaseModel
23
- from schedule import get_schedule , get_current_schedule_time , snooze_schedule , check_and_revert_snooze
24
+ from schedule import check_and_revert_snooze , get_current_schedule_time , get_schedule , snooze_schedule
24
25
from sign_jwt import main as gen_token
25
26
from slackbot import *
26
27
from typing import List , Union
74
75
75
76
76
77
class IPConfig (BaseModel ):
77
- whitelist : List [str ] = ["localhost" , "127.0.0.1" ]
78
- public_ips : List [str ] = [] # TODO: add whitelisted public IPs here
78
+ whitelist : list [str ] = ["localhost" , "127.0.0.1" ]
79
+ public_ips : list [str ] = [] # TODO: add whitelisted public IPs here
79
80
80
81
81
82
ip_config = IPConfig ()
@@ -254,7 +255,7 @@ async def ip_whitelist_or_auth(request: Request, current_user: User = Depends(ge
254
255
return current_user
255
256
256
257
257
- def check_auth (auth : Union [ dict , User ] ) -> None :
258
+ def check_auth (auth : dict | User ) -> None :
258
259
"""
259
260
Shared function to check authentication result.
260
261
Raises an HTTPException if authentication fails.
@@ -276,9 +277,7 @@ async def login_for_oauth_token(form_data: OAuth2PasswordRequestForm = Depends()
276
277
headers = {"WWW-Authenticate" : "Bearer" },
277
278
)
278
279
oauth_token_expires = timedelta (minutes = TOKEN_EXPIRE )
279
- oauth_token = create_access_token (
280
- data = {"sub" : user .username }, expires_delta = oauth_token_expires
281
- )
280
+ oauth_token = create_access_token (data = {"sub" : user .username }, expires_delta = oauth_token_expires )
282
281
283
282
return {"access_token" : oauth_token , "token_type" : "bearer" }
284
283
@@ -416,6 +415,10 @@ def get_events(auth: dict = Depends(ip_whitelist_or_auth),
416
415
# cleanup output file
417
416
sort_json (json_fn )
418
417
418
+ # check if file exists after sorting
419
+ if not os .path .exists (json_fn ) or os .stat (json_fn ).st_size == 0 :
420
+ return {"message" : "No events found" , "events" : []}
421
+
419
422
return pd .read_json (json_fn )
420
423
421
424
@@ -524,7 +527,7 @@ def post_slack(
524
527
def snooze_slack_post (
525
528
duration : str ,
526
529
auth : dict = Depends (ip_whitelist_or_auth ),
527
- ):
530
+ ):
528
531
"""
529
532
Snooze the Slack post for the specified duration
530
533
@@ -544,7 +547,7 @@ def snooze_slack_post(
544
547
545
548
# TODO: test IP whitelisting
546
549
@api_router .get ("/schedule" )
547
- def get_current_schedule (auth : Union [ dict , User ] = Depends (ip_whitelist_or_auth )):
550
+ def get_current_schedule (auth : dict | User = Depends (ip_whitelist_or_auth )):
548
551
"""
549
552
Get the current schedule including any active snoozes
550
553
"""
0 commit comments