Skip to content

Commit

Permalink
Small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
LaundroMat committed Aug 29, 2015
1 parent 1993553 commit 4787a43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

/.idea/
# C extensions
*.so

Expand Down
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'Mathieu'
11 changes: 6 additions & 5 deletions parsers/offlinelist_no_intro_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ def _find_languages(self, found, codes, sum_of_game_languages):
def __init__(self, filename):
self.tree = etree.parse(filename)
self.games = []
self.system = ''

def parse(self):
system = self.tree.find('//system').text
self.system = self.tree.find('//system').text
for game_element in self.tree.find('//games').iterchildren():
game = dict()
game['title'] = self.get_game_title(game_element)
game['publisher'] = self.get_game_publisher(game_element)
game['date'] = self.get_game_date(game_element)
game['languages'] = self.get_game_language(game_element)
game['languages'] = self.get_game_languages(game_element)
game['locations'] = self.get_game_locations(game_element)
self.games.append(game)

Expand All @@ -108,7 +109,7 @@ def get_game_date(self, game_element):
return date
return None

def get_game_language(self, game_element):
def get_game_languages(self, game_element):
offlinelist_language_codes = [n for n in self.languages.keys()]
offlinelist_language_codes.sort() # from lowest to highest

Expand All @@ -118,11 +119,11 @@ def get_game_language(self, game_element):
if game_language_codes > 0:
return self._find_languages(tuple(), offlinelist_language_codes, game_language_codes)

return None
return tuple()

def get_game_locations(self, game_element):
location_code = game_element.find('location').text
if location_code == '-1':
return None
return tuple()
else:
return self.locations[location_code]
31 changes: 16 additions & 15 deletions tosecimport.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from parsers.offlinelist_no_intro_xml_parser import NoIntroOfflineListParser
from parsers.tosec_parser import TosecParser, TosecNamingConvention
from .parsers.offlinelist_no_intro_xml_parser import NoIntroOfflineListParser
from .parsers.tosec_parser import TosecParser, TosecNamingConvention

def convert_dat_to_dicts(filename):
print("Importing {}".format(filename))
Expand All @@ -18,19 +18,20 @@ def convert_dat_to_dicts(filename):
print(tnc.__dict__)


def import_xml_dat_file(filename):
def import_no_intro_xml_dat_file(filename):
p = NoIntroOfflineListParser(filename)
p.parse()
print('{} games parsed.'.format(len(p.games)))

import argparse

parser = argparse.ArgumentParser(description="Load .dat files and convert to list of dicts")

# only arg is filename
parser.add_argument("filename", help="Database name")
parser.add_argument("-p", help="parser")

args = parser.parse_args()

import_xml_dat_file(args.filename)
return p

# import argparse
#
# parser = argparse.ArgumentParser(description="Load .dat files and convert to list of dicts")
#
# # only arg is filename
# parser.add_argument("filename", help="Database name")
# parser.add_argument("-p", help="parser")
#
# args = parser.parse_args()
#
# import_no_intro_xml_dat_file(args.filename)

0 comments on commit 4787a43

Please sign in to comment.