Schedule a Zoom meeting in Python

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

Schedule a Zoom meeting in Python
Take a screenshot in Python
Create a function in Python
Create a dictionary in Python
Make a bookmarklet in Python
Draw a heart in Python
Maybe in a python (original title: Maybe in Python)
Write a binary search in Python
Try creating a Deep Zoom file format .DZI in Python
[python] Manage functions in a list
Hit a command in Python (Windows)
Create a DI Container in Python
ABC166 in Python A ~ C problem
Write A * (A-star) algorithm in Python
Create a binary file in Python
Solve ABC036 A ~ C in Python
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python
Implementing a simple algorithm in Python 2
Create a Kubernetes Operator in Python
Solve ABC037 A ~ C in Python
Run a simple algorithm in Python
Draw a CNN diagram in Python
Create a random string in Python
When writing a program in Python
Generate a first class collection in Python
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Solve ABC175 A, B, C in Python
Use print in a Python2 lambda expression
A simple HTTP client implemented in Python
Precautions when pickling a function in python
Write the test in a python docstring
Display a list of alphabets in Python 3
Try sending a SYN packet in Python
Try drawing a simple animation in Python
Create a simple GUI app in Python
Create a JSON object mapper in Python
Write a short property definition in Python
[Python] [Windows] Take a screen capture in Python
Run the Python interpreter in a script
How to get a stacktrace in python
Write a Caesar cipher program in Python
Scraping a website using JavaScript in Python
Write a simple greedy algorithm in Python
Launch a Flask app in Python Anywhere
Get a token for conoha in python
Solve ABC165 A, B, D in Python
Write a simple Vim Plugin in Python 3
Draw a tree in Python 3 using graphviz
Generate a class from a string in Python
Display pyopengl in a browser (python + eel)
Let's make a combination calculation in Python
Try a functional programming pipe in Python
Learn dynamic programming in Python (A ~ E)
I created a password tool in Python.
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda