Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 16b398f

Browse files
Merge pull request avinashkranjan#857 from Ayushjain2205/ipl-statistics-gui
Ipl statistics gui
2 parents cd99401 + 1152f09 commit 16b398f

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

‎IPL Statistics GUI/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# IPL Statistics GUI
2+
Running this Script would allow the user see IPL statistics from various categories like most runs , most wickets etc from all seasons (2008 - 2020)
3+
4+
## Setup instructions
5+
In order to run this script, you need to have Python and pip installed on your system. After you're done installing Python and pip, run the following command from your terminal to install the requirements from the same folder (directory) of the project.
6+
```
7+
pip install -r requirements.txt
8+
```
9+
After satisfying all the requirements for the project, Open the terminal in the project folder and run
10+
```
11+
python ipl.py
12+
```
13+
or
14+
```
15+
python3 ipl.py
16+
```
17+
depending upon the python version. Make sure that you are running the command from the same virtual environment in which the required modules are installed.
18+
19+
## Output
20+
21+
The user can choose the statistics they want to analyse as shown in the sample screenshot below
22+
23+
![IPL Statistics GUI](https://i.postimg.cc/nLdgKhWQ/ipl-stats.png)
24+
25+
## Author
26+
[Ayush Jain](https://github.com/Ayushjain2205)

‎IPL Statistics GUI/ipl.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
import tkinter as tk
4+
from tkinter import ttk
5+
6+
# Dictionary containing category and corresponding slug value
7+
categories = {'Most Runs': 'most-runs',
8+
'Most Fours': 'most-fours', 'Most Sixes': 'most-sixes', 'Most Fifties': 'most-fifties',
9+
'Most Centuries': 'most-centuries', 'Highest Scores': 'highest-scores', 'Most Wickets': 'most-wickets',
10+
'Most Maidens': 'most-maidens', 'Most Dot Balls': 'most-dot-balls', 'Best Bowling Average': 'best-bowling-average',
11+
'Best Bowling Economy': 'best-bowling-economy', 'Best Bowling Strike Rate': 'best-bowling-strike-rate'}
12+
13+
# Function to generate request url based on user choice
14+
def generate_url():
15+
category_choice = category.get()
16+
year_choice = year.get()
17+
if (year_choice == 'All time'):
18+
year_choice = 'all-time'
19+
category_slug = categories[category_choice]
20+
url = 'https://www.iplt20.com/stats/{}/{}'.format(
21+
year_choice, category_slug)
22+
return url
23+
24+
# Function to scrape results based on request url
25+
def scrape_results():
26+
url = generate_url()
27+
page = requests.get(url)
28+
29+
# Start scraping resultant html data
30+
soup = BeautifulSoup(page.content, 'html.parser')
31+
results = soup.find(
32+
"table", {"class": "table table--scroll-on-tablet top-players"})
33+
rows = results.findChildren('tr')
34+
35+
table_data = []
36+
row_values = []
37+
# Append player data into a list
38+
for row in rows:
39+
cells = row.findChildren(['th', 'td'])
40+
for cell in cells:
41+
value = cell.text.strip()
42+
value = " ".join(value.split())
43+
row_values.append(value)
44+
table_data.append(row_values)
45+
row_values = []
46+
47+
# Formatting the data stored in the list
48+
p_records = ""
49+
for player in table_data[:51]:
50+
single_record = ""
51+
for cell in player:
52+
format_cell = "{:<20}"
53+
single_record += format_cell.format(cell[:20])
54+
single_record += "\n"
55+
p_records += single_record
56+
57+
# Adding the formatted data into tkinter GUI
58+
query_label.config(state=tk.NORMAL)
59+
query_label.delete(1.0,"end")
60+
query_label.insert(1.0,p_records)
61+
query_label.config(state=tk.DISABLED)
62+
63+
64+
# Creating tkinter window
65+
window = tk.Tk()
66+
window.title('IPL Statistics')
67+
window.geometry('800x850')
68+
69+
# label text for title
70+
ttk.Label(window, text="IPL Statistics",
71+
background='blue', foreground="white",
72+
font=("Helvetica", 20)).grid(row=0, column=1)
73+
74+
# label
75+
ttk.Label(window, text="Select category and year :",
76+
font=("Helvetica", 15)).grid(column=0,
77+
row=5, padx=10, pady=25)
78+
79+
# Combobox creation
80+
category = ttk.Combobox(
81+
window, width=27, state='readonly')
82+
year = ttk.Combobox(
83+
window, width=27, state='readonly')
84+
85+
submit_btn = ttk.Button(window, text="Search", command=scrape_results)
86+
87+
# Adding combobox drop down list
88+
category['values'] = ('Most Runs', 'Most Fours',
89+
'Most Sixes', 'Most Fifties', 'Most Centuries', 'Highest Scores', 'Most Wickets', 'Most Maidens', 'Most Dot Balls', 'Best Bowling Average', 'Best Bowling Economy', 'Best Bowling Strike Rate')
90+
91+
year['values'] = ('All time','2021', '2020', '2019', '2018', '2017', '2016',
92+
'2015', '2014', '2013', '2012', '2011', '2010', '2009', '2008')
93+
94+
category.grid(column=1, row=5, padx=10)
95+
category.current(0)
96+
97+
year.grid(column=2, row=5, padx=10)
98+
year.current(0)
99+
100+
submit_btn.grid(row=5, column=3, pady=5, padx=15, ipadx=5)
101+
102+
frame = ttk.Frame(window)
103+
frame.place(relx=0.50, rely=0.12, relwidth=0.98, relheight=0.90, anchor="n")
104+
105+
query_label = tk.Text( frame,height="52",width="500")
106+
query_label.grid(row=7, columnspan=2)
107+
108+
window.mainloop()

‎IPL Statistics GUI/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
beautifulsoup4

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /