def get_corp_kills(api_id, api_key): try: cache = ShelveCache('kills.dat') api = evelink.api.API(api_key=(api_id, api_key), cache=cache) corp = evelink.corp.Corp(api=api) kill_log = corp.kills() return kill_log except evelink.api.APIError as error: return {}
class ShelveCacheTestCase(unittest.TestCase): def setUp(self): self.cache_dir = tempfile.mkdtemp() self.cache_path = os.path.join(self.cache_dir, 'shelf') self.cache = ShelveCache(self.cache_path) def tearDown(self): self.cache.cache.close() try: os.remove(self.cache_path) except OSError: pass try: os.rmdir(self.cache_dir) except OSError: pass def test_cache(self): self.cache.put('foo', 'bar', 3600) self.assertEqual(self.cache.get('foo'), 'bar') def test_expire(self): self.cache.put('baz', 'qux', -1) self.assertEqual(self.cache.get('baz'), None)
class ShelveCacheTestCase(unittest.TestCase): def setUp(self): self.cache_dir = tempfile.mkdtemp() self.cache_path = os.path.join(self.cache_dir, "shelf") self.cache = ShelveCache(self.cache_path) def tearDown(self): self.cache.cache.close() os.remove(self.cache_path) os.rmdir(self.cache_dir) def test_cache(self): self.cache.put("foo", "bar", 3600) self.assertEqual(self.cache.get("foo"), "bar") def test_expire(self): self.cache.put("baz", "qux", -1) self.assertEqual(self.cache.get("baz"), None)
cache_path = config.get('posmon', 'cache') try: sentry_uri = config.get('posmon', 'sentry.uri') except ConfigParser.NoOptionError: sentry_uri = None # Set up logging logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) if sentry_uri: from raven.handlers.logging import SentryHandler sentry_handler = SentryHandler(sentry_uri) sentry_handler.setLevel(logging.WARNING) logging.getLogger().addHandler(sentry_handler) # Run! cache=ShelveCache(cache_path) fmt = sys.argv[1] if len(sys.argv) > 1 else 'text' try: for key_id, vcode in keys: api_key = API(api_key=(key_id, vcode), cache=cache) try: process(api_key, format=fmt) except Exception as e: if fmt == 'text': print "error processing key: %s" % (str(e),) else: print json.dumps({'error': str(e)}) logging.exception(str(e)) finally: cache.cache.close()
def setUp(self): self.cache_dir = tempfile.mkdtemp() self.cache_path = os.path.join(self.cache_dir, "shelf") self.cache = ShelveCache(self.cache_path)
return my_character, assets_timestamp, towerset def keys_from_args(args): return [(int(args[i]), args[i + 1]) for i in range(1, len(args) - 1, 2)] def keys_from_config(filename): config = ConfigParser.RawConfigParser() config.read(filename) return [(config.getint(section, 'keyID'), config.get(section, 'vCode')) for section in config.sections() if section.startswith('key:')] if __name__ == "__main__": logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) if len(sys.argv) > 1: keys = keys_from_args(sys.argv) else: keys = keys_from_config('posmon.ini') for key_id, vcode in keys: api_key = API(api_key=(key_id, vcode), cache=ShelveCache('/tmp/eveapi')) if len(sys.argv) > 1: process(api_key, format=sys.argv[1]) else: process(api_key)