def getLanguage(id): response = chpp.getFile('translations', params={ 'version': '1.1', 'languageId': id }) xml = ET.fromstring(response.content) obj = {} XMLParser.xml_to_python(xml, obj) return obj
def run(repo_dir=os.path.dirname(os.path.abspath(__file__)) + '/../..'): base_path = os.path.expanduser(repo_dir) for langId in Language.Codes: code = Language.Codes[langId] langObject = getLanguage(langId) result = parseLanguage(langObject['HattrickData'], code) output = XMLParser.python_to_json({'language': result}) of = '%s/content/locale/%s/htlang.json' % (base_path, code) o = codecs.open(os.path.expanduser(of), mode='w', encoding='utf-8') o.write(output) o.close()
def run(): scriptDir = os.path.dirname(os.path.abspath(__file__)) for langId in Language.Codes: code = Language.Codes[langId] langObject = getLanguage(langId) result = parseLanguage(langObject['HattrickData'], code) output = XMLParser.python_to_json({'language': result}) of = '%s/../../content/locale/%s/htlang.json' % (scriptDir, code) o = codecs.open(of, mode='w', encoding='utf-8') o.write(output) o.close()
# add valid staff staff.append(person) # add new supporters for new_id in supporters: new_person = {'id': str(new_id), 'name': '', 'duty': 'supporter'} staff.append(new_person) # update manager names from CHPP for person in staff: ht_id = person['id'] resp = chpp.getFile('search', params={'searchType': 2, 'searchID': ht_id}) dom = ET.fromstring(resp.content) result = dict() XMLParser.xml_to_python(dom, result) container = result['HattrickData']['SearchResults'] new_name = container['Result'][ 'ResultName'] if 'Result' in container else '' if not new_name or new_name.startswith('DEL_'): if not person['name']: person['name'] = '<>' elif not person['name'].startswith('<'): person['name'] = f"<{person['name']}>" else: # already replaced pass else: person['name'] = new_name
#!/usr/bin/env python from Hattrick.Parsers import XMLParser import xml.etree.ElementTree as ET import sys import re import codecs files = sys.argv files.pop(0) p = re.compile('(\\.xml)?$') for f in files: xml = ET.parse(f) of = p.sub('.json', f) o = codecs.open(of, mode='w', encoding='utf-8') o.write(XMLParser.toJSON(xml)) o.close()
def output_currencies(output_dir, cur_list): output_path = output_dir + '/htcurrency.json' output = {'hattrickcurrencies': cur_list} with codecs.open(output_path, mode='w', encoding='utf-8') as cur_file: cur_file.write(XMLParser.python_to_json(output))
def getLanguage(id): response = chpp.getFile('translations', params={'version':'1.1', 'languageId': id }) xml = ET.fromstring(response.content) obj = {} XMLParser.xml_to_python(xml, obj) return obj
def output_currencies(output_dir, cur_list): output_path = output_dir + '/htcurrency.json' output = { 'hattrickcurrencies': cur_list } with codecs.open(output_path, mode='w', encoding='utf-8') as cur_file: cur_file.write(XMLParser.python_to_json(output))
#!/usr/bin/python from Hattrick.Parsers import XMLParser import xml.etree.ElementTree as ET import sys import re import codecs files = sys.argv files.pop(0) p = re.compile('(\\.xml)?$') for f in files: xml = ET.parse(f) of = p.sub('.json', f) o = codecs.open(of, mode='w', encoding='utf-8') o.write(XMLParser.toJSON(xml)) o.close()
# skip no longer valid supporters continue # add valid staff staff.append(person) # add new supporters for new_id in supporters: new_person = { 'id': str(new_id), 'name': '', 'duty': 'supporter' } staff.append(new_person) # update manager names from CHPP for person in staff: ht_id = person['id'] resp = chpp.getFile('search', params={ 'searchType': 2, 'searchID': ht_id }) dom = ET.fromstring(resp.content) result = dict() XMLParser.xml_to_python(dom, result) container = result['HattrickData']['SearchResults'] if 'Result' in container: person['name'] = container['Result']['ResultName'] else: person['name'] = '----------' # output updated staff file staff.sort(key=lambda person: person['id']) ft['list'] = staff o = codecs.open(FT_JSON, mode='wb', encoding='utf-8') o.write(XMLParser.python_to_json(ft)) o.close()