Created
October 9, 2023 04:01
-
-
Save ProjectEli/d7971c0f8ad57dfc10844bfe23911f13 to your computer and use it in GitHub Desktop.
TW_Eta_Rank_Analyzer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request, datetime, os | |
# This code executes many http get requests in short time | |
# So don't abuse it | |
NumPages = 20 | |
startTime = datetime.datetime.now() | |
if startTime.hour < 11: | |
dirName = (startTime - datetime.timedelta(days=1)).strftime('%Y%m%d') | |
else: | |
dirName = startTime.strftime('%Y%m%d') | |
# create saving directory | |
if not os.path.exists(dirName): | |
os.makedirs(dirName) | |
for k in [x+1 for x in range(NumPages)]: | |
url = f'https://tales.nexon.com/Community/Ranking/EtaRank?page={k}&cc=99&sc=7' | |
with urllib.request.urlopen(url) as response: | |
html = response.read().decode("utf-8") | |
fname = f"hk_{k}.html" | |
with open(f"{dirName}/{fname}", 'w', encoding="utf-8") as f: | |
f.write(html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request, datetime, os | |
# This code executes many http get requests in short time | |
# So don't abuse it | |
NumPages = 20 | |
startTime = datetime.datetime.now() | |
if startTime.hour < 11: | |
dirName = (startTime - datetime.timedelta(days=1)).strftime('%Y%m%d') | |
else: | |
dirName = startTime.strftime('%Y%m%d') | |
# create saving directory | |
if not os.path.exists(dirName): | |
os.makedirs(dirName) | |
for k in [x+1 for x in range(NumPages)]: | |
url = f'https://tales.nexon.com/Community/Ranking/EtaRank?page={k}&cc=99&sc=16' | |
with urllib.request.urlopen(url) as response: | |
html = response.read().decode("utf-8") | |
fname = f"{k}.html" | |
with open(f"{dirName}/{fname}", 'w', encoding="utf-8") as f: | |
f.write(html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bs4 | |
import collections | |
import operator | |
dirName = "20231009" | |
NumPages = 20 | |
serverList = ["네냐플", "하이아칸"] | |
serverFileNamePrefix = ["", "hk_"] | |
for k2 in range(len(serverList)): | |
print(f"{dirName} 기준 {serverList[k2]} 서버 에타랭킹 캐릭별 분포") | |
charList = [] | |
for k in [x+1 for x in range(NumPages)]: | |
fname = f"{serverFileNamePrefix[k2]}{k}.html" | |
with open(f"{dirName}/{fname}", 'r', encoding="utf-8") as f: | |
html = f.read() | |
soup = bs4.BeautifulSoup(html,features="html.parser") | |
characterAnchorTags = soup.find_all("td", {"class": "col_rank"}) | |
for anchorTag in characterAnchorTags: | |
rootTag = anchorTag.parent | |
clsNames = ["number", "charname", "nickname", "col_level", "col_point"] | |
tagNames = ["span", "span", "span", "td", "td"] | |
characterValues = [rootTag.find(tagNames[k], {"class": clsNames[k]}).text for k in range(len(clsNames))] | |
charList.append(characterValues) | |
charNames = [elem[1] for elem in charList] | |
# for elem in collections.Counter(charNames).most_common(): | |
# print(f"{elem[0]:10}\t{elem[1]:>3}") | |
EtaLvIndex = 3 | |
charListLv5 = [elem for elem in charList if int(elem[EtaLvIndex])>=5] | |
charNamesLv5 = [elem[1] for elem in charListLv5] | |
EtaLv1MostCommon = collections.Counter(charNames).most_common() | |
EtaLv5MostCommon = collections.Counter(charNamesLv5).most_common() | |
EtaLv5MostCommonCharNames = [elem[0] for elem in EtaLv5MostCommon] | |
EtaLv5dict = dict(EtaLv5MostCommon) | |
EtaLv1dict = dict(EtaLv1MostCommon) | |
charTable = [[charName, EtaLv5dict[charName], EtaLv1dict[charName]] for charName in EtaLv5MostCommonCharNames] | |
sortedCharTable = sorted(charTable, key=operator.itemgetter(1,2),reverse=True) | |
print(f"{'캐릭명':10}\t{'5렙↑':>3}\t{'1렙↑':>3}") | |
print(f"{'------':10}\t{'---':>3}\t{'---':>3}") | |
for elem in sortedCharTable: | |
print(f"{elem[0]:10}\t{elem[1]:>3}\t{elem[2]:>3}") | |
print(f"{'------':10}\t{'---':>3}\t{'---':>3}") | |
print(f"{'계':10}\t{len(charListLv5):>3}\t{len(charList):>3}") | |
clsTypes = ["등수", "캐릭터", "캐릭터명", "에타레벨", "정수개수"] | |
txtArranged = ",".join(clsTypes) + "\n" + "\n".join([",".join(elem) for elem in charList]) | |
with open(f"{dirName}_{serverList[k2]}.txt", 'w', encoding="utf-8") as f: | |
f.write(txtArranged) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment