def __init__(self, loop): self.db = sqlite_db self.db.create_tables([Weapon, Monster, MapleWeapon]) self.max_bulk_rows = 20 self.db_refreshing = False self.refresh_data(loop) maple_weapons = [] with open(os.path.join(os.path.dirname(__file__), 'mapleweapons.csv')) as csvfile: list_reader = csv.DictReader(csvfile) for weapon in list_reader: maple_weapons.append(weapon) with self.db.atomic(): for i in range(0, len(maple_weapons), self.max_bulk_rows): top = i + self.max_bulk_rows MapleWeapon.insert_many(maple_weapons[i:top]).execute() if len(maple_weapons) == 0: log.warn('empty result set for maple weapons')
def maple_weapon_by_name(self, *weapon_name_terms): if self.db_refreshing: raise ValueError('Database refresh in progress') clauses = [(MapleWeapon.name ** '%{}%'.format(term)) for term in weapon_name_terms] return MapleWeapon.select().where(functools.reduce(operator.or_, clauses)).execute()