Blame view

data/catalog/txt2json.py 927 Bytes
b03d5eb1   Goutte   Add the last CME ...
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

# Small tool to convert txt catalogs
# /!. OVERWRITES EXISTING OUTPUT FILE

import json
import datetime

input_txt_file = 'univ_all.txt'

output_json_file = 'univ_all.json'

LINES_TO_SKIP = 4


json_data = {
    "columns": ['DATETIME'],
    "data": []
}

with open(input_txt_file) as fp:
    skipped_lines_count = 0
    for line in fp:
        if skipped_lines_count < LINES_TO_SKIP:
            skipped_lines_count += 1
            continue

        input_datetime_string = line[0:20]

        input_datetime = datetime.datetime.strptime(
            input_datetime_string,
            "%Y/%m/%d  %H:%M:%S"
        )

54bb1311   Goutte   Bring back the CM...
34
35
        output_datetime_string = input_datetime.strftime("%Y-%m-%dT%H:%MZ")
        # output_datetime_string = input_datetime.isoformat() + 'Z'
b03d5eb1   Goutte   Add the last CME ...
36
37
38
39
40
41
42
43

        json_data['data'].append([output_datetime_string])


with open(output_json_file, 'w') as fp:
    json.dump(json_data, fp, sort_keys=True)

print("Done.")