Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urllib
import yaml
from git import Repo
import re

ISO_8061_FORMAT = "YYYY-MM-DD[THH:MM:SS[±HH:MM]]"
UTC_FMT = '%Y-%m-%dT%H:%M:%SZ'
Expand Down Expand Up @@ -88,7 +89,9 @@ def get_trainer_keys(course_or_session, roles):
return list(set(keys))

def extract_course_code_from_title(config, title):
return eval('f' + repr(config['global']['course_code_template']))
if re.search(r'\[', title):
return eval('f' + repr(config['global']['course_code_template']))
return None

def get_survey_link(config, locale, title, date):
survey_template = config['survey'][f"survey_link_template_{locale}"]
Expand Down
56 changes: 31 additions & 25 deletions eventbrite_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,42 @@ def update_html(description, content, instructor_name):
start_date = min([to_iso8061(session['start_date']) for session in course['sessions']])
end_date = max([to_iso8061(session['end_date']) for session in course['sessions']])

eventid = eb.create_event_from(
event_id=first_session['template'],
title=first_session['title'],
start_date=start_date,
end_date=end_date,
tz=config["global"]["timezone"],
summary=event_description["summary"] if event_description else "",
)
calendar.set_eventbrite_id(first_session['course_id'], eventid)
calendar.update_spreadsheet()
print(f"Successfully created {first_session['title']}({eventid}) {start_date} {end_date}")
if args.dry_run:
print(f"Dry-run: would create event '{first_session['title']}' from template {first_session['template']} ({start_date} -> {end_date})")
else:
eventid = eb.create_event_from(
event_id=first_session['template'],
title=first_session['title'],
start_date=start_date,
end_date=end_date,
tz=config["global"]["timezone"],
summary=event_description["summary"] if event_description else "",
)
calendar.set_eventbrite_id(first_session['course_id'], eventid)
calendar.update_spreadsheet()
print(f"Successfully created {first_session['title']}({eventid}) {start_date} {end_date}")
else:
eventid = first_session['eventbrite_id']


# Update the event
if args.update or args.create:
if event_description:
# Update the description
eb.update_event_description(eventid, str(update_html(
eb.get_event_description(eventid)['description'],
event_description,
instructor,
)))
print(f'Successfully updated {eventid} description')

# Update tickets classes
hours = int(config["eventbrite"]["close_hours_before_event"])
eb.update_tickets(eventid, "", (to_iso8061(first_session['start_date']) - timedelta(hours=hours)).astimezone(timezone.utc).strftime(UTC_FMT))
print(f'Successfully updated {eventid} ticket classes')
if args.update:
if args.dry_run:
print(f"Dry-run: would update description and ticket classes for event {eventid}" f" for this course: {first_session['title']} " f"\nCurrent description: {eb.get_event_description(eventid)['description']}")
else:
if event_description:
# Update the description
eb.update_event_description(eventid, str(update_html(
eb.get_event_description(eventid)['description'],
event_description,
instructor,
)))
print(f'Successfully updated {eventid} description')

# Update tickets classes
hours = int(config["eventbrite"]["close_hours_before_event"])
eb.update_tickets(eventid, "", (to_iso8061(first_session['start_date']) - timedelta(hours=hours)).astimezone(timezone.utc).strftime(UTC_FMT))
print(f'Successfully updated {eventid} ticket classes')

# Update Zoom webinar
# Note: This merely creates a generic webinar, not a Zoom connection
Expand Down
17 changes: 10 additions & 7 deletions public_gcal_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import re

from common import valid_date, to_iso8061, ISO_8061_FORMAT, get_config
from common import extract_course_code_from_title
from common import actualize_repo

parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -106,11 +105,13 @@ def get_eb_event_by_date(query_date):
title = eb_event['name']['text']

if session['language'] == "FR":
presence = re.search(r'\[\s*([^\],]+)', session['title']).group(1)
if presence == "online" or presence == "en ligne":
presence = re.search(r'\[\s*([^\],]+)', session['title'])
if presence and presence.group(1) in ("online", "en ligne"):
presence = "online"
elif presence:
presence = "onsite"
else:
presence = "onsite"
presence = "online"
description = f"""Inscriptions: {registration_url}

{summary}
Expand All @@ -126,11 +127,13 @@ def get_eb_event_by_date(query_date):

"""
else:
presence = re.search(r'\[\s*([^\],]+)', session['title']).group(1)
if presence == "online" or presence == "en ligne":
_presence_match = re.search(r'\[\s*([^\],]+)', session['title'])
if _presence_match and _presence_match.group(1) in ("online", "en ligne"):
presence = "online"
else:
elif _presence_match:
presence = "onsite"
else:
presence = "online"
description = f"""Registration: {registration_url}

{summary}
Expand Down
3 changes: 1 addition & 2 deletions zoom_attendance_to_eventbrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import CQORCcalendar

from common import valid_date, to_iso8061, ISO_8061_FORMAT, get_config
from common import extract_course_code_from_title
from common import Trainers
from statistics import mean

Expand Down Expand Up @@ -194,7 +193,7 @@ def stringify_dict_ordered_by_name(d):

date = to_iso8061(eb_event['start']['local']).date()
locale = eb_event['locale'].split('_')[0]
course_code = extract_course_code_from_title(global_config, eb_event["name"]["text"])
course_code = course['sessions'][0]['code']
channel_name = eval('f' + repr(global_config['global']['slack_channel_template']))

if not slack.is_member(channel_name):
Expand Down