Skip to content
Snippets Groups Projects
Commit dc91f7a6 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

gtfs_make_shape_by_id

parent a99caedf
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env pypy3
import sys, os, shutil
import tempfile
from pathlib import Path
path = Path(sys.argv[1])
tmp_dir = tempfile.mkdtemp(dir="tmp")
print(tmp_dir)
with open(path/"shapes.txt") as inf:
assert inf.readline().strip() == 'shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled'
outf = None
last_shape_id = None
while True:
try:
l = inf.readline().strip()
except EOFError:
break
if l == '':
break
shape_id, rest = l.split(",", 1)
if last_shape_id == None or shape_id != last_shape_id:
if outf: outf.close()
outf = open(Path(tmp_dir)/shape_id, 'x')
outf.write('shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled\n')
outf.write(rest+'\n')
last_shape_id = shape_id
if outf: outf.close()
if Path(path/'shape_by_id').is_dir():
shutil.rmtree(path/'shape_by_id')
os.rename(tmp_dir, path/'shape_by_id')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment