Skip to content

Instantly share code, notes, and snippets.

@hakanu
Created March 30, 2016 09:58
Show Gist options
  • Save hakanu/7e8d67b3316b683bb39ce0b1a62d5ca5 to your computer and use it in GitHub Desktop.
Save hakanu/7e8d67b3316b683bb39ce0b1a62d5ca5 to your computer and use it in GitHub Desktop.
Eksisozluk backup xmllerini json formatina cevirmece konvertoru
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