Skip to content

Commit a3f550d

Browse files
committed
Fix unicode encoding error with CSV parsing
1 parent c6eba60 commit a3f550d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

scripts/make_stations_csv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main():
1515
transfers = {}
1616

1717
# load stops into a dict
18-
with open(args.stops_file, 'rb') as f:
18+
with open(args.stops_file, 'r') as f:
1919
reader = csv.DictReader(f)
2020
for row in reader:
2121
if row['parent_station']:
@@ -28,7 +28,7 @@ def main():
2828
}
2929

3030
# load transfer groups into a dict. duplicates will be filtered out later
31-
with open(args.transfers_file, 'rb') as f:
31+
with open(args.transfers_file, 'r') as f:
3232
reader = csv.DictReader(f)
3333
for row in reader:
3434
if row['from_stop_id'] == row['to_stop_id']:

scripts/make_stations_json.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main():
1111
args = parser.parse_args()
1212

1313
stations = {}
14-
with open(args.stations_file, 'rb') as f:
14+
with open(args.stations_file, 'r') as f:
1515
reader = csv.DictReader(f)
1616
for row in reader:
1717

@@ -33,11 +33,11 @@ def main():
3333
sum(v[0] for v in station['stops'].values()) / float(len(station['stops'])),
3434
sum(v[1] for v in station['stops'].values()) / float(len(station['stops']))
3535
]
36-
station['id'] = md5(''.join(station['stops'].keys())).hexdigest()[:ID_LENGTH]
36+
station['id'] = md5(''.join(station['stops'].keys()).encode('utf-8')).hexdigest()[:ID_LENGTH]
3737

3838
while station['id'] in keyed_stations:
3939
# keep hashing til we get a unique ID
40-
station['id'] = md5(station['id']).hexdigest()[:ID_LENGTH]
40+
station['id'] = md5(station['id'].encode('utf-8')).hexdigest()[:ID_LENGTH]
4141

4242
keyed_stations[station['id']] = station
4343

0 commit comments

Comments
 (0)