Created
December 19, 2019 16:53
-
-
Save cobbal/4377b632d62fc7845ac5f7b1a277206c to your computer and use it in GitHub Desktop.
opens zoom to the next/current meeting on your calendar.If distributing publicly, please remove the client secret. fill in your calendar id before use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# opens zoom to the next/current meeting on your calendar | |
# license: Apache 2.0 | |
calendar="[email protected]" | |
import datetime | |
import pickle | |
import os.path | |
try: | |
import keyring | |
from googleapiclient.discovery import build | |
from google_auth_oauthlib.flow import InstalledAppFlow | |
from google.auth.transport.requests import Request | |
except ImportError: | |
sys.exit("""Missing dependencies: | |
install using | |
pip3 install --upgrade keyring google-api-python-client google-auth-httplib2 google-auth-oauthlib | |
""") | |
import re | |
import webbrowser | |
from base64 import b64encode, b64decode | |
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] | |
client_config = { | |
"installed": { | |
"client_id": "254617732984-ai6hqc6l9n6n6nf48eg0mp92of3g8qh8.apps.googleusercontent.com", | |
"project_id": "zoom-launcher-262516", | |
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | |
"token_uri": "https://oauth2.googleapis.com/token", | |
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | |
"client_secret": "bqjrga1nZs2_ow4Gn3hp96Mq", | |
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob","http://localhost"] | |
} | |
} | |
def main(): | |
domain = "com.cobbal.zoom-launcher" | |
creds = None | |
try: | |
creds = pickle.loads(b64decode(keyring.get_password(domain, calendar))) | |
except: | |
pass | |
# If there are no (valid) credentials available, let the user log in. | |
if not creds or not creds.valid: | |
if creds and creds.expired and creds.refresh_token: | |
creds.refresh(Request()) | |
else: | |
flow = InstalledAppFlow.from_client_config(client_config, SCOPES) | |
creds = flow.run_local_server(port=0) | |
# Save the credentials for the next run | |
keyring.set_password(domain, calendar, b64encode(pickle.dumps(creds)).decode('ascii')) | |
service = build('calendar', 'v3', credentials=creds) | |
now = datetime.datetime.utcnow() | |
start = now.isoformat() + 'Z' # 'Z' indicates UTC time | |
end = (now + datetime.timedelta(days=1)).isoformat() + 'Z' # 'Z' indicates UTC time | |
events_result = service.events().list(calendarId='primary', timeMin=start, timeMax=end, | |
maxResults=10, singleEvents=True, | |
orderBy='startTime').execute() | |
events = events_result.get('items', []) | |
zoomRe = re.compile(r"https://\w+.zoom.us/j/(\d{9})") | |
zoomId = None | |
suggested = False | |
for event in events: | |
start = event['start'].get('dateTime', event['start'].get('date')) | |
matches = zoomRe.search(event['description']) | |
if matches: | |
print(start, event['summary']) | |
url = "zoommtg://zoom.us/join?confno={}".format(matches[1]) | |
print(url) | |
suggested = True | |
if "n" in input("is this correct? [Yn] "): | |
continue | |
webbrowser.open(url) | |
break | |
else: | |
print("No {}zoom meetings found on your calendar".format("other " if suggested else "")) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment