-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegaue.py
174 lines (132 loc) · 7.01 KB
/
legaue.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
from head import *
key_lol='라이엇 키를 입력해주세요'
headers_lol= {"X-Riot-Token":key_lol}
nickname_lol="검색할 닉네임을 검색해주세요"
match_list=[]
core_nick_list=["매칭내부에 들어가야하는 인원적어주세요"]
#매치 클래스
class match():
#생성
def __init__(self,game_duration,game_creation,game_Mode,player):
self.duration=str(datetime.timedelta(seconds=game_duration)) #매치 플레이시간
self.creation=str((dt.fromtimestamp(game_creation/1000)).strftime('%Y/%m/%d %H시 %M분 %S초')) #게임시작시간
self.mode=game_Mode #맵
self.players=player #플레이어 리스트
self.core_players=[]
#내가알고싶은애들 넣기
def set_core_player(self):
list1=[]
for i in self.players:
if (i.nickname in core_nick_list): self.core_players.append(i)
#출력
def print_data(self):
print("닉네임:"+str(self.players[0].nickname))
print("게임길이:"+str(self.duration))
print("챔피언:"+str(self.players[0].champion))
print("킬:"+str(self.players[0].kills))
print("데스:"+str(self.players[0].deaths))
print("어시:"+str(self.players[0].assists))
print("죽어있던시간:"+str(self.players[0].dead_time))
print("딜량:"+str(self.players[0].total_damage))
print("받은딜량:"+str(self.players[0].total_taken_damgage))
#알고싶은 애들 출력
def print_core_data(self):
print("게임길이:"+str(self.duration))
print("게임형식:"+self.mode)
print("게임시작시간:"+self.creation)
for player in self.core_players:
print("닉네임:"+str(player.nickname))
print("승리?:"+str(player.win))
print("챔피언:"+str(player.champion))
print("킬:"+str(player.kills))
print("데스:"+str(player.deaths))
print("어시:"+str(player.assists))
print("죽어있던시간:"+str(player.dead_time))
print("딜량:"+str(player.total_damage))
print("받은딜량:"+str(player.total_taken_damgage))
#디코출력용
def discord_print_lol(self):
body1=[]
win_game=""
output=""
for player_core in self.core_players:
body1.append([str(player_core.nickname),str(player_core.champion),str(player_core.kills)+"/"+str(player_core.deaths)+"/"+str(player_core.assists),str(player_core.total_damage),str(player_core.dead_time)])
win_game=player_core.win
head_print="["+str(self.creation)+"]"+win_game+"\t"+str(self.duration)+"\n"
output = t2a(
header=["닉네임", "챔프", "킬뎃", "딜량", "죽은시간"],
body=body1,
style=PresetStyle.thin_compact
)
output=head_print+output
print(output)
return output
#닉,딜같은 게임의 플레이어정보
class player():
def __init__(self,nickname,champion,kills,deaths,assists,win,dead_time,total_damage,total_taken_damage):
self.nickname=nickname
self.champion=champion
self.kills=kills
self.deaths=deaths
self.assists=assists
if win=="True": self.win="승리"
else: self.win="패배"
self.dead_time=str(datetime.timedelta(seconds=dead_time))
self.total_damage=total_damage
self.total_taken_damgage=total_taken_damage
#api 데이터 크롤링
class crol_lol():
#puuid 얻기
def get_puuid(nickname):
url_lol='https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/'+nickname
r= requests.get(url_lol,headers=headers_lol)
return r.json()['puuid'] #고유 puuid
#게임기록들얻기
def get_matchs(nickname):
lol_puuid=crol_lol.get_puuid(nickname)
r=requests.get('https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/'+lol_puuid+'/ids?start=0&count=20',headers=headers_lol)
now = time.time()
diff=43200+1000000
start_time=now-diff #12시간전
r=requests.get('https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/'+lol_puuid+'/ids?startTime='+str(int(start_time))+'&start=0&count=20',headers=headers_lol)
return r.json() #게임 기록들
#게임 세부사항얻기
def get_gamedata(nickname):
lol_matchs=crol_lol.get_matchs(nickname_lol) #12시간 내부의 게임 매치들
for lol_match in lol_matchs:
player_list=[]
r=requests.get('https://asia.api.riotgames.com/lol/match/v5/matches/'+lol_match,headers=headers_lol)
game_duration=r.json()['info']['gameDuration'] #게임길이(초시간)
game_creation=r.json()['info']['gameCreation'] #게임시작시간(타임스탬프)
game_Mode=r.json()['info']['gameMode'] #게임맵
for i in range(10):
game_nickname=r.json()['info']['participants'][i]['summonerName'] #플레이어 이름
game_champion=r.json()['info']['participants'][i]['championName'] #챔프이름
game_kills=r.json()['info']['participants'][i]['kills'] #킬
game_deaths=r.json()['info']['participants'][i]['deaths'] #데스
game_assists=r.json()['info']['participants'][i]['assists'] #어시스트
game_win=r.json()['info']['participants'][i]['win'] #승패 bool 형식
game_dead_time=r.json()['info']['participants'][i]['totalTimeSpentDead'] #뒤져있던 시간(초시간)
game_total_damage=r.json()['info']['participants'][i]['totalDamageDealtToChampions'] #딜량
game_total_taken_damage=r.json()['info']['participants'][i]['totalDamageTaken'] #받은 피해량
player_list.append(player(game_nickname,game_champion,game_kills,game_deaths,game_assists,game_win,game_dead_time,game_total_damage,game_total_taken_damage))#플레이어 10명데이터
match_list.append(match(game_duration,game_creation,game_Mode,player_list))
print("게임데이터 불러오기 완료")
print("게임데이터 불러오기 모두 완료")
#디코 출력
@bot.command(aliases=['롤전적','롤'])
async def 롤결산(ctx,*,nic):
nickname_lol=nic
crol_lol.get_gamedata(nickname_lol)
cnt=0
output_dis=""
for mat in match_list:
mat.set_core_player()
#mat.print_core_data()
output_dis=output_dis+mat.discord_print_lol()+"\n"
cnt+=1
if cnt >=4:
await ctx.send(f"```\n{output_dis}\n```")
output_dis=""
cnt=0
await ctx.send(f"```\n{output_dis}\n```")