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

Function deserialize_places

tools/python/taxi_csv_to_json.py:11–39  ·  view source on GitHub ↗
(src)

Source from the content-addressed store, hash-verified

9
10
11def deserialize_places(src):
12 lines = src.splitlines()
13 # Skip header.
14 lines = lines[1:]
15 countries = defaultdict(list)
16 mwms = []
17
18 try:
19 for l in lines:
20 cells = l.split('\t')
21
22 if len(cells) < 5 and not cells[0]:
23 logging.error("Country cell is empty. Incorrect line: {}".format(cells))
24 exit()
25
26 # Add full country.
27 if len(cells) < 3:
28 countries[cells[0]] = []
29 # Add city of the country.
30 elif len(cells) < 5:
31 countries[cells[0]].append(cells[2])
32 # Add mwm.
33 elif len(cells) >= 5:
34 mwms.append(cells[4])
35 except IndexError as e:
36 logging.error("The structure of src file is incorrect. Exception: {}".format(e))
37 exit()
38
39 return countries, mwms
40
41
42def convert(src_path, dst_path):

Callers 1

convertFunction · 0.85

Calls 2

formatMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected