-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.py
46 lines (36 loc) · 1.42 KB
/
convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
import csv
import json
# Get the start line from the command-line arguments
if len(sys.argv) < 2:
print('Usage: python script.py start_line')
sys.exit(1)
start_line = int(sys.argv[1])
file = sys.argv[2]
# Open the CSV file
with open(file) as csv_file:
# Parse the CSV data into a dictionary
csv_reader = csv.DictReader(csv_file)
# Create a dictionary to hold the JSON data
json_data = {}
# Iterate over each row in the CSV data, starting from the specified line
for i, row in enumerate(csv_reader):
if i < start_line - 1:
continue
# Get the Ragam id for the current row
ragam_id = row['RAGAM ID']
# If this Ragam id isn't already in the JSON data, create a new object for it
if ragam_id not in json_data:
json_data[ragam_id] = {
'name': row['FULL NAME'].strip(),
'college': row['COLLEGE NAME'].strip(),
'workshops': [],
'dates': []
}
# Append the workshop and date to the appropriate arrays in the JSON data
json_data[ragam_id]['workshops'].append(row['TOPIC OF WORKSHOP'].upper().strip())
date = row['DATE ON WHICH YOU HAD ATTENDED THE WORKSHOP'].split()
json_data[ragam_id]['dates'].append(date[0])
# Save the JSON data to a file
with open('output.json', 'w') as output_file:
json.dump(json_data, output_file, indent=2)