def __init__(self, manager): Item.__init__(self, manager) self.name = 'Ammo' self.stat = 'ammo' self.adj = 'reloads' self.value = 1 self.amt = 10
def __init__(self, manager): Item.__init__(self, manager) self.name = 'Bomb' self.adj = 'blasts' self.empty = 'The %s has already been detonated!' self.value = -100 self.amt = 1
def __init__(self, manager): Item.__init__(self, manager) self.name = 'Food' self.fmtline = '@TARGET eats the @NAME ' self.stat = 'health' self.empty = "The %s has already been eaten!" self.value = 1 self.amt = 1
def __init__(self, manager): Item.__init__(self, manager) self.name = 'Gun' self.stat = 'health' self.value = -10 self.amt = 1 self.range = 100 self.fmtline = "@TARGET @ADJ @VALUE points" self.adj = ('gets blasted for', 'sucks it down for', 'eats hot lead and looses', 'gets shot up for', 'gets nailed for', 'isn\'t fast enough and gets hit for' , 'feels the kiss of hot lead and looses')
def key_check_new(): logging.info('----------开始更新----------') base_dir = Config.get_config_field()['updating_dir'] updating_list = os.listdir(base_dir) # start_index = updating_list.index('NTRD') + 1 for key in updating_list: try: start = Utility.find_num(DBItemService.db_find_max_code(key)) + 1 global retry retry = 0 for cur_num in range(start, 1000): item = Item(key, cur_num) if retry > int(Config.get_config_field()["retry_times"]): logging.info("番号处理完毕" + key) break search_by_code(item, True, 'updating') if cur_num % 20 == 0: DBItemService.db_commit(item.get_key) except Exception as e: logging.error(e) finally: DBItemService.db_commit(key) db_key = DBKeyService.copy_to_db(key) DBKeyService.db_update(db_key) DBKeyService.db_commit(db_key.key_) Utility.delete_extra_file(key, 'updating') logging.info('----------更新结束----------')
def download_failed(): logging.info('----------重新处理失败的Code----------') todo_list = list() failed_list = list() with open('failed_list.txt', 'r') as f: for line in f: todo_list.append(line.strip('\n')) failed_list.append(line.strip('\n')) i = 0 for code in todo_list: try: item = Item(Utility.find_key(code), Utility.find_num(code)) keyset = KeySet(item.get_key) keyset.set_download_path(Config.get_config_field()["download_dir"]) search_by_code(item, True, 'download') if os.path.exists(keyset.get_key_path + item.get_title + ".jpg"): failed_list.pop(i) else: i += 1 except Exception as e: logging.error(e) finally: DBItemService.db_commit(item.get_key) with open('failed_list.txt', 'w') as file: for line in failed_list: file.writelines('{0}\n'.format(line)) logging.info('处理失败的Code结束。')
def use(self, target): log = logging.getLogger(__name__ + ".use") if target.__class__ == Ammo: #print "reload!" #print target.__class__ #val = getattr(target, self.stat, 0) + self.value s = self.fmtline s = s.replace('@NAME', self.name) s = s.replace('@TARGET', target.name) s = s.replace('@ADJ', 'reloads with') s = s.replace('@STAT', self.stat) s = s.replace('@VALUE', str(abs(target.amt))) log.debug(s) #setattr(target, target.amt, val) #target.amt = val #print '\tAmmo has ', target.amt, ' amt' #print '\tgun has ', self.amt, ' amt' self.amt += target.amt target.amt = 0 else: Item.use(self, target)
def search_codes(): logging.info('----------开始按Code搜索----------') for i, code in enumerate(Config.get_code_list()): if code != "": download_path = Config.get_config_field( )["download_dir"] + Utility.find_key(code) + '/' if not os.path.exists(download_path): os.makedirs(download_path) global retry retry = 0 item = Item(Utility.find_key(code), Utility.find_num(code)) if retry > int(Config.get_config_field()["retry_times"]): break search_by_code(item, True, "download") if i % 20 == 19: DBItemService.db_commit(item.get_key) logging.info('按Code搜索结束。')
def search_keys(): logging.info('----------开始按Key搜索----------') for keyset in Config.get_key_list(): if not os.path.exists(keyset.get_key_path): os.makedirs(keyset.get_key_path) global retry retry = 0 for cur_num in range(keyset.get_start, keyset.get_end): item = Item(keyset.get_key, cur_num) if retry > int(Config.get_config_field()["retry_times"]): logging.info("番号处理完毕" + keyset.get_key) break search_by_code(item, True, 'download') if cur_num % 20 == 0: DBItemService.db_commit(item.get_key) DBItemService.db_commit(keyset.get_key) Utility.delete_extra_file(keyset.get_key, 'download') logging.info('----------按Key搜索结束----------')
def db_add(): logging.info('开始向数据库中导入。') base_dir = Config.get_config_field()['arrange_dir'] for key in os.listdir(base_dir): key_dir = base_dir + key global retry retry = 0 if os.path.exists(key_dir): for i, file in enumerate( filter(lambda x: x.endswith(".jpg"), os.listdir(key_dir))): item = Item(Utility.find_key(file), Utility.find_num(file)) if retry > int(Config.get_config_field()["retry_times"]): logging.info("番号处理完毕" + key) break search_by_code(item, False, 'download') if i % 5 == 4: DBItemService.db_commit(item.get_key) DBItemService.db_commit(key) logging.info('----------向数据库中导入结束----------')
def __init__(self, manager): Item.__init__(self, manager) self.name = 'Belladonna' self.adj = 'poisons' self.value = -1 self.amt = 1
def __init__(self, manager): Item.__init__(self, manager) self.name = 'Health Potion' self.adj = 'heals' self.value = 10 self.amt = 1
def get_bill(p): return Item.get_all(p)
def set_bill(name, patient, cost): item = Item(name=name, p=patient, cost=cost) item.add_item() return