Eventboard_v_2.0/digit_converter.py

19 lines
601 B
Python
Raw Permalink Normal View History

2022-02-17 15:55:10 +01:00
# Digit converter
import json
def digit_convert(filename):
with open(filename, 'r') as file:
data = json.load(file)
for i in data:
if len(i['date']['day']) != 2:
i['date']['day'] = str('{:02d}'.format(i['date']['day']))
with open('events.json', 'w') as file:
json.dump(data, file, indent=2)
if len(i['date']['month']) != 2:
i['date']['month'] = str('{:02d}'.format(i['date']['month']))
with open('events.json', 'w') as file:
json.dump(data, file, indent=2)
digit_convert('events.json')