Fetch and Upload Deutsche Bahn Data #338
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: Fetch and Upload Deutsche Bahn Data | |
| on: | |
| schedule: | |
| # Run every 6 hours at 3am, 9am, 3pm, 9pm UTC | |
| - cron: '0 3,9,15,21 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| date: | |
| description: 'Date in YYYY-MM-DD format (leave empty for today)' | |
| required: false | |
| type: string | |
| hours: | |
| description: 'Comma-separated hours 0-23 (e.g., "3,9,15,21" or leave empty for auto-calculated 6-hour window)' | |
| required: false | |
| type: string | |
| jobs: | |
| fetch-and-upload: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup uv | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| uv sync --python 3.13 | |
| - name: Fetch Deutsche Bahn data | |
| env: | |
| DB_API_KEY: ${{ secrets.DB_API_KEY }} | |
| DB_CLIENT_ID: ${{ secrets.DB_CLIENT_ID }} | |
| run: | | |
| # Create .env file with API key | |
| echo "DB_API_KEY=$DB_API_KEY" > .env | |
| # Use manual input date if provided, otherwise use today | |
| DATE="${{ inputs.date }}" | |
| if [ -z "$DATE" ]; then | |
| DATE=$(date -u +"%Y-%m-%d") | |
| fi | |
| # Use manual input hours if provided, otherwise calculate | |
| HOURS="${{ inputs.hours }}" | |
| if [ -z "$HOURS" ]; then | |
| # Calculate hours: current hour -3 to +2 (6 hour window) | |
| CURRENT_HOUR=$(date -u +"%H") | |
| HOURS="" | |
| for i in {-3..2}; do | |
| HOUR=$(( (10#$CURRENT_HOUR + i + 24) % 24 )) | |
| if [ -z "$HOURS" ]; then | |
| HOURS="$HOUR" | |
| else | |
| HOURS="$HOURS,$HOUR" | |
| fi | |
| done | |
| fi | |
| echo "Using date: $DATE" | |
| echo "Fetching data for hours: $HOURS" | |
| # Fetch data for the 6-hour window | |
| uv run python scripts/fetch_eva_plan_and_change.py --categories 1,2,3,4,5,6,7 --date "$DATE" --hours "$HOURS" | |
| - name: Upload data to Hugging Face | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| bash scripts/upload_data_to_huggingface.sh |