34 lines
917 B
Python
34 lines
917 B
Python
import json
|
|
|
|
def parse_journal_entries(file_path):
|
|
entries = []
|
|
current_entry = None
|
|
|
|
with open(file_path, 'r') as file:
|
|
for line in file:
|
|
line = line.strip()
|
|
if line.startswith('│'):
|
|
account, amount = line[1:].split()
|
|
current_entry['entries'].append({
|
|
'account': account,
|
|
'amount': float(amount)
|
|
})
|
|
elif line:
|
|
if current_entry is not None:
|
|
entries.append(current_entry)
|
|
current_entry = {'date': line, 'entries': []}
|
|
|
|
if current_entry is not None:
|
|
entries.append(current_entry)
|
|
|
|
return entries
|
|
|
|
def convert_to_json(entries):
|
|
return json.dumps(entries, indent=4)
|
|
|
|
file_path = 'main.gl'
|
|
journal_entries = parse_journal_entries(file_path)
|
|
json_data = convert_to_json(journal_entries)
|
|
print(json_data)
|
|
|