-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
187 lines (167 loc) · 7.71 KB
/
update.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
from postgres import get_postgres
from models import Character, Style
from scrape import get_info_from_aewiki, get_info_from_altema, get_dungeon_from_aewiki
import constants
from image import upload_image
import sys
import urllib.parse
def update_character(character: Character):
code, category, light_shadow, is_awaken, aewiki_url, update_date, personalities, japanese_name, korean_name, english_class_name = get_info_from_aewiki(character)
japanese_class_name = get_info_from_altema(character)
english_dungeon_name = get_dungeon_from_aewiki(character.style, english_class_name)
endpoint_keyword = f'{japanese_name}{constants.SEESAA_SUFFIXS[character.style]}'
if character.is_original_4star:
endpoint_keyword += "☆4"
character.style = "☆4"
seesaa_url = f'{constants.SEESAA_BASE_URL}{urllib.parse.quote(endpoint_keyword.encode("euc-jp"))}'
with get_postgres() as conn:
cur = conn.cursor()
cur.execute("SELECT COUNT(*) FROM aecheck.characters WHERE character_id LIKE 'char0%'")
count = cur.fetchone()[0]
cur.execute(f"SELECT key FROM aecheck.translations WHERE en = '{english_dungeon_name}' AND key LIKE 'dungeon%'")
dungeon_id = cur.fetchone()
dungeon_id = dungeon_id[0] if dungeon_id else None
if character.alter_character_korean_name:
cur.execute(f"""
SELECT c.character_code FROM aecheck.characters c
LEFT JOIN aecheck.translations t
ON c.character_code = t.key
WHERE t.ko = '{character.alter_character_korean_name}'
""")
alter_code = cur.fetchone()[0]
else:
alter_code = None
cur.execute("SELECT character_id FROM aecheck.characters WHERE character_code = %s AND style = %s", (f'c{code}', character.style))
character_id = cur.fetchone()
if character_id is None:
character_id = f'char{str(count+1).zfill(4)}'
cur.execute(
"INSERT INTO aecheck.characters (character_id, character_code, category, style, light_shadow, max_manifest, is_awaken, is_alter, alter_character, seesaa_url, aewiki_url, update_date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
(character_id, f'c{code}', category, character.style, light_shadow, character.max_manifest, is_awaken, character.is_alter, alter_code, seesaa_url, aewiki_url, update_date)
)
if character.is_alter:
cur.execute("UPDATE aecheck.characters SET alter_character = %s WHERE character_id = %s AND style IN ('4☆', 'NS')", (f'c{code}', alter_code))
if dungeon_id:
cur.execute(
"INSERT INTO aecheck.dungeon_mappings (character_id, dungeon_id) VALUES (%s, %s)",
(character_id, dungeon_id)
)
for personality in personalities:
cur.execute(f"SELECT key FROM aecheck.translations WHERE en = '{personality}'")
data = cur.fetchone()
if data is None:
print(f"Personality {personality} not found")
sys.exit(1)
personality_id = data[0]
cur.execute(
"INSERT INTO aecheck.personality_mappings (character_id, personality_id) VALUES (%s, %s)",
(character_id, personality_id)
)
cur.execute("SELECT key FROM aecheck.translations WHERE key = %s", (f'c{code}',))
if cur.fetchone() is None:
cur.execute(
"INSERT INTO aecheck.translations (key, ko, en, ja) VALUES (%s, %s, %s, %s)",
(f'c{code}', korean_name, character.english_name, japanese_name)
)
if not character.is_original_4star:
cur.execute(
"INSERT INTO aecheck.translations (key, ko, en, ja) VALUES (%s, %s, %s, %s)",
(f'book.{character_id}', character.korean_class_name, english_class_name, japanese_class_name)
)
else:
character_id = character_id[0]
cur.execute("""
UPDATE aecheck.characters SET
category = %s,
style = %s,
light_shadow = %s,
max_manifest = %s,
is_awaken = %s,
is_alter = %s,
alter_character = %s,
seesaa_url = %s,
aewiki_url = %s,
update_date = %s
WHERE character_id = %s
""", (
category,
character.style,
light_shadow,
character.max_manifest,
is_awaken,
character.is_alter,
alter_code,
seesaa_url,
aewiki_url,
update_date,
character_id
))
cur.execute("UPDATE aecheck.dungeon_mappings SET dungeon_id = %s WHERE character_id = %s", (dungeon_id, character_id))
cur.execute("DELETE FROM aecheck.personality_mappings WHERE character_id = %s", (character_id,))
for personality in personalities:
cur.execute(f"SELECT key FROM aecheck.translations WHERE en = '{personality}'")
personality_id = cur.fetchone()[0]
cur.execute(
"INSERT INTO aecheck.personality_mappings (character_id, personality_id) VALUES (%s, %s)",
(character_id, personality_id)
)
cur.execute("UPDATE aecheck.translations SET ko = %s, en = %s, ja = %s WHERE key = %s", (korean_name, character.english_name, japanese_name, f'c{code}'))
cur.execute("UPDATE aecheck.translations SET ko = %s, en = %s, ja = %s WHERE key = %s", (character.korean_class_name, english_class_name, japanese_class_name, f'book.{character_id}'))
upload_image(character, character_id, code, is_awaken)
if __name__ == "__main__":
update_character(Character(
english_name="Ryza",
korean_class_name=None,
style=Style.FOUR.value,
altema_url="https://altema.jp/anaden/chara/1118",
is_original_4star=True
))
update_character(Character(
english_name="Klaudia",
korean_class_name=None,
style=Style.FOUR.value,
altema_url="https://altema.jp/anaden/chara/1119",
is_original_4star=True
))
update_character(Character(
english_name="Empel",
korean_class_name=None,
style=Style.FOUR.value,
altema_url="https://altema.jp/anaden/chara/1120",
is_original_4star=True
))
update_character(Character(
english_name="Ryza",
korean_class_name="기예 연금술사",
style=Style.NS.value,
altema_url="https://altema.jp/anaden/chara/1118",
max_manifest=0
))
update_character(Character(
english_name="Klaudia",
korean_class_name="정숙한 연주자",
style=Style.NS.value,
altema_url="https://altema.jp/anaden/chara/1119",
max_manifest=0
))
update_character(Character(
english_name="Empel",
korean_class_name="유랑 연금술사",
style=Style.NS.value,
altema_url="https://altema.jp/anaden/chara/1120",
max_manifest=0
))
update_character(Character(
english_name="Id",
korean_class_name=None,
style=Style.FOUR.value,
altema_url="https://altema.jp/anaden/chara/1121",
is_original_4star=True
))
update_character(Character(
english_name="Id",
korean_class_name="니르바나",
style=Style.NS.value,
altema_url="https://altema.jp/anaden/chara/1121",
max_manifest=0
))