Scrape Instagram and Store Events #149
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: Scrape Instagram and Store Events | |
| on: | |
| schedule: | |
| - cron: '0 11 * * *' # Once daily at noon UTC (8am EST) | |
| workflow_dispatch: # Optional manual trigger | |
| inputs: | |
| run_scraper: | |
| required: true | |
| type: boolean | |
| default: true | |
| scroll_limit: | |
| description: 'Number of scrolls of home feed' | |
| required: false | |
| default: 50 | |
| jobs: | |
| instagram_feed: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| env: | |
| SUPABASE_DB_URL: ${{ secrets.SUPABASE_DB_URL }} | |
| POSTGRES_DB: ${{ secrets.POSTGRES_DB }} | |
| POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | |
| POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
| POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }} | |
| POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }} | |
| USERNAME: ${{ secrets.USERNAME }} | |
| PASSWORD: ${{ secrets.PASSWORD }} | |
| SESSIONID: ${{ secrets.SESSIONID }} | |
| CSRFTOKEN: ${{ secrets.CSRFTOKEN }} | |
| DS_USER_ID: ${{ secrets.DS_USER_ID }} | |
| IG_DID: ${{ secrets.IG_DID }} | |
| MID: ${{ secrets.MID }} | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| DOC_ID: ${{ secrets.DOC_ID }} | |
| USER_AGENT: ${{ secrets.USER_AGENT }} | |
| X_IG_APP_ID: ${{ secrets.X_IG_APP_ID }} | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }} | |
| AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Cache pip | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| working-directory: backend | |
| run: | | |
| pip install --upgrade pip setuptools wheel | |
| pip install -r requirements.txt | |
| - name: Create logs directory | |
| working-directory: backend/scraping | |
| run: mkdir -p logs | |
| - name: Configure AWS CLI | |
| run: | | |
| aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID | |
| aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY | |
| aws configure set default.region $AWS_DEFAULT_REGION | |
| - name: Download Chrome profile from S3 | |
| run: | | |
| mkdir -p backend/scraping/chrome_profile | |
| aws s3 sync s3://$AWS_S3_BUCKET_NAME/chrome_profile/ backend/scraping/chrome_profile/ | |
| - name: Run scraper | |
| if: github.event_name == 'schedule' || github.event.inputs.run_scraper == 'true' | |
| working-directory: backend/scraping | |
| run: | | |
| python -u selenium_scraper.py --scroll-limit ${{ github.event.inputs.scroll_limit }} 2>&1 | tee logs/scraping.log | |
| continue-on-error: false | |
| - name: Upload logs as artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: scraping-logs-${{ github.run_number }} | |
| path: | | |
| backend/scraping/logs/ | |
| backend/scraping/*.log | |
| backend/scraping/*.csv | |
| retention-days: 30 | |
| - name: Upload Chrome profile to S3 | |
| run: | | |
| aws s3 sync backend/scraping/chrome_profile/ s3://$AWS_S3_BUCKET_NAME/chrome_profile/ | |
| - name: Generate static events file | |
| id: generate_static | |
| working-directory: backend/scraping | |
| run: python get_static_events.py | |
| - name: Commit and push changes | |
| if: steps.generate_static.outcome == 'success' | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add frontend/src/data/staticEvents.ts | |
| git commit -m "chore: update static events from DB" || echo "No changes to commit" | |
| git push |