Skip to content

Commit 8037cc6

Browse files
authored
Merge branch 'avinashkranjan:master' into simple-clock-gui
2 parents 181b0de + 7d2be06 commit 8037cc6

File tree

128 files changed

+91116
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+91116
-147
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
The provided code is a Python script that utilizes the `webbrowser` module to open a specified website multiple times in separate browser tabs.
2+
3+
Here is a description and documentation for the code:
4+
5+
1. The `webbrowser` module is imported at the beginning of the code. This module provides a high-level interface to allow displaying web-based documents to users.
6+
7+
The webbrowser module is a standard library module in Python, which means it is already included with your Python installation. You don't need to install it separately. It should be available and ready to use without any additional steps.
8+
9+
2. The user is prompted to enter the number of times they want to open the website. The input is stored in the variable `n` as an integer.
10+
11+
3. A `for` loop is used to iterate `n` times. The loop variable `e` represents the current iteration.
12+
13+
4. Inside the loop, the `webbrowser.open_new_tab()` function is called, passing the URL of the website to open as an argument. This function opens the URL in a new browser tab.
14+
15+
5. After the loop completes all iterations, the script execution ends.
16+
17+
Note: It's worth mentioning that the `webbrowser` module's behavior may vary depending on the operating system and the default web browser settings. Additionally, some web browsers may restrict or block the automatic opening of multiple tabs for security reasons.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import webbrowser # Import the webbrowser module
2+
3+
n = int(input('enter how many times you want to open website?')) # Prompt user for the number of times to open the website
4+
5+
for e in range(n): # Loop 'n' times
6+
webbrowser.open_new_tab('https://github.com/avinashkranjan/Amazing-Python-Scripts') # Open the specified website in a new tab

AI TicTacToe/src/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# TicTacToe Game
2+
3+
A simple implementation of the Tic Tac Toe game in Python.
4+
5+
## Rules of the Game
6+
Tic Tac Toe is a classic game played on a 3x3 grid. Two players take turns placing their markers (X or O) on the board, aiming to get three of their marks in a row (horizontally, vertically, or diagonally) before the opponent does. If all the positions on the board are filled and no player has won, the game ends in a tie.
7+
8+
## How to Play
9+
1. Run the `play_tic_tac_toe()` function in a Python environment.
10+
2. Player 1 will be prompted to choose either X or O.
11+
3. The players will take turns entering their positions on the board, ranging from 1 to 9. The board is displayed after each move.
12+
4. The game continues until one player wins or the board is full.
13+
5. After the game ends, players are given the option to play again.
14+
15+
## Functions
16+
- `display_board(board)`: Prints the current state of the Tic Tac Toe board.
17+
- `player_input()`: Prompts the first player to choose X or O and assigns the markers to player 1 and player 2 accordingly.
18+
- `place_marker(board, marker, position)`: Places the given marker (X or O) at the specified position on the board.
19+
- `win_check(board, mark)`: Checks if the given mark (X or O) has won the game.
20+
- `choose_first()`: Randomly selects which player goes first.
21+
- `space_check(board, position)`: Checks if a particular position on the board is empty.
22+
- `full_board_check(board)`: Checks if the board is full.
23+
- `player_choice(board)`: Asks the current player to choose a position to place their marker and returns the chosen position.
24+
- `replay()`: Asks the players if they want to play again.
25+
26+
## Usage
27+
1. Clone the repository or download the `tic_tac_toe.py` file.
28+
2. Open the file in a Python environment (e.g., IDLE, Jupyter Notebook, or any text editor with Python support).
29+
3. Run the script to start the game.
30+
4. Follow the prompts and enter your choices accordingly.
31+
5. Enjoy playing Tic Tac Toe!

AI TicTacToe/src/TicTacToe.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import random
2+
3+
def display_board(board):
4+
print('-------------')
5+
print('| ' + board[7] + ' | ' + board[8] + ' | ' + board[9] + ' |')
6+
print('-------------')
7+
print('| ' + board[4] + ' | ' + board[5] + ' | ' + board[6] + ' |')
8+
print('-------------')
9+
print('| ' + board[1] + ' | ' + board[2] + ' | ' + board[3] + ' |')
10+
print('-------------')
11+
12+
13+
def player_input():
14+
marker = ''
15+
while marker != 'X' and marker != 'O':
16+
marker = input('Player 1, choose X or O: ').upper()
17+
player1 = marker
18+
player2 = 'O' if player1 == 'X' else 'X'
19+
return player1, player2
20+
21+
22+
def place_marker(board, marker, position):
23+
board[position] = marker
24+
25+
26+
def win_check(board, mark):
27+
winning_combinations = [
28+
[1, 2, 3], [4, 5, 6], [7, 8, 9], # rows
29+
[1, 4, 7], [2, 5, 8], [3, 6, 9], # columns
30+
[1, 5, 9], [3, 5, 7] # diagonals
31+
]
32+
return any(all(board[i] == mark for i in combination) for combination in winning_combinations)
33+
34+
35+
def choose_first():
36+
return random.choice(['Player 1', 'Player 2'])
37+
38+
39+
def space_check(board, position):
40+
return board[position] == ' '
41+
42+
43+
def full_board_check(board):
44+
return all(board[i] != ' ' for i in range(1, 10))
45+
46+
47+
def player_choice(board):
48+
position = 0
49+
while position not in range(1, 10) or not space_check(board, position):
50+
position = int(input('Choose a position (1-9): '))
51+
return position
52+
53+
54+
def replay():
55+
choice = input('Do you want to play again? Enter Yes or No: ')
56+
return choice.lower() == 'yes'
57+
58+
59+
def play_tic_tac_toe():
60+
print('Welcome to Tic Tac Toe!')
61+
while True:
62+
the_board = [' '] * 10
63+
player1_marker, player2_marker = player_input()
64+
turn = choose_first()
65+
print(turn + ' will go first.')
66+
play_game = input('Are you ready to play? Enter y or n: ')
67+
if play_game.lower() == 'y':
68+
game_on = True
69+
else:
70+
game_on = False
71+
72+
while game_on:
73+
if turn == 'Player 1':
74+
display_board(the_board)
75+
position = player_choice(the_board)
76+
place_marker(the_board, player1_marker, position)
77+
78+
if win_check(the_board, player1_marker):
79+
display_board(the_board)
80+
print('Player 1 has won!')
81+
game_on = False
82+
else:
83+
if full_board_check(the_board):
84+
display_board(the_board)
85+
print('TIE GAME!')
86+
game_on = False
87+
else:
88+
turn = 'Player 2'
89+
else:
90+
display_board(the_board)
91+
position = player_choice(the_board)
92+
place_marker(the_board, player2_marker, position)
93+
94+
if win_check(the_board, player2_marker):
95+
display_board(the_board)
96+
print('Player 2 has won!')
97+
game_on = False
98+
else:
99+
if full_board_check(the_board):
100+
display_board(the_board)
101+
print('TIE GAME!')
102+
game_on = False
103+
else:
104+
turn = 'Player 1'
105+
106+
if not replay():
107+
if play_game.lower() == 'n':
108+
print('BYE! Have a good day.')
109+
else:
110+
print('Thank you for playing.')
111+
break
112+
113+
# Start the game
114+
play_tic_tac_toe()

Age-Calculator-GUI/age_calc_gui.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def check_year():
5353
try:
5454
year = int(self.yearEntry.get())
5555
if today.year - year < 0:
56-
self.statement = tk.Label(text=f"{nameValue.get()}'s age cannot be negative.", font="courier 10", bg="lightblue")
56+
self.statement = tk.Label(text=f"{nameValue.get()}'s age\n cannot be negative.", font="courier 10", bg="lightblue")
5757
self.statement.grid(row=6, column=1, pady=15)
5858
return False
5959
else:
6060
return True
6161
except Exception as e:
62-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth year cannot parse to int.", font="courier 10", bg="lightblue")
62+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth year\n cannot parse to int.", font="courier 10", bg="lightblue")
6363
self.statement.grid(row=6, column=1, pady=15)
6464
return False
6565

@@ -69,13 +69,13 @@ def check_month():
6969
try:
7070
month = int(self.monthEntry.get())
7171
if month < 0 or month > 12:
72-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month is outside 1-12.", font="courier 10", bg="lightblue")
72+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month\n is outside 1-12.", font="courier 10", bg="lightblue")
7373
self.statement.grid(row=6, column=1, pady=15)
7474
return False
7575
else:
7676
return True
7777
except Exception as e:
78-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month cannot parse to int.", font="courier 10", bg="lightblue")
78+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month\n cannot parse to int.", font="courier 10", bg="lightblue")
7979
self.statement.grid(row=6, column=1, pady=15)
8080
return False
8181

@@ -85,13 +85,13 @@ def check_day():
8585
try:
8686
day = int(self.dayEntry.get())
8787
if day < 0 or day > 31:
88-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth day is outside 1-31.", font="courier 10", bg="lightblue")
88+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth day is\n outside 1-31.", font="courier 10", bg="lightblue")
8989
self.statement.grid(row=6, column=1, pady=15)
9090
return False
9191
else:
9292
return True
9393
except Exception as e:
94-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month cannot parse to int.", font="courier 10", bg="lightblue")
94+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month\n cannot parse to int.", font="courier 10", bg="lightblue")
9595
self.statement.grid(row=6, column=1, pady=15)
9696
return False
9797

Amazon-Price-Tracker/README.MD

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1 align="center"> Amazon Price Tracker</h1>
2-
Tracks the current given product price.
2+
Tracks the current given product price and provides alerts on price drop on email and whatsapp.
33

44
---------------------------------------------------------------------
55

@@ -8,15 +8,16 @@ Tracks the current given product price.
88
- bs4 (BeautifuSoup)
99
- time
1010
- smtplib
11+
- pywhatkit
12+
- datetime
1113

12-
[requirements.txt]()
14+
[requirements.txt](Amazon-Price-Tracker/requirements.txt)
1315
<hr>
1416

1517
## How it works
1618
- By providing the User agent name and URL of the product that you want to track and buy and then it scrap the web and it
1719
tracks your product price.
18-
19-
- It returns The Tracking price of your product and it sends email when your product price decreases
20+
- It returns The Tracking price of your product and it sends email and whatsapp message when your product price decreases
2021
at best least price.
2122

22-
#### By [Avinash Kr. Ranjan](https://github.com/avinashkranjan)
23+
#### By [Avinash Kr. Ranjan](https://github.com/avinashkranjan)

Amazon-Price-Tracker/amazonprice.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
from bs4 import BeautifulSoup
33
import time
44
import smtplib
5+
import pywhatkit
6+
import datetime
57

68
# header = {
7-
# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
9+
# "
10+
# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
11+
# "
812
# }
913

10-
# Url = "https://www.amazon.in/Apple-AirPods-Wireless-Charging-Case/dp/B07QDRYVCZ/ref=sr_1_1_sspa?crid=2O0YQXVBL4T86&dchild=1&keywords=airpods&qid=1601031081&sprefix=airpod%2Caps%2C615&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUFPVUpPNUNIQUE1RUUmZW5jcnlwdGVkSWQ9QTAxNzI3NjJPNlg3OTJFSTVSOE8mZW5jcnlwdGVkQWRJZD1BMDg1MTYzNjJSRUw4VFVKQzQ1TDkmd2lkZ2V0TmFtZT1zcF9hdGYmYWN0aW9uPWNsaWNrUmVkaXJlY3QmZG9Ob3RMb2dDbGljaz10cnVl"
14+
# Url = "
15+
# https://www.amazon.in/Apple-Original-MMTN2ZM-Lightning-Connector/dp/B01M1EEPOB/ref=sr_1_1?crid=XFITOYOGI999&keywords=airpods+apple&qid=1685422019&s=electronics&sprefix=airpods+appl%2Celectronics%2C458&sr=1-1
16+
# "
1117

1218
# get your browser information by searching "my user agent"
1319
user_agent = input("Enter your User-Agent string here\n")
@@ -20,6 +26,11 @@
2026
# print(soup)
2127

2228

29+
def message_sending(phone_number,title):
30+
now = datetime.datetime.now()
31+
message = f"Price of {title} is fallen below the threshold amount. Click on the link below to buy the product!!!\n\n"
32+
pywhatkit.sendwhatmsg(phone_number, message, now.hour, now.minute + 1)
33+
2334
def mail_sending(mail_id, title, password):
2435
server_mail = "smtp.gmail.com"
2536
port = 587
@@ -37,53 +48,28 @@ def mail_sending(mail_id, title, password):
3748
def check_price():
3849
title = soup.find(id="productTitle").get_text().strip()
3950
try:
40-
price = soup.find(
41-
id="priceblock_ourprice_row").get_text().strip()[:20].replace(
42-
'₹', '').replace(' ', '').replace('Price:', '').replace(
43-
'\n', '').replace('\xa0',
44-
'').replace(',', '').replace('Fu', '')
51+
price = price = soup.find('span', class_='a-price-whole').text
52+
price = price[:len(price)-1]
4553

4654
except:
47-
try:
48-
price = soup.find(
49-
id="priceblock_dealprice").get_text().strip()[:20].replace(
50-
'₹', '').replace(' ', '').replace('Price:', '').replace(
51-
'\n', '').replace('\xa0',
52-
'').replace(',',
53-
'').replace('Fu', '')
54-
55-
except:
56-
try:
57-
price = soup.find(
58-
id="priceblock_ourprice").get_text().strip()[:20].replace(
59-
'₹',
60-
'').replace(' ', '').replace('Price:', '').replace(
61-
'\n',
62-
'').replace('\xa0',
63-
'').replace(',', '').replace('Fu', '')
64-
65-
except:
66-
price = soup.find(id="priceblock_ourprice_lbl").get_text(
67-
).strip()[:20].replace('₹', '').replace(' ', '').replace(
68-
'Price:',
69-
'').replace('\n',
70-
'').replace('\xa0',
71-
'').replace(',',
72-
'').replace('Fu', '')
55+
print("Object out of stock or removed")
56+
return
7357

74-
fixed_price = float(price)
58+
fixed_price = float(price.replace(",", ""))
7559
print(title)
7660
print(f'The current price is {fixed_price}')
7761
y_price = (input('Enter the price you wish to get the product at:'))
7862
your_price = y_price.replace(',', '')
7963
mail_id = input("Please enter your email id: ")
8064
password = input("Enter your app password here: ")
65+
phone_number = input("Please enter your phone number: ")
8166
print(
8267
"Thank You! You'll receive an email as soon as the price of product drops...!"
8368
)
8469
# print(price)
8570
if fixed_price <= float(your_price):
8671
mail_sending(mail_id, title, password)
72+
message_sending(phone_number, title)
8773
exit()
8874
else:
8975
pass

Amazon-Price-Tracker/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
requests==2.27.1
2+
bs4==0.0.1
3+
pywhatkit==5.4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://www.amazon.in/Apple-Original-MMTN2ZM-Lightning-Connector/dp/B01M1EEPOB/ref=sr_1_1?crid=XFITOYOGI999&keywords=airpods+apple&qid=1685422019&s=electronics&sprefix=airpods+appl%2Celectronics%2C458&sr=1-1

0 commit comments

Comments
 (0)