28 lines
546 B
Python
28 lines
546 B
Python
|
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}")
|