-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.py
executable file
·75 lines (68 loc) · 1.54 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
import os
import os.path
import subprocess
import sys
import time
import hashlib
if os.path.exists('node_modules'):
print("Remove node_modules before running")
sys.exit(2)
if not os.path.exists('input-planet.osm.pbf'):
print("Place planet file to be processed in input-planet.osm.pbf")
sys.exit(2)
tic = time.time()
args = [
'docker',
'run',
'-it',
'--rm',
'-w',
'/wkd',
'-v',
f'{os.getcwd()}:/wkd',
'stefda/osmium-tool',
'osmium',
'tags-filter',
'input-planet.osm.pbf',
'-R',
'name,brand,operator,network',
'--overwrite',
'-o',
'filtered.osm.pbf',
]
print(f'Running docker command: {" ".join(args)}')
subprocess.run(args, check=True)
toc = time.time()
print(f'Took {toc-tic}s')
tic = time.time()
args = [
'docker',
'run',
'-it',
'--rm',
'-w',
'/wkd',
'-v',
f'{os.getcwd()}:/wkd',
'node:10',
'bash',
'-c',
'npm install && node collect_osm.js filtered.osm.pbf',
]
print(f'Running docker command: {" ".join(args)}')
subprocess.run(args, check=True)
toc = time.time()
print(f'Took {toc-tic}s')
print(f'Calculating hash of input-planet.osm.pbf')
tic = time.time()
md5_hash = hashlib.md5()
with open("input-planet.osm.pbf","rb") as fd:
# Read and update hash in chunks of 4K
for byte_block in iter(lambda: fd.read(4096),b""):
md5_hash.update(byte_block)
hash = md5_hash.hexdigest()
toc = time.time()
print(f'Got: {hash} Took {toc-tic}s')
with open("last_run.md5", "w") as fd:
fd.write(hash + '\n')