Skip to content

Commit 1e85825

Browse files
Add GitHub Actions workflow for X-Bot daily posting
1 parent 39a0865 commit 1e85825

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

.github/workflows/x-bot-daily.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: X-Bot Daily Post
2+
3+
on:
4+
schedule:
5+
# Run at midnight UTC (00:00 GMT+0) every day
6+
- cron: '0 0 * * *'
7+
# Allow manual triggering for testing
8+
workflow_dispatch:
9+
10+
jobs:
11+
post-year-progress:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.10'
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r apps/x-bot/requirements.txt
27+
28+
- name: Run X-Bot
29+
env:
30+
API_KEY: ${{ secrets.API_KEY }}
31+
API_SECRET: ${{ secrets.API_SECRET }}
32+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
33+
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
34+
run: |
35+
cd apps/x-bot
36+
python bot.py

apps/x-bot/README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,41 @@ python bot.py
105105

106106
Verify the tweet posted correctly.
107107

108-
## ⏰ Automate with Cron
108+
## ⏰ Automate with GitHub Actions
109109

110-
Open your crontab:
110+
This bot is configured to run automatically using GitHub Actions. The workflow is set up to:
111111

112-
```
113-
crontab -e
114-
```
112+
1. Run daily at midnight (00:00 GMT+0)
113+
2. Use repository secrets for API credentials
114+
3. Allow manual triggering for testing
115115

116-
Add the cron job (adjust paths accordingly):
116+
### Setting Up GitHub Secrets
117117

118-
```
119-
0 0 \* \* \* cd /path/to/year-progress-bot && /path/to/year-progress-bot/venv/bin/python bot.py
120-
```
118+
For the GitHub Action to work, you need to add your X API credentials as repository secrets:
119+
120+
1. Go to your GitHub repository
121+
2. Navigate to Settings > Secrets and variables > Actions
122+
3. Add the following secrets:
123+
- `API_KEY` - Your X API Key
124+
- `API_SECRET` - Your X API Secret
125+
- `ACCESS_TOKEN` - Your X Access Token
126+
- `ACCESS_TOKEN_SECRET` - Your X Access Token Secret
127+
128+
### Manual Triggering
129+
130+
To manually trigger the workflow:
131+
132+
1. Go to your GitHub repository
133+
2. Navigate to Actions > X-Bot Daily Post
134+
3. Click "Run workflow"
121135

122136
## 📌 Verify Automation
123137

124-
Ensure the bot posts correctly at midnight (GMT+0). Check cron logs if troubleshooting is needed:
138+
After setting up the GitHub Action:
125139

126-
```bash
127-
grep CRON /var/log/syslog
128-
```
140+
1. Check the Actions tab in your repository to see if the workflow runs successfully
141+
2. Verify that tweets are posted to your X account at the scheduled time
129142

130143
##🎉 Done!
131144

132-
Your bot is live and will automatically post the years progress daily. Happy tweeting!
145+
Your bot is live and will automatically post the year's progress daily. Happy tweeting!

apps/x-bot/bot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import pathlib
66

77

8+
# Try to load from .env file for local development
89
current_dir = pathlib.Path(__file__).parent.absolute()
910
env_path = current_dir.parent.parent / '.env'
10-
load_dotenv(dotenv_path=env_path)
11+
if env_path.exists():
12+
load_dotenv(dotenv_path=env_path)
1113

1214
def year_progress_bar():
1315
today = datetime.datetime.now(datetime.timezone.utc)

0 commit comments

Comments
 (0)