Skip to content

Commit

Permalink
Setup github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
chunlaw committed Nov 29, 2023
1 parent 2c49a78 commit de2a7b0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/crawl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Data Fetching
on:
push:
schedule:
- cron: "5 19 * * *"
workflow_dispatch:

jobs:
Fetch-Route-Data:
runs-on: ubuntu-latest

steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Setup Python environment
uses: actions/setup-python@v2
with:
python-version: '3.12'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./crawling/requirements.txt
- name: Crawling resources
run: python waypoints.py
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: waypoints # The folder the action should deploy.
single-commit: true
3 changes: 1 addition & 2 deletions waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import zipfile
import io
import gzip

r = requests.get("https://static.csdi.gov.hk/csdi-webpage/download/common/51bbe0d88d421c1e94572e503ad0428fabe11e3300c40e221146550044e54de5")
z = zipfile.ZipFile(io.BytesIO(r.content))
Expand All @@ -15,7 +14,7 @@

for feature in data["features"]:
properties = feature["properties"]
with gzip.open("waypoints/"+str(properties["ROUTE_ID"])+"-"+("O" if properties["ROUTE_SEQ"] == 1 else "I")+".json.gz", "wt") as f:
with open("waypoints/"+str(properties["ROUTE_ID"])+"-"+("O" if properties["ROUTE_SEQ"] == 1 else "I")+".json", "w") as f:
f.write(json.dumps({
"features": [feature],
"type": "FeatureCollection"
Expand Down

0 comments on commit de2a7b0

Please sign in to comment.