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