def image_for_rom(self, rom): if not os.path.exists('hash.csv'): f = urllib2.urlopen( 'https://raw.githubusercontent.com/sselph/scraper/master/hash.csv' ) with open('hash.csv', 'w') as hashfile: hashfile.write(f.read()) gameid = None title = None for method in ( 'md5', ): # map(lambda m: getattr(hashlib,m), hashlib.algorithms): hash = self.rom_hash(rom.path) gameid, title = self.find_hash_id_and_title(hash) if gameid is not None: break if gameid is None: logger.debug('Did not find hash for %s', rom.path) return None query = urllib.urlencode({'id': gameid}) xml_url = urlparse.urlunparse( ('http', 'thegamesdb.net', '/api/GetArt.php', '', query, '')) try: image_url = self.get_image_url(xml_url) except Exception: logger.exception('Error parsing thegamesdb xml %s', xml_url) return None logger.debug('Hash-based image found: %s %s', rom.path, image_url) if image_url is None or image_url == "": return None return self.download_image(image_url)
def handle_exception(e, fatal): # Just log it if fatal: logger.exception("An exception occurred while running Ice") else: logger.error(e.message)
def run(self, dry_run=False): try: self.main(dry_run=dry_run) except Exception as error: logger.exception("An exception occurred while running Ice")