|
import os |
|
import secrets |
|
import string |
|
|
|
import arrow |
|
import click |
|
import dateparser |
|
from zoomus import ZoomClient |
|
|
|
API_CLIENT = os.environ["API_CLIENT"] |
|
API_SECRET = os.environ["API_SECRET"] |
|
|
|
client = ZoomClient(API_CLIENT, API_SECRET) |
|
|
|
|
|
def create_new_meeting(config): |
|
response = client.meeting.create(**config) |
|
print(response.text) |
|
return response.json()["id"] |
|
|
|
|
|
def delete_meeting(meeting_id): |
|
response = client.meeting.delete(id=meeting_id) |
|
return response.status_code == 204 |
|
|
|
|
|
def is_old_meeting(meeting): |
|
start_time = arrow.get(meeting["start_time"]) |
|
end_time = start_time.shift(hours=+1.5) |
|
return end_time < arrow.utcnow() |
|
|
|
|
|
def list_user_meetings(user_id): |
|
return client.meeting.list(user_id=user_id).json()["meetings"] |
|
|
|
|
|
def random_password(max_length=10): |
|
alphabet = string.ascii_letters + string.digits |
|
return "".join(secrets.choice(alphabet) for i in range(max_length)) |
|
|
|
|
|
def human_date_to_ISO(time_str): |
|
return arrow.get(dateparser.parse(time_str), "IST").isoformat() |
|
|
|
|
|
@click.group() |
|
def cli(): |
|
pass |
|
|
|
|
|
@cli.command() |
|
@click.option( |
|
"--waiting-room", default=False, is_flag=True, help="Enable waiting room", |
|
) |
|
@click.option( |
|
"--join-before-host", |
|
default=False, |
|
is_flag=True, |
|
help="Allow users to join before host", |
|
) |
|
@click.option( |
|
"--no-password", |
|
is_flag=True, |
|
default=False, |
|
help="Toggle password for meeting", |
|
) |
|
@click.option( |
|
"--start-time", |
|
default=None, |
|
help="Start time in UTC", |
|
type=human_date_to_ISO, |
|
) |
|
@click.option( |
|
"--type", |
|
default=2, |
|
help="Meeting type [1: Instant, 2: Scheduled, 3: Recurring, 8: Recurring with fixed time]", |
|
) |
|
@click.option("--topic", help="Topic for the meeting") |
|
@click.argument("email") |
|
def create_meeting( |
|
email, topic, type, start_time, no_password, join_before_host, waiting_room |
|
): |
|
data = { |
|
"topic": topic, |
|
"start_time": start_time, |
|
"type": type, |
|
"password": "" if no_password else random_password(), |
|
"settings": { |
|
"join_before_host": join_before_host, |
|
"in_meeting": True, |
|
"mute_upon_entry": True, |
|
"waiting_room": waiting_room, |
|
}, |
|
} |
|
# Remove empty settings from the config; Use sane defaults from Zoom |
|
for key, value in data.copy().items(): |
|
if not value: |
|
data.pop(key) |
|
config = {"user_id": email, "data": data} |
|
create_new_meeting(config) |
|
|
|
|
|
@cli.command() |
|
@click.argument("meeting_id") |
|
def delete_meeting_by_id(meeting_id): |
|
delete_meeting(meeting_id) |
|
|
|
|
|
@cli.command() |
|
@click.argument("email") |
|
def delete_old_meetings(email): |
|
for meeting in list_user_meetings(email): |
|
if is_old_meeting(meeting): |
|
delete_meeting(meeting["id"]) |
|
|
|
|
|
@cli.command() |
|
@click.option( |
|
"--format", default="tsv", help="Display list using specified format" |
|
) |
|
@click.argument("email") |
|
def list_meetings(email, format): |
|
for meeting in list_user_meetings(email): |
|
if format == "dict": |
|
print(meeting) |
|
elif format == "tsv": |
|
time = ( |
|
arrow.get(meeting["start_time"]) |
|
.to(meeting["timezone"]) |
|
.format() |
|
) |
|
print("{topic}\t{time}\t{join_url}".format(**meeting, time=time)) |
|
else: |
|
raise RuntimeError("Unknown format") |
|
|
|
|
|
if __name__ == "__main__": |
|
cli() |