From c86b4655f72c86362c064dd50bb701782b39e6eb Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Sun, 20 Apr 2025 19:34:56 +0200 Subject: Update stop overrides --- .github/workflows/update-stops-data.yml | 65 +++++++++++++++++++++++++++ data/download-stops.py | 28 +++++------- data/stop-overrides.yaml | 75 +++++++++++++++++++++++-------- public/stops.json | 80 --------------------------------- 4 files changed, 131 insertions(+), 117 deletions(-) create mode 100644 .github/workflows/update-stops-data.yml diff --git a/.github/workflows/update-stops-data.yml b/.github/workflows/update-stops-data.yml new file mode 100644 index 0000000..1b72cdc --- /dev/null +++ b/.github/workflows/update-stops-data.yml @@ -0,0 +1,65 @@ +name: Update Stops Data + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +jobs: + update-stops-data: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Run download script + run: python data/download-stops.py + + - name: Commit changes if any + id: commit + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + git add public/stops.json + if git diff --staged --exit-code; then + echo "No changes to commit" + echo "changes_made=false" >> $GITHUB_OUTPUT + else + # Create a new branch with timestamp + BRANCH_NAME="update-stops-data-$(date +%Y-%m-%d-%H%M%S)" + git checkout -b $BRANCH_NAME + git commit -m "Update stops data" + git push origin $BRANCH_NAME + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT + echo "changes_made=true" >> $GITHUB_OUTPUT + fi + + - name: Create Pull Request + if: steps.commit.outputs.changes_made == 'true' + env: + GH_TOKEN: ${{ github.token }} + BRANCH_NAME: ${{ steps.commit.outputs.branch_name }} + run: | + # Close any existing PRs created by this action + existing_prs=$(gh pr list --json number,title,headRefName --search "Update stops data in:title head:update-stops-data- author:app/github-actions is:open") + + if [[ $(echo "$existing_prs" | jq length) -gt 0 ]]; then + echo "Found existing PRs to close" + echo "$existing_prs" | jq -c '.[]' | while read pr; do + pr_number=$(echo "$pr" | jq -r '.number') + echo "Closing PR #$pr_number" + gh pr close $pr_number --comment "Superseded by a new PR with updated data" + done + fi + + # Create new PR + gh pr create \ + --title "Update stops data" \ + --body "Automatically generated PR with updated stops data from scheduled fetch." \ + --base main \ + --head "$BRANCH_NAME" \ No newline at end of file diff --git a/data/download-stops.py b/data/download-stops.py index 2720014..957e50d 100644 --- a/data/download-stops.py +++ b/data/download-stops.py @@ -33,12 +33,6 @@ def apply_overrides(stops, overrides): # Apply or add alternate names if "alternateNames" in override: - if isinstance(stop["name"], str): - # Convert simple name to object if it's a string - original_name = stop["name"] - stop["name"] = {"original": original_name} - - # Add alternate names for key, value in override["alternateNames"].items(): stop["name"][key] = value @@ -49,20 +43,14 @@ def apply_overrides(stops, overrides): if "longitude" in override["location"]: stop["longitude"] = override["location"]["longitude"] - # Add notes - if "notes" in override: - stop["notes"] = override["notes"] - - # Add active status - if "active" in override: - stop["active"] = override["active"] - # Add amenities if "amenities" in override: stop["amenities"] = override["amenities"] - - print(f"Applied overrides to stop {stop_id} ({stop['name']})") - + + # Mark stop as hidden if needed + if "hide" in override: + stop["hide"] = override["hide"] + return stops def main(): @@ -100,11 +88,15 @@ def main(): overrides = load_stop_overrides(overrides_file) processed_stops = apply_overrides(processed_stops, overrides) + # Filter out hidden stops + visible_stops = [stop for stop in processed_stops if not stop.get("hide")] + print(f"Removed {len(processed_stops) - len(visible_stops)} hidden stops") + # Save to public directory output_file = os.path.join(script_dir, "..", "public", "stops.json") with open(output_file, 'w', encoding='utf-8') as f: - json.dump(processed_stops, f, ensure_ascii=False, indent=2) + json.dump(visible_stops, f, ensure_ascii=False, indent=2) print(f"Saved processed stops data to {output_file}") return 0 diff --git a/data/stop-overrides.yaml b/data/stop-overrides.yaml index 6dfc23f..f20f633 100644 --- a/data/stop-overrides.yaml +++ b/data/stop-overrides.yaml @@ -7,32 +7,69 @@ # location: # Override location coordinates # latitude: # New latitude value # longitude: # New longitude value -# notes: # Additional notes about the stop -# active: # Boolean to indicate if stop is active +# hide: # Hide the stop from the map and list # amenities: # List of amenities available at this stop # - shelter # Marquesina # - real-time display # Display with real-time information -6930: # Praza de América 1 - alternateNames: - intersect: "Praza América - Camelias" - amenities: - - shelter - - real-time display - -14264: - alternateNames: - intersect: "Urzáiz - Príncipe" - amenities: - - shelter - - real-time display - -6620: +#6930: # Praza de América 1 +# alternateNames: + +# intersect: "Praza América - Camelias" +# amenities: +# - shelter +# - real-time display + +#14264: # Urzáiz - Príncipe +# alternateNames: +# intersect: "Urzáiz - Príncipe" +# amenities: +# - shelter +# - real-time display + +6620: # Policarpo Sanz, 40 location: latitude: 42.23757846151978 longitude: -8.721031378896738 -20193: +20193: # Policarpo Sanz, 25 location: latitude: 42.23767601188501 - longitude: -8.721582630122455 \ No newline at end of file + longitude: -8.721582630122455 + +5720: # Gregorio Espino, 33 + location: + latitude: 42.23004933454558 + longitude: -8.706947409683313 + +5710: # Gregorio Espino, 22 + location: + latitude: 42.23003666347398 + longitude: -8.707266671978003 + +5730: # Gregorio Espino, 44 + location: + latitude: 42.227850036119314 + longitude: -8.708105429626789 + +5740: # Gregorio Espino, 57 + location: + latitude: 42.22783722597372 + longitude: -8.707849091551859 + +#region Hidden stops +20223: # Castrelos (Pavillón) - Final U1 + hide: true +20146: # García Barbón 7 - final líneas A y 18A + hide: true +20220: # (Samil) COIA-SAMIL - Final L15A + hide: true +20001: # (Samil) Samil por Beiramar - Final L15B + hide: true +20002: # (Samil) Samil por Torrecedeira - Final L15C + hide: true +20144: # (Samil) Samil por Coia - Final C3D+C3i + hide: true +20145: # (Samil) Samil por Bouzas - Final C3D+C3i + hide: true +#endregion \ No newline at end of file diff --git a/public/stops.json b/public/stops.json index ed2eb4f..b5420df 100644 --- a/public/stops.json +++ b/public/stops.json @@ -1571,18 +1571,6 @@ "15A" ] }, - { - "stopId": 20145, - "name": { - "original": "Samil por Bouzas" - }, - "latitude": 42.215944153, - "longitude": -8.774726162, - "lines": [ - "C3d", - "C3i" - ] - }, { "stopId": 6790, "name": { @@ -1723,18 +1711,6 @@ "PSA 4" ] }, - { - "stopId": 20144, - "name": { - "original": "Samil por Coia" - }, - "latitude": 42.215903856, - "longitude": -8.774724852, - "lines": [ - "C3d", - "C3i" - ] - }, { "stopId": 14299, "name": { @@ -7124,18 +7100,6 @@ "A" ] }, - { - "stopId": 20146, - "name": { - "original": "Avda. de García Barbón 7" - }, - "latitude": 42.237488035, - "longitude": -8.719378239, - "lines": [ - "A", - "18A" - ] - }, { "stopId": 430, "name": { @@ -9907,17 +9871,6 @@ "11" ] }, - { - "stopId": 20002, - "name": { - "original": "Samil por Torrecedeira" - }, - "latitude": 42.213660664, - "longitude": -8.774571223, - "lines": [ - "15C" - ] - }, { "stopId": 20143, "name": { @@ -9953,17 +9906,6 @@ "15B" ] }, - { - "stopId": 20220, - "name": { - "original": "COIA - SAMIL" - }, - "latitude": 42.213783955, - "longitude": -8.774372371, - "lines": [ - "15A" - ] - }, { "stopId": 1580, "name": { @@ -13659,17 +13601,6 @@ "15B" ] }, - { - "stopId": 20001, - "name": { - "original": "Samil por Beiramar" - }, - "latitude": 42.213957029, - "longitude": -8.774591463, - "lines": [ - "15B" - ] - }, { "stopId": 14409, "name": { @@ -15147,16 +15078,5 @@ "lines": [ "U1" ] - }, - { - "stopId": 20223, - "name": { - "original": "Avda. de Castrelos (Pavillón)" - }, - "latitude": 42.219691433, - "longitude": -8.732510039, - "lines": [ - "U1" - ] } ] \ No newline at end of file -- cgit v1.3