MCPcopy Create free account
hub / github.com/comaps/comaps / convert

Function convert

tools/python/taxi_csv_to_json.py:42–71  ·  view source on GitHub ↗
(src_path, dst_path)

Source from the content-addressed store, hash-verified

40
41
42def convert(src_path, dst_path):
43 try:
44 with open(src_path, "r") as f:
45 src = f.read()
46 except (OSError, IOError):
47 logging.error("Cannot read src file {}".format(src_path))
48 return
49
50 countries, mwms = deserialize_places(src)
51
52 # Carcass of the result.
53 result = {
54 "enabled": {"countries": [], "mwms": []},
55 "disabled": {"countries": [], "mwms": []}
56 }
57
58 for country, cities in countries.iteritems():
59 result["enabled"]["countries"].append({
60 "id": country,
61 "cities": cities
62 })
63
64 result["enabled"]["mwms"] = mwms
65
66 try:
67 with open(dst_path, "w") as f:
68 json.dump(result, f, indent=2, sort_keys=True)
69 except (OSError, IOError):
70 logging.error("Cannot write result into dst file {}".format(dst_path))
71 return
72
73
74def process_options():

Callers 1

mainFunction · 0.70

Calls 6

deserialize_placesFunction · 0.85
formatMethod · 0.80
iteritemsMethod · 0.80
dumpMethod · 0.80
readMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected