-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
214 lines (176 loc) Β· 6.12 KB
/
main.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import re
import json
from typing import List
import requests
from bs4 import BeautifulSoup
from database import db_session
from models import SupportCard, CardEventChoice, CardEvent, Skill, UmaEvent, Umamusume
from models.iterator import iter_card_uri, iter_uma_event
from translator import translate
from utils import download_image
def get_illust_url(article_url: str):
r = requests.get(article_url)
if r.status_code != 200:
raise ConnectionError(f"Cannot load page: {article_url}")
soup = BeautifulSoup(r.text, 'lxml')
image_soup = soup.find('img', {'alt': 'γ€γ©γΉγ'})
image_url = image_soup['data-original']
return image_url
def crawl_all_uma():
r = requests.get("https://gamewith.jp/uma-musume/article/show/253241")
soup = BeautifulSoup(r.text, 'lxml')
uma_list_table = soup.find('div', {"class": "umamusume-ikusei-ichiran"})
rows: List[BeautifulSoup] = uma_list_table.find_all('tr')
for row in rows:
uma_info_a_tag = row.find('a')
if not uma_info_a_tag:
continue
uma_info_uri = uma_info_a_tag['href']
print(uma_info_uri)
if uma_info_uri == "https://gamewith.jp/uma-musume/article/show/266048":
continue
payload = {
"root_password": "tngh167",
"new_card_uri": uma_info_uri
}
header = {
"Content-Type": "application/json"
}
p = requests.post("http://localhost:5000/ops/new/uma", headers=header, data=json.dumps(payload))
if p.text != "ok":
print(p.text)
break
def change_card_event_choice(soup: BeautifulSoup):
choice_tables = soup.find_all('div', {"class": "uma_choice_table"})
for table in choice_tables:
tr_tags = table.find_all('tr')
event_title = table.find_previous_sibling('h3').text
event = CardEvent.query.filter(CardEvent.title == event_title).first()
for tr in tr_tags:
title = tr.find('th').text
choice: CardEventChoice = \
CardEventChoice.query.filter(CardEventChoice.title == title) \
.filter(CardEventChoice.event == event).first()
if choice:
effect = tr.find('td').get_text(separator="\n")
choice.effect = effect
choice.effect_kr = effect
print(choice.uuid)
else:
print('something went wrong')
db_session.commit()
def change_card_event_bulk():
for uri in iter_card_uri():
r = requests.get(uri)
soup = BeautifulSoup(r.text, 'lxml')
change_card_event_choice(soup)
def search_skill():
choices: List[CardEventChoice] = CardEventChoice.query.all()
for choice in choices:
skill = re.findall("(γ.*?γ)", choice.effect)
def dump_new_card():
for uri in iter_card_uri():
payload = {
"root_password": "tngh167",
"new_card_uri": uri
}
header = {
"Content-Type": "application/json"
}
p = requests.post("http://localhost:5000/ops/new/card", headers=header, data=json.dumps(payload))
if p.text != "ok":
print(p.text)
break
def download_skill_image():
for i in range(100):
uri = f"https://img.gamewith.jp/article_tools/uma-musume/gacha/i_skill{i}.png"
download_image(uri)
def get_skill_icon(name: str, grade_value: str, type_value: str, float_value: str):
if int(grade_value) < 0:
return -1, -1
grade_data = {
"340": 2,
"508": 1,
"334": 1,
"394": 1,
"262": 0,
"240": 2,
"217": 0,
"180": 2,
"174": 0,
"129": 0,
"85": 0,
"461": 1
}
grade = grade_data[grade_value]
type_data = {
"μ§κ΅¬λ ₯": 0,
"κ°μλ": 1,
"μλ": 2,
"μ€νλ―Έλ": 3,
"μ§λ₯": 4,
"κ·Όμ±": 5,
"μ€νΌλ": 6,
"νμ": 7,
"μλ κ°μ": 8,
"μ€ννΈ": 9,
"λλ°": 10,
"ν¬μ§μ
": 11,
"μμΌ ": 12,
"μμΌ λ°©ν΄": 13,
"μ€νλ―Έλ λ°©ν΄": 14,
"νΌμ§μ»¬": 15,
}
type_number = type_data[type_value]
if type_number == 3 and int(float_value) < 0:
type_number = 14
if name == "γ©γγγΌγ»γγ³" or name == "γΉγΌγγΌγ©γγγΌγ»γγ³":
type_number = 15
return grade, type_number
def read_skill_csv():
import csv
with open('skill.csv', newline='') as csvfile:
spamreader = csv.DictReader(csvfile)
for row in spamreader:
icon = get_skill_icon(row['Name'], row['Grade Value'], row['Type 1'], row['Float Value 1'])
name = row['Name']
name_kr = row['NameKr']
description = row['Description']
condition = row['Condition']
if icon[0] > -1 or icon[1] > -1:
icon_uri = f"i_skill{icon[0]}_{icon[1]}.png"
skill = Skill(name, name_kr, description, condition, icon_uri)
db_session.add(skill)
db_session.commit()
def read_uma_event_csv():
import csv
with open('data_table/uma_event.csv', newline='') as csvfile:
spamreader = csv.DictReader(csvfile)
for row in spamreader:
uuid = int(row['uuid'])
title_kr = row['title_kr']
event = UmaEvent.query.filter(UmaEvent.uuid == uuid).first()
event.title_kr = title_kr
db_session.commit()
def remove_same_data():
buffer = set([])
for event in iter_uma_event():
mapper = (event.title, event.umamusume_id)
if mapper in buffer:
print(event.__dict__)
db_session.delete(event)
else:
buffer.add(mapper)
db_session.commit()
def remove_by_gamewith(wiki_id):
obj = Umamusume.query.filter(Umamusume.gamewith_wiki_id == wiki_id).first()
if not obj:
obj = SupportCard.query.filter(SupportCard.gamewith_wiki_id == wiki_id).first()
db_session.delete(obj)
db_session.commit()
def main():
translate()
# remove_by_gamewith(272325)
# remove_same_data()
if __name__ == '__main__':
main()