-
Notifications
You must be signed in to change notification settings - Fork 16
/
store_trap_door.py
executable file
·173 lines (147 loc) · 6.54 KB
/
store_trap_door.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
# coding=utf-8
# Copyright (C) 2020 The Dofus Fashionista
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import json
import sqlite3
from fashionistapulp.fashionista_config import (get_items_db_path, load_items_db_from_dump,
save_items_db_to_dump)
from store_rosetta import get_item_id_and_name_for_ankama_profile
from fashionistapulp.structure import get_structure
from fashionistapulp.item import Item
from fashionistapulp.weapon import Weapon
from fashionistapulp.dofus_constants import (ELEMENT_NAME_TO_KEY, DamageDigest,
WEIRD_CONDITIONS)
from fashionistapulp.modify_items_db import update_item, fake_delete_item,\
insert_item
from fashionistapulp.translation import NON_EN_LANGUAGES
def main(json_file):
weapons = read_id_to_terms(json_file)
load_items_db_from_dump()
for ankama_id, weapon_data in weapons.iteritems():
ankama_profile = (ankama_id, 'equipment')
conn = sqlite3.connect(get_items_db_path())
c = conn.cursor()
item_id, weapon_name = get_item_id_and_name_for_ankama_profile(c, 'items', ankama_profile)
conn.close()
#print item_id
if item_id is None:
store_weapon_data(item_id, weapon_name, weapon_data)
save_items_db_to_dump()
def store_weapon_data(item_id, weapon_name, weapon_data):
s = get_structure()
if 'removed' in weapon_data:
fake_delete_item(item_id, True)
else:
new_item, new_weapon = _convert_json_item_to_item(weapon_data)
insert_item(new_item, new_weapon)
def store_weapon_data_field(c, item_id, weapon_name, weapon_data, table, weapon_data_field):
new_value = weapon_data.get(weapon_data_field)
if new_value is None:
print 'Warning: weapon [%d] %s does not have %s' % (item_id, weapon_name, weapon_data_field)
return
c.execute('SELECT value FROM %s WHERE item = ?' % table,
(item_id,))
query_result = c.fetchone()
if query_result is None:
c.execute('INSERT INTO %s VALUES (?, ?)' % table,
(item_id, new_value))
print ('Added weapon [%d] %s %s as %s'
% (item_id, weapon_name, weapon_data_field, new_value))
else:
if query_result[0] != new_value:
c.execute('UPDATE %s SET value = ? WHERE item = ?' % table,
(new_value, item_id))
print ('Changed weapon [%d] %s %s from %s to %s'
% (item_id, weapon_name, weapon_data_field, query_result[0], new_value))
def _convert_json_item_to_item(json_item):
structure = get_structure()
item = Item()
item.removed = False
item.name = json_item['name']
item.ankama_id = json_item['ankama_id']
item.ankama_type = 'equipment'
item.level = json_item['level']
item.dofus_touch = False
if json_item['w_type'] == 'Trophy':
json_item['w_type'] = 'Dofus'
if json_item['w_type'] == 'Backpack':
json_item['w_type'] = 'Cloak'
if json_item['w_type'] == 'Petsmount':
json_item['w_type'] = 'Pet'
item_type = structure.get_type_id_by_name(json_item['w_type'])
if item_type:
item.type = item_type
else:
item.type = structure.get_type_id_by_name('Weapon')
if json_item['w_type'] == 'Ceremonial item':
json_item['w_type'] = None
item.removed = True
item.type = None
weapon = Weapon()
print json_item['w_type']
if item.type == structure.get_type_id_by_name('Weapon'):
#print json_item['w_type']
#print structure.get_type_name_by_id(item.type)
#print item.name
print item.name
weapon.ap = int(json_item['ap'])
weapon.crit_chance = int(json_item['crit_chance'])
weapon.crit_bonus = int(json_item.get('crit_bonus')) if json_item.get('crit_bonus') else None
#print weapon.crit_bonus
weapon.weapon_type = structure.get_weapon_type_by_name(json_item['w_type']).id
index = 0
for stat in json_item['stats']:
if stat[2].startswith('('):
hit_name = stat[2].strip('()')
hit_element = hit_name.split()[0]
hit_type = hit_name.split()[1]
if hit_name != 'Hunting weapon':
element = (ELEMENT_NAME_TO_KEY[hit_element] if hit_element != 'HP'
else ELEMENT_NAME_TO_KEY['Fire'])
weapon.hits_dict[index] = DamageDigest((stat[0]),
(stat[1] if stat[1] else stat[0]),
element,
True if hit_type == 'steal' else False,
False if hit_element != 'HP' else True)
index = index + 1
elif (stat[0] or stat[1]):
if structure.get_stat_by_name(stat[2]):
if stat[1] == None:
stat_value = stat[0]
else:
if stat[0] >= 0:
stat_value = stat[1]
else:
stat_value = stat[0]
_add_to_old_stat(item, structure.get_stat_by_name(stat[2]).id, stat_value)
else:
filetomod = open('HPitems.txt','a')
filetomod.write(item.name + ': ' + stat[2] + '\n')
print 'COULD NOT FIND STAT %s' % stat[2]
filetomod.close()
return item, weapon
def _add_to_old_stat(old_item, stat_id, value):
old_item.stats.append((stat_id, value))
def read_id_to_terms(filename):
weapons = {}
with open(filename) as f:
weapon_list = json.load(f)
for entry in weapon_list:
weapons[entry['ankama_id']] = entry
return weapons
if __name__ == '__main__':
main('itemscraper/dofus248lalala.json')