11import os
2+ import secrets
3+ from io import StringIO
4+ from typing import Tuple
5+ import datetime
6+
27import github
38import requests
4- import secrets
9+ from ruamel .yaml import YAML
10+ import jinja2
11+ import pytz
12+
513import common
614from researchseminarsdotorg import publish_to_researchseminars
715from host_key_rotation import host_key
8- from io import StringIO
9- from ruamel .yaml import YAML
16+
1017
1118ISSUE_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
1623EMAIL_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+
122124def 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
184186def 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