diff --git a/.github/workflows/launch_events.yml b/.github/workflows/launch_events.yml new file mode 100644 index 0000000..f1b961d --- /dev/null +++ b/.github/workflows/launch_events.yml @@ -0,0 +1,125 @@ +name: Launch Events +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 - <