-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f29eebe
commit c1a57aa
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
name: Launch Event Emailer | ||
on: workflow_dispatch | ||
|
||
jobs: | ||
generate_event_reminders: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install pandas | ||
python -m pip install pyyaml | ||
- name: Read TSV and generate event scripts | ||
run: | | ||
import pandas as pd | ||
import yaml | ||
from datetime import datetime, timedelta | ||
# Load TSV files | ||
events_df = pd.read_csv('events.tsv', delimiter='\t') | ||
emails_df = pd.read_csv('email_addresses.csv') | ||
# Filter email addresses | ||
sender_email = emails_df[emails_df['Role'] == 'Sender']['Email address'].iloc[0] | ||
admin_emails = emails_df[emails_df['Role'] == 'Admin']['Email address'].tolist() | ||
organizer_emails = emails_df[emails_df['Role'] == 'Organizer']['Email address'].tolist() | ||
admin_emails_str = ', '.join(admin_emails) | ||
organizer_emails_str = ', '.join(organizer_emails) | ||
# Function to create event reminder scripts | ||
def create_event_script(event_name, date_str, content, frequency, day_of_week, date, time, location): | ||
event_date = datetime.strptime(date_str, '%Y-%m-%d') | ||
trigger_time = (event_date - timedelta(days=1)).strftime('%Y-%m-%dT14:00:00Z') # 9 AM ET is 14:00 UTC | ||
# Email content | ||
with open(f'templates/{content}', 'r') as file: | ||
email_content = file.read() | ||
# Replace placeholders with actual values | ||
email_content = email_content.replace('{DATE}', date).replace('{TIME}', time).replace('{LOCATION}', location) | ||
# Read admin.md template | ||
with open('templates/admin.md', 'r') as file: | ||
admin_template = file.read() | ||
# Insert event content into admin template | ||
announcement_content = admin_template.replace('===BEGIN===', '===BEGIN===\n' + email_content).replace('===END===', '\n===END===') | ||
# Create GitHub Action YAML | ||
action_script = { | ||
'name': f'Reminder for {event_name}', | ||
'on': { | ||
'schedule': [ | ||
{'cron': trigger_time} | ||
] | ||
}, | ||
'jobs': { | ||
'send_email': { | ||
'runs-on': 'ubuntu-latest', | ||
'steps': [ | ||
{'name': 'Checkout repository', 'uses': 'actions/checkout@v2'}, | ||
{'name': 'Set up Python', 'uses': 'actions/setup-python@v2', 'with': {'python-version': '3.x'}}, | ||
{'name': 'Install dependencies', 'run': 'pip install smtplib email'}, | ||
{'name': 'Send email', 'run': f'''\ | ||
python - <<EOF | ||
import smtplib | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
|
||
sender_email = "{sender_email}" | ||
receiver_email = "{admin_emails_str}" | ||
cc_email = "{organizer_emails_str}" | ||
subject = "{event_name} Reminder" | ||
|
||
msg = MIMEMultipart() | ||
msg['From'] = sender_email | ||
msg['To'] = receiver_email | ||
msg['Cc'] = cc_email | ||
msg['Subject'] = subject | ||
|
||
body = """{announcement_content}""" | ||
msg.attach(MIMEText(body, 'plain')) | ||
|
||
server = smtplib.SMTP('smtp.gmail.com', 587) | ||
server.starttls() | ||
server.login(sender_email, "${{ secrets.GMAIL_PASSWORD }}") | ||
text = msg.as_string() | ||
server.sendmail(sender_email, receiver_email.split(", ") + cc_email.split(", "), text) | ||
server.quit() | ||
EOF | ||
'''} | ||
] | ||
} | ||
} | ||
} | ||
# Write action script to file | ||
with open(f'.github/workflows/reminder_{event_name}.yml', 'w') as file: | ||
yaml.dump(action_script, file) | ||
|
||
# Process each event | ||
for _, row in events_df.iterrows(): | ||
event_name = row['Event Name'] | ||
start_date = row['Start Date'] | ||
frequency = row['Frequency'] | ||
content_file = row['Content File'] | ||
date = row['Date'] | ||
time = row['Time'] | ||
location = row['Location'] | ||
|
||
if frequency == 'O' or pd.isna(frequency): | ||
create_event_script(event_name, start_date, content_file, 'one-time', None, date, time, location) | ||
elif frequency.startswith('W-'): | ||
day_of_week = frequency.split('-')[1] | ||
create_event_script(event_name, start_date, content_file, 'weekly', day_of_week, date, time, location) | ||
elif frequency == 'M': | ||
create_event_script(event_name, start_date, content_file, 'monthly', None, date, time, location) |