diff --git a/db.ddl b/db.ddl index 3332c6b5ef0043b3cbf1d5d05a67f6cd5d99f2d1..e969836d5832a02f62c303f2ac4a351f8e33fd8f 100644 --- a/db.ddl +++ b/db.ddl @@ -7,8 +7,9 @@ CREATE TABLE zoom_users ( CREATE TABLE zoom_meetings ( id serial PRIMARY KEY, -- our internal - meeting_id int NOT NULL, -- Zoom's meeting ID (not unique for recurring meetings!) - uuid varchar(255) NOT NULL, -- Zoom's + meeting_id int NOT NULL, -- Zoom's meeting ID + uuid varchar(255) NOT NULL, -- Zoom's meeting instance ID + occurrence_id bigint DEFAULT NULL, -- Occurrence for recurring meetings host_id int NOT NULL REFERENCES zoom_users(id), topic varchar(255) DEFAULT '', type int NOT NULL, -- 1=instant, 2=scheduled, 3=recurring no time, 8=recurring fixed time diff --git a/fetch-meetings.py b/fetch-meetings.py index dc8b9117e5ff87f85546901dc6ecb44c7df00d43..7037637115d6ced684b6f40817e0012fd6873d1d 100755 --- a/fetch-meetings.py +++ b/fetch-meetings.py @@ -9,9 +9,10 @@ import psycopg2.extras import time import dateutil.parser # import dateutil.tz +import sys verbose = True -very_verbose = False +very_verbose = True config = configparser.ConfigParser() config.read('zoom.ini') @@ -29,11 +30,42 @@ def parse_time(iso_time, tz_name): return utc +def add_recurring(uid, meet): + time.sleep(0.2) + resp = client.meeting.get(host_id = meet['host_id'], id = meet['id']) + resp.raise_for_status() + details = json.loads(resp.content) + if very_verbose: + pprint(details) + + for occ in details["occurrences"]: + db.execute(""" + INSERT INTO zoom_meetings + (meeting_id, uuid, occurrence_id, host_id, topic, type, start_time, duration) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s) + """, ( + meet['id'], + meet['uuid'], + occ['occurrence_id'], + uid, + meet['topic'], + meet['type'], + parse_time(occ['start_time'], meet['timezone']), + occ['duration'], + )) + + def add_meeting(uid, meet): - if 'start_time' not in meet: + type = meet['type'] + if type == 3: # Type 3 meetings (scheduled with no time) are ignored return + if type == 8: + # Recurring meetings: need to ask for the list of occurrences + add_recurring(uid, meet) + return + db.execute(""" INSERT INTO zoom_meetings (meeting_id, uuid, host_id, topic, type, start_time, duration) @@ -59,7 +91,7 @@ def get_meetings(uid, user_id): if verbose: print(f"Fetching meetings for user {user_id}: page {page_id} of {num_pages}") - resp = client.meeting.list(user_id = user_id, type = 'upcoming', page_number = page_id) + resp = client.meeting.list(user_id = user_id, type = 'scheduled', page_number = page_id) resp.raise_for_status() meeting_list = json.loads(resp.content)