Skip to content
Snippets Groups Projects
Commit 4a57aec0 authored by Martin Mareš's avatar Martin Mareš
Browse files

One more change of data model

parent 347b2322
No related branches found
No related tags found
No related merge requests found
CREATE TABLE zoom_users ( CREATE TABLE zoom_users (
id serial PRIMARY KEY, -- our internal uid serial PRIMARY KEY,
user_id varchar(255) UNIQUE NOT NULL, -- Zoom's user_id varchar(255) UNIQUE NOT NULL, -- Zoom's
email varchar(255) NOT NULL, email varchar(255) NOT NULL,
full_name varchar(255) NOT NULL full_name varchar(255) NOT NULL
); );
CREATE TABLE zoom_meetings ( CREATE TABLE zoom_meetings (
id serial PRIMARY KEY, -- our internal mid serial PRIMARY KEY,
meeting_id int NOT NULL, -- Zoom's meeting ID meeting_id int UNIQUE NOT NULL, -- Zoom's meeting ID
uuid varchar(255) NOT NULL, -- Zoom's meeting instance ID uuid varchar(255) NOT NULL, -- Zoom's meeting instance ID
occurrence_id bigint DEFAULT NULL, -- Occurrence for recurring meetings host_uid int NOT NULL REFERENCES zoom_users(uid),
host_id int NOT NULL REFERENCES zoom_users(id),
topic varchar(255) DEFAULT '', topic varchar(255) DEFAULT '',
type int NOT NULL, -- 1=instant, 2=scheduled, 3=recurring no time, 8=recurring fixed time type int NOT NULL -- 1=instant, 2=scheduled, 3=recurring no time, 8=recurring fixed time
);
CREATE TABLE zoom_schedule (
id serial PRIMARY KEY,
mid int NOT NULL REFERENCES zoom_meetings(mid),
occurrence_id bigint DEFAULT 0, -- Occurrence for recurring meetings, 0 otherwise
start_time timestamp NOT NULL, start_time timestamp NOT NULL,
duration int NOT NULL -- minutes duration int NOT NULL, -- minutes
UNIQUE(mid, occurrence_id)
); );
...@@ -8,7 +8,6 @@ import psycopg2 ...@@ -8,7 +8,6 @@ import psycopg2
import psycopg2.extras import psycopg2.extras
import time import time
import dateutil.parser import dateutil.parser
# import dateutil.tz
import sys import sys
verbose = True verbose = True
...@@ -23,14 +22,11 @@ db_conn = psycopg2.connect(dbname=config['db']['name'], user=config['db']['user' ...@@ -23,14 +22,11 @@ db_conn = psycopg2.connect(dbname=config['db']['name'], user=config['db']['user'
db = db_conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) db = db_conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
def parse_time(iso_time, tz_name): def parse_time(iso_time):
utc = dateutil.parser.isoparse(iso_time) return dateutil.parser.isoparse(iso_time)
# tz = dateutil.tz.gettz(tz_name)
# return utc.astimezone(tz)
return utc
def add_recurring(uid, meet): def add_recurring(mid, meet):
time.sleep(0.2) time.sleep(0.2)
resp = client.meeting.get(host_id = meet['host_id'], id = meet['id']) resp = client.meeting.get(host_id = meet['host_id'], id = meet['id'])
resp.raise_for_status() resp.raise_for_status()
...@@ -40,43 +36,47 @@ def add_recurring(uid, meet): ...@@ -40,43 +36,47 @@ def add_recurring(uid, meet):
for occ in details["occurrences"]: for occ in details["occurrences"]:
db.execute(""" db.execute("""
INSERT INTO zoom_meetings INSERT INTO zoom_schedule
(meeting_id, uuid, occurrence_id, host_id, topic, type, start_time, duration) (mid, occurrence_id, start_time, duration)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s) VALUES (%s, %s, %s, %s)
""", ( """, (
meet['id'], mid,
meet['uuid'],
occ['occurrence_id'], occ['occurrence_id'],
uid, parse_time(occ['start_time']),
meet['topic'],
meet['type'],
parse_time(occ['start_time'], meet['timezone']),
occ['duration'], occ['duration'],
)) ))
def add_meeting(uid, meet): def add_meeting(uid, 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(""" db.execute("""
INSERT INTO zoom_meetings INSERT INTO zoom_meetings
(meeting_id, uuid, host_id, topic, type, start_time, duration) (meeting_id, uuid, host_uid, topic, type)
VALUES (%s, %s, %s, %s, %s, %s, %s) VALUES (%s, %s, %s, %s, %s)
RETURNING mid
""", ( """, (
meet['id'], meet['id'],
meet['uuid'], meet['uuid'],
uid, uid,
meet['topic'], meet['topic'],
meet['type'], meet['type'],
parse_time(meet['start_time'], meet['timezone']), ))
meeting_row = db.fetchone()
mid = meeting_row.mid
mtype = meet['type']
if mtype == 8:
# Recurring meetings: need to ask for the list of occurrences
add_recurring(mid, meet)
elif 'start_time' in meet:
# Other meetings usually have a starting time
db.execute("""
INSERT INTO zoom_schedule
(mid, occurrence_id, start_time, duration)
VALUES (%s, %s, %s, %s)
""", (
mid,
0,
parse_time(meet['start_time']),
meet['duration'], meet['duration'],
)) ))
...@@ -111,11 +111,12 @@ def get_meetings(uid, user_id): ...@@ -111,11 +111,12 @@ def get_meetings(uid, user_id):
assert total_rec == expected_rec, "Unexpected number of records, probably because of race condition" assert total_rec == expected_rec, "Unexpected number of records, probably because of race condition"
db.execute('DELETE FROM zoom_schedule')
db.execute('DELETE FROM zoom_meetings') db.execute('DELETE FROM zoom_meetings')
db.execute("SELECT * FROM zoom_users") db.execute("SELECT * FROM zoom_users")
users = db.fetchall() users = db.fetchall()
for u in users: for u in users:
get_meetings(u.id, u.user_id) get_meetings(u.uid, u.user_id)
db_conn.commit() db_conn.commit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment