Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
jr
Commits
dc91f7a6
Commit
dc91f7a6
authored
11 months ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
gtfs_make_shape_by_id
parent
a99caedf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
prog/gtfs_make_shape_by_id.py
+38
-0
38 additions, 0 deletions
prog/gtfs_make_shape_by_id.py
with
38 additions
and
0 deletions
prog/gtfs_make_shape_by_id.py
0 → 100755
+
38
−
0
View file @
dc91f7a6
#!/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
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment