From 4787a4351afa82dfb23ed831eb50d5599f285409 Mon Sep 17 00:00:00 2001 From: laundromat Date: Sat, 29 Aug 2015 13:13:32 +0200 Subject: [PATCH] Small updates --- .gitignore | 2 +- __init__.py | 1 + parsers/offlinelist_no_intro_xml_parser.py | 11 ++++---- tosecimport.py | 31 +++++++++++----------- 4 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 __init__.py diff --git a/.gitignore b/.gitignore index ba74660..b7add8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] - +/.idea/ # C extensions *.so diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..35ea860 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +__author__ = 'Mathieu' diff --git a/parsers/offlinelist_no_intro_xml_parser.py b/parsers/offlinelist_no_intro_xml_parser.py index 07a269a..688cbfc 100644 --- a/parsers/offlinelist_no_intro_xml_parser.py +++ b/parsers/offlinelist_no_intro_xml_parser.py @@ -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) @@ -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 @@ -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] diff --git a/tosecimport.py b/tosecimport.py index f79a6ad..61cf678 100644 --- a/tosecimport.py +++ b/tosecimport.py @@ -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)) @@ -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)