Skip to content

Commit

Permalink
gz all the waypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
chunlaw committed Nov 28, 2023
1 parent 5abd751 commit 18d143f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crawling/waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
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))
with z.open("FB_ROUTE_LINE.json") as f:
data = json.loads(re.sub(r"([0-9]+\.[0-9]{6})[0-9]+", r"\1", f.read().decode("utf-8")).replace("\n", ""))

print (data["type"])
os.makedirs("waypoints", exist_ok=True)

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

0 comments on commit 18d143f

Please sign in to comment.