Created
March 30, 2016 09:58
-
-
Save hakanu/7e8d67b3316b683bb39ce0b1a62d5ca5 to your computer and use it in GitHub Desktop.
Eksisozluk backup xmllerini json formatina cevirmece konvertoru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import re | |
import sys | |
entry_xml_path = sys.argv[1] | |
print 'parsing: ', entry_xml_path | |
lines = open(entry_xml_path, 'r').read().split('\n') | |
entry_dict = {} | |
entries = [] | |
author = '' | |
for i in range(0, len(lines)): | |
line = lines[i] | |
if line.startswith('<entry'): | |
entry = {} | |
title_match = re.match( r'<entry title="(.*?)" id="(.*?)" date="(.*?)">', line) | |
entry = { | |
'title': title_match.group(1), | |
'id': title_match.group(2), | |
'date': title_match.group(3), | |
'content': lines[i + 1], | |
'author': author, | |
} | |
entries.append(entry) | |
i += 1 | |
elif line.startswith('<backup nick="'): | |
author = re.match(r'<backup nick="(.*)" backupdate="', line).group(1) | |
entry_dict['entries'] = entries | |
open(entry_xml_path + '.json', 'w').write(json.dumps(entry_dict, indent=4)) | |
print 'Done parsing: ', len(entry_dict['entries']), ' entries.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment