Untitled
unknown
python
3 years ago
837 B
8
Indexable
import csv
import json
import argparse
parser = argparse.ArgumentParser(description='Choose destinations for space stations')
parser.add_argument('--file', type=str, help='CSV file with tracks data')
parser.add_argument('--motor', type=str, default='puls', help='Type of motors to filter on')
args = parser.parse_args()
with open(args.file, newline='') as csvfile:
reader = csv.DictReader(csvfile, delimiter=':')
data = [row for row in reader if row['motor'] == args.motor]
destinations = {}
for row in data:
ship = row['ship']
start = row['start']
destination = row['destination']
if ship not in destinations:
destinations[ship] = []
destinations[ship].append(start)
destinations[ship].append(destination)
with open('destinations.json', 'w') as outfile:
json.dump(destinations, outfile)
Editor is loading...