Update News Sentiment Daily #61
This file contains hidden or 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
| name: Update News Sentiment Daily | |
| on: | |
| schedule: | |
| - cron: '0 12 * * *' # Runs daily at 12:00 UTC | |
| workflow_dispatch: # Allows manual triggering of the workflow | |
| permissions: | |
| contents: write # Grants write access to the repository contents | |
| jobs: | |
| update-sentiment: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} # Ensures the checkout uses the token with write permissions | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.9' # Specify the Python version you need | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install requests vaderSentiment pandas | |
| - name: Run Sentiment Analysis Script | |
| env: | |
| NEWSAPI_KEY: ${{ secrets.NEWSAPI_KEY }} | |
| run: | | |
| python scripts/update_sentiment.py | |
| - name: Commit and Push Changes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add news_sentiment.csv | |
| # Check if there are changes to commit | |
| if ! git diff --quiet; then | |
| git commit -m "Update news sentiment data [skip ci]" | |
| # Update the remote URL to include the GITHUB_TOKEN for authentication | |
| git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git | |
| git push origin main | |
| else | |
| echo "No changes to commit." | |
| fi |