This project serves as a lab manager for the Levenson-Falk Lab at USC. It automates reminders for maintenance, snacks, and manages lab meeting schedules through emails, Slack, and Google Calendar.
- .github/: Contains GitHub workflows for automation.
- calendar_manager.py: Manages Google Calendar integration.
- config_loader.py: Loads configuration from JSON files.
- email_notifier.py: Handles email notifications.
- main.py: The main script for managing notifications.
- slack_notifier.py: Manages Slack notifications.
- duty_tracker.json: Tracks the rotation of lab duties.
- trigger.sh: Script for running- main.pyin a scheduled manner.
- check_and_trigger.sh: Checks for missed executions and triggers- main.pyif needed.
- markers/: Directory where the marker file emissions are stored.
- 
Install Dependencies: Install the necessary dependencies from requirements.txt.python -m pip install --upgrade pip pip install -r requirements.txt 
- 
Set Up Environment Variables: Set up environment variables for Gmail, Slack, and Google Calendar credentials. export GMAIL_USER=<email> export GMAIL_PASSWORD=<password> export SLACK_TOKEN=<token> 
- 
Generate and Encrypt Sensitive Files: Move or generate the client_secret.json,token.pickle,service_key.json, andlab_members.jsonfiles locally. Encrypt these files using the following commands:openssl aes-256-cbc -salt -a -e -in client_secret.json -out client_secret.json.enc -pass pass:$SECRET_KEY -pbkdf2 openssl aes-256-cbc -salt -a -e -in token.pickle -out token.pickle.enc -pass pass:$SECRET_KEY -pbkdf2 openssl aes-256-cbc -salt -a -e -in service_key.json -out service_key.json.enc -pass pass:$SECRET_KEY -pbkdf2 openssl aes-256-cbc -salt -a -e -in lab_members.json -out lab_members.json.enc -pass pass:$SECRET_KEY -pbkdf2 
- 
Commit Encrypted Files to Repository: Commit and push the encrypted files ( *.enc) to your repository.
- 
Run the following command to set up Git hooks: 
./scripts/setup-hooks.sh- 
Create GitHub Secrets: Go to your GitHub repository settings, navigate to Secrets and variables->Actions, and add the following secrets:- SECRET_KEY: Your encryption password.
- GMAIL_USER: Your Gmail username.
- GMAIL_PASSWORD: Your Gmail password.
- SLACK_TOKEN: Your Slack token.
- GH_BOT: Your GitHub PAT with at least- reposcopes enabled.
 
- 
Create GitHub Actions Workflow: Create a workflow file in .github/workflows/main.yml. Check the GitHub Actions workflow in this repository for reference.The idea is to decrypt the sensitive files, set up the environment variables, and run the script using the decrypted files. 
Ensure that "Read and write permissions" are enabled in Settings -> Actions -> General -> Workflow permissions:
- 
Upload Script Files: Upload the script files and encrypted JSON files ( *.enc) to PythonAnywhere.
- 
Set Up Scheduled Task: Set up a scheduled task to run main.pydaily at 7 AM using cron.0 7 * * * /home/<username>/lfl-lab-manager/venv/bin/python /home/<username>/lfl-lab-manager/main.py 
- 
Upload and Decrypt Sensitive Files: Ensure client_secret.jsonandtoken.pickleare safely uploaded and handled. You may need to decrypt these files on PythonAnywhere before running your script.
- The script checks the validity of token.pickle.
- If re-authentication is required, it sends an email notification.
- Manually update token.pickleon PythonAnywhere after re-authenticating locally.
This updated blurb provides comprehensive instructions for setting up and running your workflow both locally and in the cloud using GitHub Actions and PythonAnywhere.
For Mac users, a method is provided to ensure trigger.sh runs even if the Mac is asleep at the scheduled time:
- 
Marker System: The trigger.shscript creates a daily marker file upon successful execution, indicating the script has run for that day.
- 
Missed Execution Check: check_and_trigger.shchecks for the presence of this marker file. If it's missing (indicating a missed execution), it runstrigger.sh.
- 
launchdDaemon: Alaunchdservice is set up to runcheck_and_trigger.shevery time the Mac wakes up, ensuring missed executions are caught.- Create com.user.checkandtrigger.plistin~/Library/LaunchAgents/with the following content:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.user.checkandtrigger</string> <key>ProgramArguments</key> <array> <string>/path/to/check_and_trigger.sh</string> </array> <key>WatchPaths</key> <array> <string>/var/log/powermanagement</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> 
- Load the launchdjob:launchctl load ~/Library/LaunchAgents/com.user.checkandtrigger.plist
 
- Create 
Note: For security, never store sensitive information like lab members' details and service keys in the repository.
The mm_calendar.py script automates the creation of calendar events based on a list of presentations from the APS March Meeting.
- Extracts presentation details from provided APS URLs.
- Automatically creates Google Calendar events with extracted details.
- Authenticates with Google Calendar API to manage calendar events.
- Ensure Google Calendar API credentials are set up and credentials.jsonis available.
- Populate url_listinmm_calendar.pywith APS meeting URLs to schedule.
- Run mm_calendar.pyto authenticate and create events in the specified Google Calendar.
Follow the local setup instructions for environment variables and authentication as described in the Setup and Operation section. Ensure MM_calendar_ID and MM_TIMEZONE are correctly set in your environment or .env file to match your Google Calendar settings.
Important: Keep token.pickle and credentials.json secure and update them as needed to maintain access to the Google Calendar API.
For detailed steps on handling authentication and deploying the script, refer to the Handling Authentication section.
Sensitive information is handled securely, and environment variables are used to store credentials.
Remember to keep the token.pickle and client_secret.json files secure and handle them carefully during deployment and updates.