Skip to content

Commit 0d7ac9f

Browse files
committed
bugfixes
1 parent 49129d6 commit 0d7ac9f

File tree

3 files changed

+67
-61
lines changed

3 files changed

+67
-61
lines changed

common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import lru_cache
22
import os
33
from time import time
4+
import json
45

56
import jwt
67
import requests
@@ -77,10 +78,11 @@ def all_meetings(user_id) -> list:
7778

7879

7980
def decode(response):
80-
if response.status_code != 200:
81+
if response.status_code > 299: # Not OK
8182
raise RuntimeError(response.content.decode())
8283
return json.loads(response.content.decode())
8384

85+
8486
def api_query(method, endpoint, **params):
8587
return decode(method(
8688
MAILGUN_BASE_URL + endpoint,

researchseminarsdotorg.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
"order": 0,
2020
"display": True}]}
2121

22+
2223
def find_seminar_series(series_id):
23-
url = "https://researchseminars.org/api/0/search/series?series_id=%s"%series_id
24+
url = f"https://researchseminars.org/api/0/search/series?series_id={series_id}"
2425
r = get(url)
2526
if r.status_code == 200:
2627
J = r.json()
2728
results = J["properties"]["results"]
2829
return (len(results) != 0)
2930

31+
3032
def create_seminar_series(payload, authorization):
3133
url = "https://researchseminars.org/api/0/save/series/"
3234
r = post(url, json=payload, headers={"authorization":authorization})
@@ -41,6 +43,7 @@ def create_seminar_series(payload, authorization):
4143
else:
4244
return False, ""
4345

46+
4447
def edit_seminar_series(name, payload, authorization):
4548
url = "https://researchseminars.org/api/0/save/series/"
4649
r = post(url, json=payload, headers={"authorization":authorization})
@@ -55,6 +58,7 @@ def edit_seminar_series(name, payload, authorization):
5558
else:
5659
return False, ""
5760

61+
5862
def add_talk_to_series(series_id, payload, authorization):
5963
url = "https://researchseminars.org/api/0/save/talk/"
6064
r = post(url, json=payload, headers={"authorization":authorization})
@@ -68,6 +72,7 @@ def add_talk_to_series(series_id, payload, authorization):
6872
else:
6973
return "", r.status_code
7074

75+
7176
def publish_to_researchseminars(talk):
7277
# talk should be provided in yaml format
7378
api_token = os.getenv("RESEARCHSEMINARS_API_TOKEN")

schedulezoomtalks.py

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,52 @@
11
import os
2+
import secrets
3+
from io import StringIO
4+
from typing import Tuple
5+
import datetime
6+
27
import github
38
import requests
4-
import secrets
9+
from ruamel.yaml import YAML
10+
import jinja2
11+
import pytz
12+
513
import common
614
from researchseminarsdotorg import publish_to_researchseminars
715
from host_key_rotation import host_key
8-
from io import StringIO
9-
from ruamel.yaml import YAML
16+
1017

1118
ISSUE_RESPONSE_TEMPLATE = jinja2.Template(
12-
"""Hi again! I've now created a Zoom meeting for your talk, with meeting ID
19+
"""I've now created a Zoom meeting for your talk, with meeting ID
1320
{{ meeting_id }}. You'll receive a separate email with a host key.
1421
""")
1522

1623
EMAIL_TEMPLATE = jinja2.Template(
1724
"""Hi {{ author }},
1825
19-
A Zoom meeting has now been scheduled for your Speakers' Corner talk.
20-
Five minutes before your timeslot starts, you and your audience will be
21-
able to join the meeting. You will then be able to claim the host role by
22-
using the host key below. After an hour the meeting will automatically
23-
be terminated. Once the recording finishes processing, you will get the
24-
opportunity to cut out parts of it.
26+
A Zoom meeting has now been scheduled for your Speakers' Corner talk.
27+
Five minutes before your timeslot starts, you and your audience will be
28+
able to join the meeting. You will then be able to claim the host role by
29+
using the host key below. After an hour the meeting will automatically
30+
be terminated. Once the recording finishes processing, you will get the
31+
opportunity to cut out parts of it.
2532
26-
Your meeting information:
27-
Talk title: {{ meeting_talk_title }}
28-
Date: {{ meeting_date }}
29-
Time slot: {{ meeting_start }} - {{ meeting_end }}
33+
Your meeting information:
34+
Talk title: {{ meeting_talk_title }}
35+
Date: {{ meeting_date }}
36+
Time slot: {{ meeting_start }} - {{ meeting_end }}
3037
31-
Zoom link: {{ meeting_zoom_link }}
32-
Host key: {{ meeting_host_key }}
38+
Zoom link: {{ meeting_zoom_link }}
39+
Host key: {{ meeting_host_key }}
3340
34-
Thank you in advance for contributing to the Speakers' Corner!
35-
- The VSF team
36-
""")
41+
Thank you in advance for contributing to the Speakers' Corner!
42+
- The VSF team
43+
""")
3744

38-
def schedule_zoom_talk(talk) -> Tuple[string, string]:
45+
46+
def schedule_zoom_talk(talk) -> Tuple[str, str]:
3947

4048
# Form the talk registration body
41-
request_body =
42-
{
49+
request_body = {
4350
"topic": "Speakers\' corner talk by %s"%(talk.get("name")),
4451
"type": 2, # Scheduled meeting
4552
"start_time": talk["time"],
@@ -83,42 +90,37 @@ def schedule_zoom_talk(talk) -> Tuple[string, string]:
8390
}
8491

8592
# Create the meeting
86-
response = zoom_request(
93+
response = common.zoom_request(
8794
requests.post,
88-
f"{common.ZOOM_API}users/{user_id}/meetings",
95+
f"{common.ZOOM_API}users/{common.SPEAKERS_CORNER_USER_ID}/meetings",
8996
params={"body":request_body}
9097
)
9198

92-
if( response.status != 201 ):
93-
return None
99+
meeting_id = response["id"]
94100

95-
# Extract meeting id
96-
meeting_id = response.id
97-
# Register the speaker
98-
register_speaker(meeting_id)
99-
# Update the meeting registration questions
100-
patch_registration_questions(meeting_id, talk)
101-
# Update the registrants email notification
101+
register_speaker(meeting_id, talk)
102+
patch_registration_questions(meeting_id)
102103
patch_registration_notification(meeting_id)
103104

104-
return meeting_id, response.join_url
105+
return meeting_id, response["registration_url"]
105106

106-
def register_speaker(meeting_id, talk) -> int:
107107

108+
def register_speaker(meeting_id, talk) -> int:
108109
request_payload = {
109110
"email": talk["email"],
110-
"first_name": "talk["speaker_name"],
111+
"first_name": talk["speaker_name"],
111112
}
112113

113114
# Send request
114-
response = zoom_request(
115+
response = common.zoom_request(
115116
requests.post,
116-
f"{common.ZOOM_API}users/{user_id}/meetings/{meeting_id}/registrants",
117-
params={"body":request_body}
117+
f"{common.ZOOM_API}users/{common.SPEAKERS_CORNER_USER_ID}/meetings/{meeting_id}/registrants",
118+
params={"body": request_payload}
118119
)
119120

120121
return response.status
121122

123+
122124
def patch_registration_questions(meeting_id) -> int:
123125

124126
request_body = {
@@ -135,7 +137,7 @@ def patch_registration_questions(meeting_id) -> int:
135137
"title": "May we contact you about future Virtual Science Forum events?",
136138
"type": "single", # short or single
137139
"answers": ["Yes", "No"], # only single
138-
"required": true
140+
"required": True
139141
},
140142
{
141143
"title": "How did you hear about the Virtual Science Forum?",
@@ -144,20 +146,20 @@ def patch_registration_questions(meeting_id) -> int:
144146
"One of the organizers",
145147
"A colleague (not an organizer)",
146148
"Other"],
147-
"required": true
149+
"required": True
148150
},
149151
{
150152
"title": "Please confirm you have read the participant instructions: \
151153
http://virtualscienceforum.org/#/attendeeguide*",
152154
"type": "short", # short or single
153-
"required": true
155+
"required": True
154156
},
155157
]
156158
}
157159

158-
response = zoom_request(
160+
response = common.zoom_request(
159161
requests.patch,
160-
f"{common.ZOOM_API}users/{user_id}/meetings/{meeting_id}/registrants/questions",
162+
f"{common.ZOOM_API}users/{common.SPEAKERS_CORNER_USER_ID}/meetings/{meeting_id}/registrants/questions",
161163
params={"body":request_body}
162164
)
163165

@@ -173,25 +175,22 @@ def patch_registration_notification(meeting_id) -> int:
173175
}
174176

175177
# Create the meeting
176-
response = zoom_request(
178+
response = common.zoom_request(
177179
requests.patch,
178-
f"{common.ZOOM_API}users/{user_id}/meetings/{meeting_id}",
180+
f"{common.ZOOM_API}users/{common.SPEAKERS_CORNER_USER_ID}/meetings/{meeting_id}",
179181
params={"body":request_body}
180182
)
181183

182184
return response.status
183185

184186
def notify_issue_about_zoom_meeting(repo, talk):
185-
issue_comment = ISSUE_RESPONSE_TEMPLATE.render(meeting_id=meeting_id)
187+
issue_comment = ISSUE_RESPONSE_TEMPLATE.render(meeting_id=talk["meeting_id"])
186188

187-
try:
188-
issue = repo.get_issue(number=talk["workflow_issue"])
189-
issue.create_comment(issue_comment)
190-
except:
191-
print("Couldn't create issue comment. The content would have been: ")
192-
print(issue_comment)
189+
issue = repo.get_issue(number=talk["workflow_issue"])
190+
issue.create_comment(issue_comment)
193191

194-
def notify_author(talk, join_url) -> string:
192+
193+
def notify_author(talk, join_url) -> str:
195194
# Get the host key
196195
meeting_host_key = host_key(talk["time"])
197196

@@ -214,8 +213,8 @@ def notify_author(talk, join_url) -> string:
214213
"html": email_text,
215214
}
216215

217-
return api_query(
218-
post,
216+
return common.api_query(
217+
requests.post,
219218
f"{common.MAILGUN_DOMAIN}messages",
220219
data=data
221220
)
@@ -229,8 +228,8 @@ def schedule_talks(repo, talks) -> int:
229228
continue
230229

231230
meeting_id, join_url = schedule_zoom_talk(talk)
232-
if( meetind_id ):
233-
talk.get("zoom_meeting_id") = meeting_id
231+
if meeting_id:
232+
talk["zoom_meeting_id"] = meeting_id
234233
# Add this talk to researchseminars.org
235234
publish_to_researchseminars(talk)
236235
# Create comment in issue
@@ -262,7 +261,7 @@ def schedule_talks(repo, talks) -> int:
262261
yaml.dump(talks, serialized)
263262

264263
repo.update_file(
265-
TALKS_FILE, f"Added Zoom link{1} for {0} scheduled speakers\'"\
264+
common.TALKS_FILE, f"Added Zoom link{1} for {0} scheduled speakers\'"\
266265
"corner talk{1}".format(num_updated,'' if num_updated == 1 else 's'),
267266
serialized.getvalue(),
268267
sha=talks_data.sha,

0 commit comments

Comments
 (0)