Spaces:
Runtime error
Runtime error
Download .github/workflows/sync-meta.yml from BinbomJared/DM-Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/spaces/BinbomJared/DM-Agent/resolve/main/.github/workflows/sync-meta.yml
- Command line
-
hf download hf://spaces/BinbomJared/DM-Agent/.github/workflows/sync-meta.yml
-
curl -L -o sync-meta.yml https://huggingface.co/spaces/BinbomJared/DM-Agent/resolve/main/.github/workflows/sync-meta.yml
1.75 kB
| name: Sync Meta Ads Data | |
| on: | |
| schedule: | |
| - cron: "0 1 * * *" # UTC 01:00 = 北京时间 09:00 | |
| workflow_dispatch: | |
| inputs: | |
| days_back: | |
| description: "拉取最近几天的数据" | |
| required: false | |
| default: "7" | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: pip install requests pandas gspread google-auth pyyaml python-dotenv openpyxl | |
| - name: Sync Meta data to Google Sheets | |
| env: | |
| META_ACCESS_TOKEN: ${{ secrets.META_ACCESS_TOKEN }} | |
| META_AD_ACCOUNTS: ${{ secrets.META_AD_ACCOUNTS }} | |
| GOOGLE_OAUTH_REFRESH_TOKEN: ${{ secrets.GOOGLE_OAUTH_REFRESH_TOKEN }} | |
| GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.GOOGLE_OAUTH_CLIENT_ID }} | |
| GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }} | |
| run: | | |
| python -c " | |
| import sys, os, logging | |
| sys.path.insert(0, '.') | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s') | |
| from src.meta_api import fetch_meta_data | |
| from src.loader import write_api_data_to_sheets | |
| days = int('${{ github.event.inputs.days_back || 7 }}') | |
| print(f'Fetching Meta data (last {days} days)...') | |
| df = fetch_meta_data(days_back=days) | |
| if df.empty: | |
| print('No data fetched.') | |
| sys.exit(0) | |
| print(f'Fetched {len(df)} rows, date range: {df[\"date\"].min()} ~ {df[\"date\"].max()}') | |
| result = write_api_data_to_sheets(df) | |
| print(f'Written to Sheets: {result[\"added\"]} new rows') | |
| " | |