Skip to content

Commit 05b823a

Browse files
committed
Adding events links URL generator
1 parent c8aabc1 commit 05b823a

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

tools/generate_event_links.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/python3
2+
3+
"""
4+
Generates `meetup.com` URLs for the upcoming TWiR
5+
"""
6+
import datetime
7+
8+
WEDNESDAY_DATETIME_DAY = 2
9+
END_DATE_WEEKS = 4 # Number of weeks to skip
10+
11+
START_URL_ENCODING = "T03%3A00%3A00-05%3A00" #T03:00:00
12+
END_URL_ENCODING = "T02%3A59%3A00-05%3A00" #T02:59:00
13+
EVENT_TYPES = [
14+
"online",
15+
"inPerson"
16+
]
17+
KEYWORDS = [
18+
"Rust"
19+
]
20+
LOCATIONS = [
21+
"us--tx--Dallas",
22+
"us--ca--San%20Francisco",
23+
"us--ma--Boston",
24+
"gb--Greater%20London--London",
25+
"ru--Moscow",
26+
"ma--Casablanca",
27+
"de--Berlin"
28+
]
29+
30+
def get_closest_wednesday():
31+
"""
32+
Returns the closest Wednesday to the current day
33+
"""
34+
day = datetime.datetime.today()
35+
36+
while day.weekday() != WEDNESDAY_DATETIME_DAY:
37+
day += datetime.timedelta(days=1)
38+
39+
return day
40+
41+
def get_desired_date_range():
42+
"""
43+
Returns datetime.datetime for the next closest Wednesday, and the Wednesday that
44+
is four weeks later.
45+
"""
46+
closest_wednesday = get_closest_wednesday()
47+
48+
# We add END_DATE_WEEKS, and 1 day because Meetup requires DAY+1 for proper querying
49+
end_date = closest_wednesday + datetime.timedelta(weeks=END_DATE_WEEKS, days=1)
50+
51+
return closest_wednesday, end_date
52+
53+
def get_formatted_dates():
54+
"""
55+
Returns formatted date strings of format "YEAR-MONTH-DAY"
56+
57+
e.g. March 11, 2022 would be 2022-03-01{START_URL_ENCODING}
58+
"""
59+
60+
start, end = get_desired_date_range()
61+
start_year, end_year = str(start.year), str(end.year)
62+
start_month, end_month = str(start.month).zfill(2), str(end.month).zfill(2) # left padding with 0s
63+
start_day, end_day = str(start.day).zfill(2), str(end.day).zfill(2) # left padding with 0s
64+
65+
return f"{start_year}-{start_month}-{start_day}{START_URL_ENCODING}", f"{end_year}-{end_month}-{end_day}{END_URL_ENCODING}"
66+
67+
def get_urls():
68+
urls = []
69+
start_date, end_date = get_formatted_dates()
70+
71+
for event_type in EVENT_TYPES:
72+
for keyword in KEYWORDS:
73+
for loc in LOCATIONS:
74+
full_url = f"https://www.meetup.com/find/" \
75+
f"?keywords={keyword}" \
76+
f"&source=EVENTS&" \
77+
f"customStartDate={start_date}" \
78+
f"&customEndDate={end_date}" \
79+
f"&location={loc}" \
80+
f"&eventType={event_type}"
81+
urls.append(full_url)
82+
83+
return urls
84+
85+
86+
def main():
87+
urls = get_urls()
88+
89+
# TODO: Auto parse results... For now, generates an HTML page of links to use
90+
date_title = str(datetime.datetime.today().strftime("%m_%d_%Y"))
91+
with open(f'{date_title}.html', 'w') as f:
92+
f.write(f'<p>{date_title}</p>\n<br>\n')
93+
for i, url in enumerate(urls):
94+
text_line = url[160:]
95+
f.write(f'<a href="{url}" target="_blank">{text_line}</a>\n<br>\n<br>\n')
96+
97+
if __name__ == '__main__':
98+
main()

0 commit comments

Comments
 (0)