def ParsePlatformSearchXml(self, text): xmlDocument = minidom.parseString(text) if self.TestXmlDocumentErrorStatus(xmlDocument) == False: raise Exception("Invalid response for search platform XML") gameTagResultList = xmlDocument.getElementsByTagName("platform") #print "PLATFORM SEARCH TEXT: " + text resultDictList = [] for gameTag in gameTagResultList: romDict = {} romDict[ 'giantBombPlatformId'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'id') romDict['name'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'name') romDict['abbreviation'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'abbreviation') romDict['description'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'deck') resultDictList.append(romDict) return resultDictList
def ParseGenreDetailsXml(self, text): xmlDocument = minidom.parseString(text) if self.TestXmlDocumentErrorStatus(xmlDocument) == False: raise Exception("Invalid response for get genre details XML") # print "XML: " + text gameTagResultList = xmlDocument.getElementsByTagName("results") if len(gameTagResultList) == 0: raise Exception("Could not find result for genre") if len(gameTagResultList) > 1: raise Exception("Unexpected number of results for genre") gameTag = gameTagResultList[0] romDict = {} romDict['name'] = XmlHelper.FindFirstDataInXmlTagList(gameTag, 'name') romDict['description'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'deck') romDict['giantBombId'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'id') imageNode = XmlHelper.FindFirstChildNodeByTagName(gameTag, 'image') if imageNode is not None: self.SaveImageToRomCache( Config.config.GetGenresImageCachePath(romDict['name']), romDict['name'], imageNode) return romDict
def ParseSimilarGamesData(self, xmlTag): ret = [] if xmlTag != None: gameTags = XmlHelper.FindChildNodesByTagName(xmlTag, 'game') for gameTag in gameTags: dict = {} dict['giantBombRomId'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'id') dict['name'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'name') ret.append(dict) return ret
def ParseRomDetailsXml(self, romName, text): xmlDocument = minidom.parseString(text) if self.TestXmlDocumentErrorStatus(xmlDocument) == False: raise Exception("Invalid response for get rom details XML") #print "XML: " + text gameTagResultList = xmlDocument.getElementsByTagName("results") if len(gameTagResultList) == 0: raise Exception("Could not find result for rom") if len(gameTagResultList) > 1: raise Exception("Unexpected number of results for rom") gameTag = gameTagResultList[0] romDict = {} #romDict[ 'name' ] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'name' ) romDict['description'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'deck') romDict['giantBombRomId'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'id') # string is provided in ISO standard format anyway so can be stored in DB like that romDict['releaseDate'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'original_release_date') # similar games are map of { 'giantBombRomId', 'name' } romDict['similarGames'] = self.ParseSimilarGamesData( XmlHelper.FindFirstChildNodeByTagName(gameTag, 'similar_games')) romDict['developers'] = self.ParseDeveloperData( XmlHelper.FindFirstChildNodeByTagName(gameTag, 'developers'), 'company') romDict['publishers'] = self.ParseDeveloperData( XmlHelper.FindFirstChildNodeByTagName(gameTag, 'publishers'), 'publisher') romDict['genres'] = self.ParseDeveloperData( XmlHelper.FindFirstChildNodeByTagName(gameTag, 'genres'), 'genre') imageNode = XmlHelper.FindFirstChildNodeByTagName(gameTag, 'image') if imageNode is not None: self.SaveImageToRomCache( Config.config.GetRomsImageCachePath(romName), romName, imageNode) return romDict
def ParseDeveloperData(self, developersNode, xmlNodeName): devList = [] if developersNode is not None: for developerNode in XmlHelper.FindChildNodesByTagName( developersNode, xmlNodeName): dev = {} dev['giantBombId'] = XmlHelper.FindFirstDataInXmlTagList( developerNode, 'id') dev['name'] = XmlHelper.FindFirstDataInXmlTagList( developerNode, 'name') dev['apiurl'] = XmlHelper.FindFirstDataInXmlTagList( developerNode, 'api_detail_url') devList.append(dev) return devList
def ParseSearchXml(self, text, giantBombPlatformId): xmlDocument = minidom.parseString(text) if self.TestXmlDocumentErrorStatus(xmlDocument) == False: raise Exception("Invalid response for search XML") gameTagResultList = xmlDocument.getElementsByTagName("game") # print "ROM SEARCH TEXT: " + text resultDictList = [] for gameTag in gameTagResultList: romDict = {} romDict['giantBombRomId'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'id') romDict['name'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'name') romDict['aliases'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'aliases') platformList = XmlHelper.FindFirstChildNodeByTagName( gameTag, 'platforms') if platformList != None: romDict['platforms'] = FormatPlatformsData(platformList) romDict[ 'giantBombApiDetailsUrl'] = XmlHelper.FindFirstDataInXmlTagList( gameTag, 'api_detail_url') # filter by giantBombPlatformId (can't do this directly in the url search string) foundPlatformId = False if len(giantBombPlatformId) > 0: for platform in romDict['platforms']: # print "Platform: " + platform[ 'name' ] if int(platform['giantBombPlatformId']) == int( giantBombPlatformId): foundPlatformId = True break else: foundPlatformId = True if foundPlatformId == True: resultDictList.append(romDict) return resultDictList
def FormatPlatformsData(dom): ret = [] if dom != None: platformList = dom.getElementsByTagName('platform') for platform in platformList: platformData = {} platformData['name'] = XmlHelper.FindFirstDataInXmlTagList( platform, 'name') platformData['abbreviation'] = XmlHelper.FindFirstDataInXmlTagList( platform, 'abbreviation') platformData[ 'giantBombPlatformId'] = XmlHelper.FindFirstDataInXmlTagList( platform, 'id') ret.append(platformData) return ret
def SaveImageToRomCache(self, cacheDirectory, romName, imageXmlNode): # pick an image priority for imageSizeName in Config.config.imagePriorityOrder: try: apiUrl = XmlHelper.FindFirstDataInXmlTagList( imageXmlNode, imageSizeName + '_url') if apiUrl is not None and len(apiUrl) > 0: imageUrl = apiUrl imageFilenameNoExtension = imageSizeName # print "[" + romName + "] TRYING " + imageUrl + " FILE: " + imageFilenameNoExtension if imageUrl is not None and imageFilenameNoExtension is not None and len( imageUrl) > 0 and len( imageFilenameNoExtension) > 0: if not os.path.exists(cacheDirectory): os.makedirs(cacheDirectory) # get image file extension from imageUrl (dummy, imageExtension) = os.path.splitext(imageUrl) imageFilename = imageFilenameNoExtension + imageExtension romImageFilename = os.path.join( cacheDirectory, imageFilename) if os.path.isfile(romImageFilename): return # file already exists if imageUrl != None and len(imageUrl) > 0: imageResp = urllib2.urlopen(imageUrl) imageData = imageResp.read() if len(imageData) > 0: imageFile = open(romImageFilename, 'wb') imageFile.write(imageData) imageFile.close() return except Exception as e: logging.exception(e)