forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] master from avinashkranjan:master #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1a9f064
Added Battery Notification Script
pankaj892 661616e
Update Battery-Notification/README.md
pankaj892 f84f18b
Update README.md
pankaj892 9ebc91b
Update SCRIPTS.md
pankaj892 e8a3559
Update SCRIPTS.md
pankaj892 54daeb9
Update Battery-Notification.py
pankaj892 e7367b1
GUI Implementation done
Ayushjain2205 c4bc0dd
web scraping and showing result in GUI complete
Ayushjain2205 a31fc40
requirements files added
Ayushjain2205 451308a
Readme file added
Ayushjain2205 6b16b1a
Update Battery-Notification.py
pankaj892 52a3abc
player data allignment fix
Ayushjain2205 b94ba81
2021 support added
Ayushjain2205 1152f09
readme updated with new UI screenshot
Ayushjain2205 0d86656
Update Battery-Notification/Battery-Notification.py
pankaj892 5873386
Update Battery-Notification.py
pankaj892 16b398f
Merge pull request #857 from Ayushjain2205/ipl-statistics-gui
avinashkranjan 4a8bf7b
Merge pull request #746 from pankaj892/master
avinashkranjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
Battery-Notification/Battery-Notification.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import psutil | ||
from plyer import notification | ||
import time | ||
#From psutil we import sensors battery class which gives us battery percentage | ||
threshold = int(input('Enter the threshold: ')) | ||
|
||
battery = psutil.sensors_battery() | ||
percent = battery.percent | ||
|
||
while(True): | ||
battery = psutil.sensors_battery() | ||
cur_per = battery.percent | ||
change = cur_per - percent | ||
diff = abs(change) | ||
#We calculate the change in the battery and show notification if battery level increases or decreases | ||
if(diff >= threshold): | ||
notification.notify( | ||
title = "Battery Percentage", | ||
message = str(cur_per) + "% Battery Remaining", | ||
timeout = 5 | ||
) | ||
percent = cur_per | ||
continue |
19 changes: 19 additions & 0 deletions
Battery-Notification/README.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This is a Python Script which shows the battery percentage left | ||
|
||
## Requirements | ||
|
||
For this script to run you need to have psutil and plyer packages installed | ||
|
||
Run the command in terminal to install package | ||
|
||
``` | ||
$ pip install psutil | ||
``` | ||
``` | ||
$ pip install plyer | ||
``` | ||
Run the program using command | ||
|
||
``` | ||
$ python Battery-Notification.py | ||
``` |
26 changes: 26 additions & 0 deletions
IPL Statistics GUI/README.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# IPL Statistics GUI | ||
Running this Script would allow the user see IPL statistics from various categories like most runs , most wickets etc from all seasons (2008 - 2020) | ||
|
||
## Setup instructions | ||
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. | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
After satisfying all the requirements for the project, Open the terminal in the project folder and run | ||
``` | ||
python ipl.py | ||
``` | ||
or | ||
``` | ||
python3 ipl.py | ||
``` | ||
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. | ||
|
||
## Output | ||
|
||
The user can choose the statistics they want to analyse as shown in the sample screenshot below | ||
|
||
 | ||
|
||
## Author | ||
[Ayush Jain](https://github.com/Ayushjain2205) |
108 changes: 108 additions & 0 deletions
IPL Statistics GUI/ipl.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
import tkinter as tk | ||
from tkinter import ttk | ||
|
||
# Dictionary containing category and corresponding slug value | ||
categories = {'Most Runs': 'most-runs', | ||
'Most Fours': 'most-fours', 'Most Sixes': 'most-sixes', 'Most Fifties': 'most-fifties', | ||
'Most Centuries': 'most-centuries', 'Highest Scores': 'highest-scores', 'Most Wickets': 'most-wickets', | ||
'Most Maidens': 'most-maidens', 'Most Dot Balls': 'most-dot-balls', 'Best Bowling Average': 'best-bowling-average', | ||
'Best Bowling Economy': 'best-bowling-economy', 'Best Bowling Strike Rate': 'best-bowling-strike-rate'} | ||
|
||
# Function to generate request url based on user choice | ||
def generate_url(): | ||
category_choice = category.get() | ||
year_choice = year.get() | ||
if (year_choice == 'All time'): | ||
year_choice = 'all-time' | ||
category_slug = categories[category_choice] | ||
url = 'https://www.iplt20.com/stats/{}/{}'.format( | ||
year_choice, category_slug) | ||
return url | ||
|
||
# Function to scrape results based on request url | ||
def scrape_results(): | ||
url = generate_url() | ||
page = requests.get(url) | ||
|
||
# Start scraping resultant html data | ||
soup = BeautifulSoup(page.content, 'html.parser') | ||
results = soup.find( | ||
"table", {"class": "table table--scroll-on-tablet top-players"}) | ||
rows = results.findChildren('tr') | ||
|
||
table_data = [] | ||
row_values = [] | ||
# Append player data into a list | ||
for row in rows: | ||
cells = row.findChildren(['th', 'td']) | ||
for cell in cells: | ||
value = cell.text.strip() | ||
value = " ".join(value.split()) | ||
row_values.append(value) | ||
table_data.append(row_values) | ||
row_values = [] | ||
|
||
# Formatting the data stored in the list | ||
p_records = "" | ||
for player in table_data[:51]: | ||
single_record = "" | ||
for cell in player: | ||
format_cell = "{:<20}" | ||
single_record += format_cell.format(cell[:20]) | ||
single_record += "\n" | ||
p_records += single_record | ||
|
||
# Adding the formatted data into tkinter GUI | ||
query_label.config(state=tk.NORMAL) | ||
query_label.delete(1.0,"end") | ||
query_label.insert(1.0,p_records) | ||
query_label.config(state=tk.DISABLED) | ||
|
||
|
||
# Creating tkinter window | ||
window = tk.Tk() | ||
window.title('IPL Statistics') | ||
window.geometry('800x850') | ||
|
||
# label text for title | ||
ttk.Label(window, text="IPL Statistics", | ||
background='blue', foreground="white", | ||
font=("Helvetica", 20)).grid(row=0, column=1) | ||
|
||
# label | ||
ttk.Label(window, text="Select category and year :", | ||
font=("Helvetica", 15)).grid(column=0, | ||
row=5, padx=10, pady=25) | ||
|
||
# Combobox creation | ||
category = ttk.Combobox( | ||
window, width=27, state='readonly') | ||
year = ttk.Combobox( | ||
window, width=27, state='readonly') | ||
|
||
submit_btn = ttk.Button(window, text="Search", command=scrape_results) | ||
|
||
# Adding combobox drop down list | ||
category['values'] = ('Most Runs', 'Most Fours', | ||
'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') | ||
|
||
year['values'] = ('All time','2021', '2020', '2019', '2018', '2017', '2016', | ||
'2015', '2014', '2013', '2012', '2011', '2010', '2009', '2008') | ||
|
||
category.grid(column=1, row=5, padx=10) | ||
category.current(0) | ||
|
||
year.grid(column=2, row=5, padx=10) | ||
year.current(0) | ||
|
||
submit_btn.grid(row=5, column=3, pady=5, padx=15, ipadx=5) | ||
|
||
frame = ttk.Frame(window) | ||
frame.place(relx=0.50, rely=0.12, relwidth=0.98, relheight=0.90, anchor="n") | ||
|
||
query_label = tk.Text( frame,height="52",width="500") | ||
query_label.grid(row=7, columnspan=2) | ||
|
||
window.mainloop() |
2 changes: 2 additions & 0 deletions
IPL Statistics GUI/requirements.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests | ||
beautifulsoup4 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.