Ok I think I have gotten my head around it.
Incase anyone is interested, this is a python 2 script to batch convert LB xml's into RL game data ini's. You need to set the two variables to the respective LB + RL data folders.
Incase anyone is interested, this is a python 2 script to batch convert LB xml's into RL game data ini's. You need to set the two variables to the respective LB + RL data folders.
Code:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
from itertools import izip
from HTMLParser import HTMLParser
import os
import shutil
import re
import sys
import xml.etree.ElementTree as ET
try:
txt_encode = sys.getfilesystemencoding()
except:
txt_encode = 'utf-8'
reload(sys)
sys.setdefaultencoding('utf-8')
lb_dir = 'c:/Users/tw/Desktop/lb-rl-info'
rl_dir = 'c:/Users/tw/Desktop/lb-rl-output'
###
rl_dir_backup = os.path.join(rl_dir, 'backup')
for system in os.listdir(lb_dir):
if system.endswith(".xml"):
system_name = system[:-4]
print(system_name)
xml_lb = os.path.join(lb_dir, system)
ini_rl = os.path.join(rl_dir, system_name+'.ini')
h = HTMLParser()
if os.path.exists(ini_rl):
if not os.path.exists(rl_dir_backup):
os.makedirs(rl_dir_backup)
if os.path.exists(os.path.join(rl_dir_backup, system_name+'.ini')):
if os.path.exists(os.path.join(rl_dir_backup, system_name+'.ini.old')):
os.remove(os.path.join(rl_dir_backup, system_name+'.ini.old'))
shutil.move(os.path.join(rl_dir_backup, system_name+'.ini'), os.path.join(rl_dir_backup, system_name+'.ini.old'))
shutil.move(ini_rl, rl_dir_backup)
tree = ET.parse(xml_lb)
root = tree.getroot()
lb_label = ['Title', 'Publisher', 'Developer', 'ReleaseDate', 'Genre', 'StarRating', 'PlayMode', 'Rating', 'WikipediaURL', 'Notes']
rl_label = ['Title', 'Publisher', 'Developer', 'Released', 'Genre', 'Score', 'Players', 'Rating', 'Url', 'Description']
with open(ini_rl, 'w') as f:
for game in root.findall('Game'):
for lbl,rll in izip(lb_label, rl_label):
if game.find(lbl) != None and game.find(lbl).text:
if rll == 'Title':
info = '[' + h.unescape(game.find(lbl).text) + ']'
info = info.replace('\r', ' ').replace('\n', ' ') + "\n"
info = re.sub(' +', ' ', info)
elif rll == 'Released':
info = h.unescape(game.find(lbl).text)[:4]
info = rll + '=' + info + "\n"
else:
info = rll + '=' + h.unescape(game.find(lbl).text)
info = info.replace('\r', ' ').replace('\n', ' ') + "\n"
info = re.sub(' +', ' ', info)
f.write(info)
f.write("\n")