happy New Year. I found it awkward to book a Zoom meeting, so I wrote a program. It's a lot of work to log in, select a time, and so on. It seems easy to do with a library called pyzoom, It's difficult to use (or rather, I didn't know how to change the setting of the itchy place), so I made a class for studying.
You can get the API key and secret key from the ZOOM Marketplace. https://marketplace.zoom.us/develop/create
import requests
import json
from datetime import datetime
import jwt
import time
import random
from pprint import pprint
class ZoomClient(object):
URL = 'https://api.zoom.us/v2'
def __init__(self, key: str, secret: str, user_id: str):
"""
:param key:Zoom Api Key
:param secret: Zoom Api Secret
:param user_id: Zoom ID(mail address)
"""
self.key = key
self.secret = secret
self.user_id = user_id
self.token = self.generate_token()
def generate_token(self):
header = {"alg": "HS256", "typ": "JWT"}
payload = {"iss": self.key, "exp": int(time.time() + 600)}
return jwt.encode(payload, self.secret, algorithm='HS256', headers=header).decode('utf-8')
def create_meeting(self, topic: str, start_time: datetime, duration_min: int,
pass_code: str = None, **settings: dict):
end_point = f'/users/{self.user_id}/meetings'
headers = {'Authorization': f"Bearer {self.token}",
'Content-Type': 'application/json'}
#Passcode: If not specified, make it appropriately
if not pass_code:
pass_code = str(random.randint(100000, 999999))
#Settings: Set by default
default_setting = self.default_setting()
#Setting: Rewrite with designation
if settings:
for k, v in settings.items():
default_setting[k] = v
body = {
"topic": topic,
'type': 2, # scheduled meeting
"start_time": start_time.isoformat(),
"duration": duration_min,
"timezone": "Osaka, Sapporo, Tokyo",
"password": pass_code,
"settings": default_setting}
response = requests.request('POST',
self.URL + end_point,
headers=headers,
data=json.dumps(body)).json()
return response
@staticmethod
def default_setting():
return {
'host_video': True, # start video when the host joins
'participant_video': True, # start video when the participants join
'join_before_host': True,
'mute_upon_entry': True,
'approval_type': 0, # automatically approve
'cn_meeting': False, # host meeting in china
'in_meeting': False, # host meeting in india
'watermark': False,
'use_pmi': False, # personal meeting id
'registration_type': 1,
'audio': "voip",
'auto_recording': "none",
'enforce_login': False,
'waiting_room': False,
'registrants_email_notification': False,
'meeting_authentication': False,
'contact_name': "UFY",
'contact_email': "[email protected]"}
def invitation(self, meeting_id: int):
end_point = f"/meetings/{meeting_id}/invitation"
headers = {'authorization': 'Bearer ' + self.token}
return requests.request("GET",
self.URL + end_point,
headers=headers).json()
Let's actually schedule the meeting and display the invitation.
def job():
api_key = 'your zoom api key'
api_secret = 'your zoom api secret'
user_id = 'your zoom id' # account mail address
client = ZoomClient(api_key, api_secret, user_id)
day = '2021/1/5'
start_time = '11:30'
end_time = '15:30'
mtg_start_time = datetime.strptime(day + ' ' + start_time, '%Y/%m/%d %H:%M')
mtg_end_time = datetime.strptime(day + ' ' + end_time, '%Y/%m/%d %H:%M')
duration_min = int((mtg_end_time - mtg_start_time).seconds / 60)
mtg = client.create_meeting(topic='api test',
start_time=mtg_start_time,
duration_min=duration_min,
**{'host_video': False})
mtg_id = mtg['id']
invitation = client.invitation(mtg_id)
pprint(invitation)
if __name__ == '__main__':
job()
Create a meeting → Receive in json format → Extract the meeting id → Issue an invitation based on the meeting id It is a flow.
Is the output
{'invitation': 'Mr. 〇〇 is inviting you to a reserved Zoom meeting.\r\n'
'\r\n'
'topic: api test\r\n'
'time:January 5, 2021 11:30 AM Osaka, Sapporo, Tokyo\r\n'
'\r\n'
'Join a Zoom meeting\r\n'
'https://invitation/url\r\n'
'\r\n'
'Meeting ID:Generated id\r\n'
'passcode:Generated pass code\r\n'}
There are many mysterious settings in zoom, and it has not been clarified yet. I would like to try various things.
Recommended Posts