-
Notifications
You must be signed in to change notification settings - Fork 0
/
picks_bans_to_csv.py
149 lines (124 loc) · 4.62 KB
/
picks_bans_to_csv.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Scrape Leaguepedia for picks and bans and create a CSV file with the data."""
__file__ = 'picks_bans_to_csv.py'
__author__ = 'Jesse Estes'
__copyright__ = 'Copyright 2022, LolDraftSimulator'
__credits__ = ['Jesse Estes']
__license__ = 'MIT'
__version__ = '1.0.1'
__maintainer__ = 'Jesse Estes'
__email__ = '[email protected]'
__status__ = 'Prototype'
# --------------------------------------------------------------------------- #
# Imports #
# --------------------------------------------------------------------------- #
# Standard libraries
# Third-party libraries
import leaguepedia_parser
import lol_id_tools as lit
import pandas as pd
# Owned libraries
# --------------------------------------------------------------------------- #
# Code #
# --------------------------------------------------------------------------- #
# Initialize a dictionary to store data
draft_dict = {
'Blue Ban 1': [],
'Red Ban 1': [],
'Blue Ban 2': [],
'Red Ban 2': [],
'Blue Ban 3': [],
'Red Ban 3': [],
'Blue Pick 1': [],
'Red Pick 1': [],
'Red Pick 2': [],
'Blue Pick 2': [],
'Blue Pick 3': [],
'Red Pick 3': [],
'Red Ban 4': [],
'Blue Ban 4': [],
'Red Ban 5': [],
'Blue Ban 5': [],
'Red Pick 4': [],
'Blue Pick 4': [],
'Blue Pick 5': [],
'Red Pick 5': [],
}
# Create a list of names of regions
region_names = ['China', 'Europe', 'Korea', 'North America']
# Create a list of the names of tournaments
tournament_names = [
'LPL/2021 Season/Spring Season',
'LPL/2021 Season/Summer Season',
'LEC/2021 Season/Spring Season',
'LEC/2021 Season/Summer Season',
'LCK/2021 Season/Spring Season',
'LCK/2021 Season/Summer Season',
'LCS/2021 Season/Spring Season',
'LCS/2021 Season/Summer Season',
]
# Get the reigons
regions = leaguepedia_parser.get_regions()
# Loop through the list of region names
for region_name in region_names:
# Get tournaments from the 2021 season of the specified region
tournaments = leaguepedia_parser.get_tournaments(region_name, year=2021)
# Loop through the list of tournament names
for tournament_name in tournament_names:
# Get all games from the specified tournament
games = leaguepedia_parser.get_games(tournament_name)
# Loop through all the games from the specified list
for game in games:
# Get the details of the current game
current_game = leaguepedia_parser.get_game_details(game)
# Save the picks and bans of the current game
picks_bans = current_game.picksBans
# Save the teams playing in the current gamee
teams = current_game.teams
# Set up pick/ban counters for each team
count_blue_ban = 0
count_red_ban = 0
count_blue_pick = 0
count_red_pick = 0
# Loop through all picks and bans
for champion in picks_bans:
# Check if the champion was picked or banned
if champion.isBan:
# Check what team banned the champion
if champion.team == 'BLUE' and count_blue_ban < 5:
# Increment the counter
count_blue_ban += 1
# Create a string to use as the dictionary index
result = 'Blue Ban ' + str(count_blue_ban)
elif count_red_ban < 5:
# Increment the counter
count_red_ban += 1
# Create a string to use as the dictionary index
result = 'Red Ban ' + str(count_red_ban)
# Store the draft data in the dictionary
draft_dict[result].append(
lit.get_name(champion.championId, object_type='champion')
)
else:
# Check what team picked the champion
if champion.team == 'BLUE' and count_blue_pick < 5:
# Increment the counter
count_blue_pick += 1
# Create a string to use as the dictionary index
result = 'Blue Pick ' + str(count_blue_pick)
elif count_red_pick < 5:
# Increment the counter
count_red_pick += 1
# Create a string to use as the dictionary index
result = 'Red Pick ' + str(count_red_pick)
# Store the draft data in the dictionary
draft_dict[result].append(
lit.get_name(champion.championId, object_type='champion')
)
# Create a DataFrame using the dictionary
data = pd.DataFrame(draft_dict)
# Shuffle the DataFrame
data = data.sample(frac=1)
# Send the DataFrame to a csv file for reading
data.to_csv('picks_bans_2021.csv', index=False)