Commit 4a57aec0 authored by Martin Mareš's avatar Martin Mareš
Browse files

One more change of data model

parent 347b2322
CREATE TABLE zoom_users (
id serial PRIMARY KEY, -- our internal
uid serial PRIMARY KEY,
user_id varchar(255) UNIQUE NOT NULL, -- Zoom's
email varchar(255) NOT NULL,
full_name varchar(255) NOT NULL
);
CREATE TABLE zoom_meetings (
id serial PRIMARY KEY, -- our internal
meeting_id int NOT NULL, -- Zoom's meeting ID
mid serial PRIMARY KEY,
meeting_id int UNIQUE 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),
host_uid int NOT NULL REFERENCES zoom_users(uid),
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,
duration int NOT NULL -- minutes
duration int NOT NULL, -- minutes
UNIQUE(mid, occurrence_id)
);
......@@ -8,7 +8,6 @@ import psycopg2
import psycopg2.extras
import time
import dateutil.parser
# import dateutil.tz
import sys
verbose = True
......@@ -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)
def parse_time(iso_time, tz_name):
utc = dateutil.parser.isoparse(iso_time)
# tz = dateutil.tz.gettz(tz_name)
# return utc.astimezone(tz)
return utc
def parse_time(iso_time):
return dateutil.parser.isoparse(iso_time)
def add_recurring(uid, meet):
def add_recurring(mid, meet):
time.sleep(0.2)
resp = client.meeting.get(host_id = meet['host_id'], id = meet['id'])
resp.raise_for_status()
......@@ -40,45 +36,49 @@ def add_recurring(uid, meet):
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)
INSERT INTO zoom_schedule
(mid, occurrence_id, start_time, duration)
VALUES (%s, %s, %s, %s)
""", (
meet['id'],
meet['uuid'],
mid,
occ['occurrence_id'],
uid,
meet['topic'],
meet['type'],
parse_time(occ['start_time'], meet['timezone']),
parse_time(occ['start_time']),
occ['duration'],
))
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("""
INSERT INTO zoom_meetings
(meeting_id, uuid, host_id, topic, type, start_time, duration)
VALUES (%s, %s, %s, %s, %s, %s, %s)
(meeting_id, uuid, host_uid, topic, type)
VALUES (%s, %s, %s, %s, %s)
RETURNING mid
""", (
meet['id'],
meet['uuid'],
uid,
meet['topic'],
meet['type'],
parse_time(meet['start_time'], meet['timezone']),
meet['duration'],
))
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'],
))
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"
db.execute('DELETE FROM zoom_schedule')
db.execute('DELETE FROM zoom_meetings')
db.execute("SELECT * FROM zoom_users")
users = db.fetchall()
for u in users:
get_meetings(u.id, u.user_id)
get_meetings(u.uid, u.user_id)
db_conn.commit()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment