Skip to content

Instantly share code, notes, and snippets.

@punchagan
Last active February 23, 2024 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save punchagan/634f73acb10ec9b1c387521766bd0158 to your computer and use it in GitHub Desktop.
Save punchagan/634f73acb10ec9b1c387521766bd0158 to your computer and use it in GitHub Desktop.
Zoom Meetings Command Line
/.mypy_cache/
/.envrc

Command line script to manage Zoom meetings

A script to easily create, list and delete meetings

LICENSE: GPLv3 NOTE: You need to create a JWT app, and obtain the API CLIENT and SECRET to be able to use this script.

arrow==0.15.5
certifi==2019.11.28
chardet==3.0.4
click==7.1.1
dateparser==0.7.4
idna==2.9
PyJWT==1.7.1
python-dateutil==2.8.1
pytz==2019.3
regex==2020.4.4
requests==2.23.0
six==1.14.0
tzlocal==2.0.0
urllib3==1.25.8
https://github.com/punchagan/zoomus/archive/master.zip
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment