-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.py
79 lines (69 loc) · 2.49 KB
/
helper.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from datetime import datetime, timedelta
import pytz
from surrealdb import Surreal
import requests
def convert_et_to_utc(et_time_str):
# define the month mapping dictionary
month_map = {
"Jan.": "January",
"Feb.": "February",
"March": "March",
"April": "April",
"May": "May",
"June": "June",
"July": "July",
"Aug.": "August",
"Sept.": "September",
"Oct.": "October",
"Nov.": "November",
"Dec.": "December",
}
# get current date and time in ET
et_tz = pytz.timezone("US/Eastern")
now = datetime.now(et_tz)
# handle "Today" and "Yesterday"
if et_time_str.startswith("Today"):
time_str = et_time_str.replace("Today ", "")
et_time = now.replace(
hour=int(time_str[:2]),
minute=int(time_str[3:5]),
second=int(time_str[6:8]),
microsecond=0,
)
elif et_time_str.startswith("Yesterday"):
time_str = et_time_str.replace("Yesterday ", "")
et_time = (now - timedelta(days=1)).replace(
hour=int(time_str[:2]),
minute=int(time_str[3:5]),
second=int(time_str[6:8]),
microsecond=0,
)
else:
# replace abbreviated month names with full names
for short, full in month_map.items():
if short in et_time_str:
et_time_str = et_time_str.replace(short, full)
break
# parse the date string
et_time = datetime.strptime(et_time_str, "%B %d, %Y %H:%M:%S")
et_time = et_tz.localize(et_time)
# convert the ET time to UTC
utc_time = et_time.astimezone(pytz.utc)
# return the UTC time as an ISO 8601 formatted string
return utc_time.isoformat()
async def relate(db: Surreal, id_1: str, id_2: str, table: str):
"""Runs ``RELATE id_1->table->id_2`` for you. You're welcome."""
return await db.query(f"RELATE {id_1}->{table}->{id_2}")
async def works(CATEGORIES):
for category_id, category_info in CATEGORIES.items():
if requests.get(f"https://scratch.mit.edu/discuss/{category_id}").ok:
category_info["user_accessible"] = True
print(
f"✅ The forums responded gladly when accessing {category_info['name']}"
)
else:
category_info["user_accessible"] = False
print(
f"❌ The forums did not respond when accessing {category_info['name']}"
)
print(str(CATEGORIES))