コード例 #1
0
def main(json_file):
    sets_dict = read_id_to_terms(json_file)

    load_items_db_from_dump()
    for ankama_id, set_data in sets_dict.iteritems():
        set_name = set_data.get('name')
        print set_name
        if set_name:
            conn = sqlite3.connect(get_items_db_path())
            c = conn.cursor()
            c.execute('SELECT id FROM %s WHERE name = ?' % 'sets',
                      (set_name, ))
            query_result = c.fetchone()
            conn.close()
            if query_result is not None:
                store_set_data(query_result[0], ankama_id, set_data)
            else:
                filetomod = open('MissingSets.txt', 'a')

                name_to_print = set_name + '\n'
                filetomod.write(name_to_print.encode('utf-8'))

                filetomod.close()
    save_items_db_to_dump()
    invalidate_structure()
コード例 #2
0
def _delete_set(set_id):
    structure = get_structure()
    old_set = structure.get_set_by_id(set_id)
    if old_set is None:
        return False

    delete_set(set_id)
    invalidate_structure()
    return True
コード例 #3
0
def _delete_item(item_id):
    structure = get_structure()
    old_item = structure.get_item_by_id(item_id)
    if old_item is None:
        return False

    delete_item(item_id)
    invalidate_structure()
    return True
コード例 #4
0
def store_set_data(set_ID, ankama_id, set_data):
    if 'removed' in set_data:
        return
    else:
        new_set = _convert_json_item_to_item(set_data)
        old_set = get_structure().get_set_by_name(new_set.name, True)
        print 'Checking %s' % new_set.name

        if old_set:
            for lang in NON_EN_LANGUAGES:
                new_set.localized_names[lang] = old_set.localized_names.get(
                    lang)

        set_id = update_set(set_ID, new_set, False)

        invalidate_structure()
        for item in new_set.items:
            store_item_set(item, set_id)
コード例 #5
0
def _insert_set(json_set):
    s = _convert_json_set_to_set(json_set)

    insert_set(s)

    invalidate_structure()
コード例 #6
0
def _insert_item(json_item):
    item, weapon = _convert_json_item_to_item(json_item)

    insert_item(item, weapon)

    invalidate_structure()
コード例 #7
0
def update_set(set_id, new, invalidate=True):
    if set_id:
        print 'Updating set with id %d' % set_id
    else:
        print 'Adding set with name %s' % new.name

    if set_id == None:
        my_id = insert_set(new)
        return my_id

    structure = get_structure()
    old = structure.get_set_by_id(set_id)

    if new.name != old.name:
        exists = structure.get_set_by_name(new.name)
        if exists != None:
            print 'The set %s already exists in the database' % (new.name)
            return False

    if new.name != old.name:
        print 'Changing %s\'s name to %s' % (old.name, new.name)
        conn, c = _open_conn_get_cursor()
        c.execute('UPDATE sets SET name = ? WHERE ID = ?', (new.name, set_id))
        _finish_editing(conn)

    if new.dofus_touch != old.dofus_touch:
        print 'Changing %s\'s dofus_touch to %s' % (new.name, new.dofus_touch)
        conn, c = _open_conn_get_cursor()
        c.execute('UPDATE sets SET dofustouch = ? WHERE ID = ?',
                  (new.name, 1 if new.dofus_touch else None))
        _finish_editing(conn)

    if new.ankama_id != old.ankama_id:
        print 'Updating %s\'s Ankama ID' % (new.name)
        conn, c = _open_conn_get_cursor()
        c.execute('UPDATE sets SET ankama_id = ? WHERE ID = ?',
                  (new.ankama_id, set_id))
        _finish_editing(conn)

    for lang in NON_EN_LANGUAGES:
        if new.localized_names.get(lang) != old.localized_names.get(lang):
            print('Localized name for %s in %s changed from %s to %s' %
                  (old.name, lang, old.localized_names.get(lang),
                   new.localized_names.get(lang)))
            modify_localized_name('set_names', 'item_set', old.id, lang,
                                  new.localized_names.get(lang))

    conn, c = _open_conn_get_cursor()
    for num_items, stat_id, new_value in new.bonus:
        stat_name = structure.get_stat_by_id(stat_id).name
        old_value = _check_and_get_old_stat_in_set(old, stat_id, num_items)
        if old_value:
            if new_value != old_value:
                print 'Changing %s\'s  %s from %d to %s with %d items' % (
                    old.name, stat_name, old_value, new_value, num_items)
                c.execute(
                    'UPDATE set_bonus SET value = ? WHERE item_set = ? AND stat = ? '
                    'AND num_pieces_used = ?',
                    (new_value, set_id, stat_id, num_items))
        else:
            print 'Adding %s %s to %s at %d items' % (new_value, stat_name,
                                                      old.name, num_items)
            c.execute(
                'INSERT INTO set_bonus (item_set, num_pieces_used, stat, value)'
                'VALUES (?, ?, ?, ?)', (set_id, num_items, stat_id, new_value))
    _finish_editing(conn)

    conn, c = _open_conn_get_cursor()
    for num_items, stat_id, _ in old.bonus:
        stat_name = structure.get_stat_by_id(stat_id).name
        if not _check_if_new_set_has_stat(new, stat_id, num_items):
            print 'Removing %s from %s at %d items' % (stat_name, old.name,
                                                       num_items)
            c.execute(
                'DELETE from set_bonus WHERE item_set = ? AND stat = ? '
                'AND num_pieces_used = ?', (set_id, stat_id, num_items))
    _finish_editing(conn)

    if invalidate:
        invalidate_structure()

    return new.id
コード例 #8
0
def update_item(old, new, new_weapon, invalidate):
    structure = get_structure()

    if new.ankama_id:
        if int(new.ankama_id) != old.ankama_id:
            print 'Changing %s\'s Ankama ID from %s to %s' % (
                old.name, old.ankama_id, new.ankama_id)
            modify_item_ankama_id(old.id, new.ankama_id)

    if new.ankama_type != old.ankama_type:
        print 'Changing %s\'s Ankama type from %s to %s' % (
            old.name, old.ankama_type, new.ankama_type)
        modify_item_ankama_type(old.id, new.dofus_touch)

    if new.dofus_touch != old.dofus_touch:
        if new.dofus_touch:
            print ' %s is now a Dofus Touch item' % (old.name)
        else:
            print ' %s is no longer a Dofus Touch item' % (old.name)
        modify_item_dofus_touch(old.id, new.dofus_touch)

    if new.name != old.name:
        #         filetomod = open('NameChanges.txt','a')
        #
        #         filetomod.write('%s: %s\n' % (old.name.encode('utf-8'), new.name.encode('utf-8')))
        #
        #         print '%s TURNED INTO %s' % (old.name.encode('utf-8'), new.name.encode('utf-8'))
        #
        #         filetomod.close()
        exists = structure.get_item_by_name(new.name, new.dofus_touch)
        still_exists = False
        if exists:
            still_exists = exists.dofus_touch == new.dofus_touch
        if still_exists:
            print 'The item %s already exists in the database' % (new.name)
            return False

    if int(new.level) != old.level:
        print 'Changing %s\'s level from %d to %s' % (old.name, old.level,
                                                      new.level)
        modify_item_level(old.id, new.level)

    if new.removed != old.removed:
        if new.removed == True:
            print 'Setting %s as removed' % (new.name)
            fake_delete_item(old.id, True)
        else:
            print 'Setting %s as not removed' % (new.name)
            fake_delete_item(old.id, False)

    if new.type != old.type:
        print 'Changing %s\'s type from %s to %s' % (
            old.name, structure.get_type_name_by_id(
                old.type), structure.get_type_name_by_id(new.type))
        modify_item_type(old.id, new.type)
        if structure.get_type_name_by_id(old.type) == 'Weapon':
            print 'Removing weapon data from %s' % (old.name)
            delete_weapon(old.id)

    if new.set != old.set:
        old_set_name = structure.get_set_by_id(
            old.set).name if old.set else 'None'
        new_set_name = structure.get_set_by_id(
            new.set).name if new.set else 'None'
        print 'Changing %s\'s set from %s to %s' % (old.name, old_set_name,
                                                    new_set_name)
        modify_item_set(old.id, new.set)
    if new.set == '' and old.set != None:
        print 'Removing set from %s' % (old.name)
        modify_item_set(old.id, None)

    for wc in WEIRD_CONDITIONS:
        if new.weird_conditions[wc] != old.weird_conditions[wc]:
            modify_weird_condition(old.id, wc, new.weird_conditions[wc])

    for stat, stat_value in new.stats:
        old_value = _check_and_get_old_stat(old, stat)
        if old_value:
            if stat_value != old_value:
                print 'Changing %s\'s  %s from %d to %s' % (
                    old.name, structure.get_stat_by_id(stat).name, old_value,
                    stat_value)
                modify_item_stat(old.id, stat, stat_value)
        else:
            print 'Adding %s %s to %s' % (
                stat_value, structure.get_stat_by_id(stat).name, old.name)
            add_item_stat(old.id, stat, stat_value)
    for old_stat, _ in old.stats:
        if not _check_if_new_has_stat(new, old_stat):
            if structure.get_stat_by_id(old_stat):
                print 'Removing %s from %s' % (
                    structure.get_stat_by_id(old_stat).name, old.name)
            else:
                print 'Removing a stat from %s' % old.name
            remove_item_stat(old.id, old_stat)

    for stat, value in new.min_stats_to_equip:
        old_value = _check_and_get_old_condition(old, stat, True)
        new_value = value
        if old_value:
            if new_value != old_value:
                print 'Modifying %s\'s condition' % (old.name)
                modify_item_cond(old.id, stat, True, new_value)
        else:
            print 'Adding condition to %s' % (old.name)
            add_item_cond(old.id, stat, True, new_value)
    for old_stat, _ in old.min_stats_to_equip:
        if not _check_if_new_has_condition(new, old_stat, True):
            print 'Removing condition from %s' % (old.name)
            remove_item_cond(old.id, old_stat, True)
    for stat, value in new.max_stats_to_equip:
        old_value = _check_and_get_old_condition(old, stat, False)
        new_value = value
        if old_value:
            if new_value != old_value:
                print 'Modifying %s\'s condition' % (old.name)
                modify_item_cond(old.id, stat, False, new_value)
        else:
            print 'Adding condition to %s' % (old.name)
            add_item_cond(old.id, stat, False, new_value)
    for old_stat, _ in old.max_stats_to_equip:
        if not _check_if_new_has_condition(new, old_stat, False):
            print 'Removing condition from %s' % (old.name)
            remove_item_cond(old.id, old_stat, False)

    for lang in NON_EN_LANGUAGES:
        if new.localized_names.get(lang) != old.localized_names.get(lang):
            print('Localized name for %s in %s changed from %s to %s' %
                  (old.name, lang, old.localized_names.get(lang),
                   new.localized_names.get(lang)))
            modify_localized_name('item_names', 'item', old.id, lang,
                                  new.localized_names.get(lang))

    if new.localized_extras != old.localized_extras:
        print 'Modifying %s\'s localized extras' % (old.name)
        modify_extras(old, new)

    if structure.get_type_name_by_id(new.type) == 'Weapon':
        if not structure.get_type_name_by_id(old.type) == 'Weapon':
            conn, cursor = _open_conn_get_cursor()
            _insert_weapon(new, new_weapon, old.id, cursor)
            _finish_editing(conn)
        else:
            old_weapon = structure.get_weapon_by_name(old.name,
                                                      new.dofus_touch)

            if old_weapon == None:
                return
            if new_weapon.ap != old_weapon.ap:
                print 'Changing %s\'s AP cost from %d to %d' % (
                    old.name, old_weapon.ap, new_weapon.ap)
                modify_item_ap(old.id, new_weapon.ap)

            if new_weapon.crit_chance != old_weapon.crit_chance:
                print 'Changing %s\'s critical hit rate from %d to %d' % (
                    old.name,
                    old_weapon.crit_chance if old_weapon.crit_chance else 0,
                    new_weapon.crit_chance if new_weapon.crit_chance else 0)
                modify_weapon_ch_rate(old.id, new_weapon.crit_chance)

            if new_weapon.crit_bonus != old_weapon.crit_bonus:
                print 'Changing %s\'s critical hit bonus from %d to %d' % (
                    old.name,
                    old_weapon.crit_bonus if old_weapon.crit_bonus else 0,
                    new_weapon.crit_bonus if new_weapon.crit_bonus else 0)
                modify_weapon_ch_bonus(old.id, new_weapon.crit_bonus)


#             if new.is_one_handed != old.is_one_handed:
#                 print 'Changing whether %s is one handed: from %r to %r' % (old.name,
#                                                                            old.is_one_handed,
#                                                                            new.is_one_handed)
#                 modify_one_handness(old.id, new.is_one_handed)

            if new_weapon.weapon_type != old_weapon.weapon_type:
                print 'Changing %s\'s type from %s to %s' % (
                    old.name,
                    structure.get_weapon_type_by_id(
                        old_weapon.weapon_type).name,
                    structure.get_weapon_type_by_id(
                        new_weapon.weapon_type).name)
                modify_weapon_type(old.id, new_weapon.weapon_type)

            last_index = 0
            for index, hit in new_weapon.hits_dict.iteritems():
                if index > last_index:
                    last_index = index
                if index in old_weapon.hits_dict:
                    if old_weapon.hits_dict[
                            index].min_dam != new_weapon.hits_dict[
                                index].min_dam:
                        print 'Changing %s\'s hit number %d: minimum damage going from %d to %d' % (
                            old.name, index,
                            old_weapon.hits_dict[index].min_dam,
                            new_weapon.hits_dict[index].min_dam)
                        modify_min_hit(old.id, index,
                                       new_weapon.hits_dict[index].min_dam)
                    if old_weapon.hits_dict[
                            index].max_dam != new_weapon.hits_dict[
                                index].max_dam:
                        print 'Changing %s\'s hit number %d: maximum damage going from %d to %d' % (
                            old.name, index,
                            old_weapon.hits_dict[index].max_dam,
                            new_weapon.hits_dict[index].max_dam)
                        modify_max_hit(old.id, index,
                                       new_weapon.hits_dict[index].max_dam)
                    if old_weapon.hits_dict[
                            index].element != new_weapon.hits_dict[
                                index].element:
                        print 'Changing %s\'s hit number %d: element changing from %s to %s' % (
                            old.name, index,
                            old_weapon.hits_dict[index].element,
                            new_weapon.hits_dict[index].element)
                        modify_hit_element(old.id, index,
                                           new_weapon.hits_dict[index].element)
                    if old_weapon.hits_dict[
                            index].heals != new_weapon.hits_dict[index].heals:
                        print 'Changing %s\'s hit number %d: heals going from %r to %r' % (
                            old.name, index, old_weapon.hits_dict[index].heals,
                            new_weapon.hits_dict[index].heals)
                        modify_hit_heals(old.id, index,
                                         new_weapon.hits_dict[index].heals)
                    if old_weapon.hits_dict[
                            index].steals != new_weapon.hits_dict[index].steals:
                        print 'Changing %s\'s hit number %d: steals going from %r to %r' % (
                            old.name, index,
                            old_weapon.hits_dict[index].steals,
                            new_weapon.hits_dict[index].steals)
                        modify_hit_steals(old.id, index,
                                          new_weapon.hits_dict[index].steals)
                else:
                    print 'Adding hit number %d to %s:\nminimum damage: %d\nmaximum damage: %d\nelement: %s\nheals: %r\nsteals: %r' % (
                        index, old.name, new_weapon.hits_dict[index].min_dam,
                        new_weapon.hits_dict[index].max_dam,
                        new_weapon.hits_dict[index].element,
                        new_weapon.hits_dict[index].heals,
                        new_weapon.hits_dict[index].steals)
                    add_hit(old.id, index, new_weapon.hits_dict[index].min_dam,
                            new_weapon.hits_dict[index].max_dam,
                            new_weapon.hits_dict[index].element,
                            new_weapon.hits_dict[index].heals,
                            new_weapon.hits_dict[index].steals)
            for index, hit in old_weapon.hits_dict.iteritems():
                if index > last_index:
                    print 'Removing hit number %d from %s' % (index, old.name)
                    remove_hit(old.id, index)

    if new.name != old.name:
        print 'Changing %s\'s  name to %s' % (old.name, new.name)
        modify_item_name(old.id, new.name)

    if invalidate:
        invalidate_structure()
    return True