Skip to content

Instantly share code, notes, and snippets.

@penguoir
Last active March 27, 2020 12:05
Show Gist options
  • Save penguoir/4be41efe7d48c02b776bd119331db940 to your computer and use it in GitHub Desktop.
Save penguoir/4be41efe7d48c02b776bd119331db940 to your computer and use it in GitHub Desktop.
A script which notifies me when I have a canvas conference (made this because canvas doesn't have one??? and corona means there are way more conferences)
import requests, json, time
notify_url = 'my notify url'
url = 'my canvas api (including /api/v1)'
token = 'my canvas token'
headers = {
"Authorization": "Bearer {}".format(token)
}
def notify(message):
requests.post(notify_url, data=message)
notify('Started conference notifier')
print('Getting all courses')
r_courses = requests.get(url + 'courses', headers=headers)
courses = json.loads(r_courses.text)
print('Got {} courses'.format(len(courses)))
def notify_conferences():
for course in courses:
id = course['id']
r_conferences = requests.get(url + 'courses/' + str(id) + '/conferences', headers=headers)
conferences = json.loads(r_conferences.text).get('conferences', [])
for conference in conferences:
if conference.get('join_url', None):
notify('You have an active conference: "{}"'.format(conference['title']))
else:
print('No conferences in {}'.format(course.get('name', None)))
while True:
notify_conferences()
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment