ub-movements-test/parse_data.py

28 lines
546 B
Python
Raw Normal View History

import csv
import json
node_names = set()
edges = []
with open("data/requests.csv") as fp:
reader = csv.DictReader(fp, delimiter=";")
for item in reader:
node_names.add(item['Owning Library Name'])
node_names.add(item['Pickup Location'])
edges.append(item)
nodes = [{'name': n} for n in node_names]
print(f"{len(nodes)} nodes, {len(edges)} edges")
data = {
'nodes': nodes,
'edges': edges
}
fn = 'data/parsed_requests.json'
with open(fn, 'w') as fp:
json.dump(data, fp)
print(f"Written to {fn}")