I made a calendar that automatically updates the distribution schedule of Vtuber (Google Calendar edition)

Introduction

This article is a continuation of the article below.

I made a calendar that automatically updates the distribution schedule of Vtuber

Last time, we got video information from YouTube, so this time we will register the schedule in Google Calendar based on the obtained video information.

environment

Data to prepare

--YouTube video information --Google Calendar Calendar ID

Method

This time, we will register the schedule in Google Calendar, so naturally we need the calendar of the registration destination. Therefore, check the calendar ID in advance from the calendar settings.

After that, I was able to easily register to the calendar just by following the Official sample.

1. Enable Google Calendar API

Just press the button on the sample page. At the same time, save credentials.json in the directory you are working on.

2. Installation of required libraries

Execute the command exactly as it is written.

pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

3. Register the appointment in the calendar

Register the appointment in the calendar based on the sample code.

from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

SCOPES = ['https://www.googleapis.com/auth/calendar']

def insert_event(event, calendar_id):
    creds = None
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('calendar', 'v3', credentials=creds)

    event = {
        'summary': event.summary,
        'description': event.description,
        'start': {
            'dateTime': event.start_datetime,
            'timeZone': 'Japan',
        },
        'end': {
            'dateTime': event.end_datetime,
            'timeZone': 'Japan',
        }
    }
    event = service.events().insert(calendarId=calendar_id, body=event).execute()
    return event['id']

After that, pass the information to be registered in the calendar from the video information acquired last time and the calendar ID confirmed first to this function, and you're done. I decided to pass only the minimum information to be registered in the calendar as an event.

--summary: Video title --description: Video URL --https://www.youtube.com/watch?v= + Video ID --start_datetime: Delivery start time --Basically, actualStartTime is used. The video before the start of distribution is replaced with scheduledStartTime. --end_datetime: Delivery end time --Basically, actualEndTime is used. Set before the start of distribution or 1 hour after scheduledStartTime if it is being distributed.

If you write down the ID of the return value, you can edit the registered schedule, so you can respond to changes in the delivery time and video title.

Recommended Posts

I made a calendar that automatically updates the distribution schedule of Vtuber (Google Calendar edition)
I made a calendar that automatically updates the distribution schedule of Vtuber
I want a Slack bot that calculates and tells me the salary of a part-time job from the schedule of Google Calendar!
I made a slack bot that notifies me of the temperature
I made a program that automatically calculates the zodiac with tkinter
I made a tool to automatically back up the metadata of the Salesforce organization
I made a github action that notifies Slack of the visual regression test
[Python] I made a web scraping code that automatically acquires the news title and URL of Nikkei Inc.
I made a system that automatically decides whether to run tomorrow with Python and adds it to Google Calendar.
I made a twitter app that decodes the characters of Pricone with heroku (failure)
[Python / C] I made a device that wirelessly scrolls the screen of a PC remotely.
I made a function to check the model of DCGAN
I made a dot picture of the image of Irasutoya. (part1)
I made a program that solves the spot the difference in seconds
I made a Line bot that guesses the gender and age of a person from an image
Scraping the schedule of Hinatazaka46 and reflecting it in Google Calendar
I investigated the X-means method that automatically estimates the number of clusters
I analyzed the image of the Kyudo scoring book (a booklet that records the results of the hits). (Google Colaboratory)
I made a command to display a colorful calendar in the terminal
[Kaggle] I made a collection of questions using the Titanic tutorial
I made a web application that graphs the life log recorded on Google Home like a Gantt chart.
I made a note of Google colaboratory which can use Spleeter easily.
I wrote a corpus reader that reads the results of MeCab analysis
The story of developing a web application that automatically generates catchphrases [MeCab]
I made a simple timer that can be started from the terminal
I made a GAN with Keras, so I made a video of the learning process.
I made a library konoha that switches the tokenizer to a nice feeling
I made a program to check the size of a file in Python
I made a mistake in fetching the hierarchy with MultiIndex of pandas
[Python] Note: A self-made function that finds the area of the normal distribution
I made a function to see the movement of a two-dimensional array (Python)
I made a tool to estimate the execution time of cron (+ PyPI debut)
I made a LINE BOT that returns a terrorist image using the Flickr API
The story of IPv6 address that I want to keep at a minimum
Around the authentication of PyDrive2, a package that operates Google Drive with Python
I made an appdo command to execute a command in the context of the app
With LINEBot, I made an app that informs me of the "bus time"
I made a Linebot that notifies me of nearby evacuation sites on AWS
[Python] A program that calculates the number of updates of the highest and lowest records
[Discode Bot] I created a bot that tells me the race value of Pokemon
The story of making a Line Bot that tells us the schedule of competitive programming
I made a script to record the active window using win32gui of Python
I made a simple RSS reader ~ C edition ~
I made a Docker Image that reads RSS and automatically tweets regularly and released it.
I made a program in Python that changes the 1-minute data of FX to an arbitrary time frame (1 hour frame, etc.)
A story that reduces the effort of operation / maintenance
[Python] A program that counts the number of valleys
I made a cleaning tool for Google Container Registry
I made a threshold change box of Pepper's Dialog
Make a BOT that shortens the URL of Discord
# Function that returns the character code of a string
Steps to calculate the likelihood of a normal distribution
I tried to visualize the spacha information of VTuber
Generate that shape of the bottom of a PET bottle
A memo that I touched the Datastore with python
I made an Android application that displays Google Map
A story that analyzed the delivery of Nico Nama.
[Python] A program that compares the positions of kangaroos.
Clustering G-means that automatically determines the number of clusters
I tried to automatically generate OGP of a blog made with Hugo with tcardgen made by Go
I made a tool to get the answer links of OpenAI Gym all at once