Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit e731e7a

Browse files
authored
Merge branch 'Mrinank-Bhowmick:main' into johnrtitor
2 parents 0e8a349 + 4d04c7f commit e731e7a

93 files changed

Lines changed: 9504 additions & 851 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 192 additions & 106 deletions
Large diffs are not rendered by default.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
4+
5+
def check_amazon_availability(product_url):
6+
headers = {
7+
"User-Agent": "Your User Agent Here" # You can set a user agent string here
8+
}
9+
10+
try:
11+
response = requests.get(product_url, headers=headers)
12+
response.raise_for_status()
13+
14+
soup = BeautifulSoup(response.content, "html.parser")
15+
16+
title = soup.find("span", {"id": "productTitle"}).get_text(strip=True)
17+
availability = soup.find(
18+
"span", {"class": "a-declarative", "data-asin": True}
19+
).get_text(strip=True)
20+
21+
if "out of stock" in availability.lower():
22+
print(f"{title} is currently out of stock on Amazon.")
23+
else:
24+
print(f"{title} is available on Amazon.")
25+
26+
except requests.exceptions.RequestException as e:
27+
print("Error:", e)
28+
29+
30+
if __name__ == "__main__":
31+
product_url = "YOUR_PRODUCT_URL_HERE"
32+
check_amazon_availability(product_url)

projects/Analog Clock/analog_clock.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import tkinter as tk
22
from math import sin, cos, pi
33

4+
45
def update_clock():
56
current_time = time_var.get()
67
seconds = current_time % 60
78
minutes = (current_time // 60) % 60
89
hours = (current_time // 3600) % 12
9-
10+
1011
seconds_angle = 90 - seconds * 6
1112
minutes_angle = 90 - minutes * 6 - seconds * 0.1
1213
hours_angle = 90 - (hours * 30 + minutes * 0.5)
@@ -16,34 +17,35 @@ def update_clock():
1617
canvas.create_oval(50, 50, 250, 250)
1718

1819
for i in range(1, 13):
19-
angle = 90 - i * 30
20+
angle = 90 - i * 30
2021
x = 150 + 85 * cos(angle * (pi / 180))
2122
y = 150 - 85 * sin(angle * (pi / 180))
2223
canvas.create_text(x, y, text=str(i), font=("Arial", 12, "bold"))
2324

24-
draw_hand(150, 150, seconds_angle, 80, 1)
25-
draw_hand(150, 150, minutes_angle, 70, 2)
26-
draw_hand(150, 150, hours_angle, 50, 4)
25+
draw_hand(150, 150, seconds_angle, 80, 1)
26+
draw_hand(150, 150, minutes_angle, 70, 2)
27+
draw_hand(150, 150, hours_angle, 50, 4)
2728

2829
time_var.set(current_time + 1)
29-
30+
3031
root.after(1000, update_clock)
3132

33+
3234
def draw_hand(x, y, angle, length, width):
3335
radian_angle = angle * (pi / 180)
3436
end_x = x + length * cos(radian_angle)
35-
end_y = y - length * sin(radian_angle)
37+
end_y = y - length * sin(radian_angle)
3638
canvas.create_line(x, y, end_x, end_y, width=width)
3739

40+
3841
root = tk.Tk()
3942
root.title("Analog Clock")
4043

4144
canvas = tk.Canvas(root, width=350, height=350)
4245
canvas.pack()
4346

4447
time_var = tk.IntVar()
45-
time_var.set(10 * 3600)
48+
time_var.set(10 * 3600)
4649

4750
update_clock()
4851
root.mainloop()
49-

projects/Battleship/main.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77

88
def new_game():
99
global size
10-
os.system('cls' if os.name == 'nt' else 'clear')
10+
os.system("cls" if os.name == "nt" else "clear")
1111
answer = input("Do you want to start a new game of Battleship? ").lower()
1212

13-
if answer not in ['yes', 'y', 'no', 'n']:
13+
if answer not in ["yes", "y", "no", "n"]:
1414
new_game()
1515
else:
16-
if answer == 'yes' or answer == 'y':
16+
if answer == "yes" or answer == "y":
1717
while True:
1818
try:
19-
os.system('cls' if os.name == 'nt' else 'clear')
20-
size = int(input(
21-
"Enter a number between 5 and 15.\n\nThis will determine how big the playing board is and how many turns you have to find the Battleship. (5 rows, 5 columns, 5 turns, etc.): "))
19+
os.system("cls" if os.name == "nt" else "clear")
20+
size = int(
21+
input(
22+
"Enter a number between 5 and 15.\n\nThis will determine how big the playing board is and how many turns you have to find the Battleship. (5 rows, 5 columns, 5 turns, etc.): "
23+
)
24+
)
2225
if size not in range(5, 16):
2326
raise ValueError()
2427
except ValueError:
@@ -31,11 +34,11 @@ def new_game():
3134
for x in range(0, size):
3235
board.append(["O"] * size)
3336
game()
34-
elif answer == 'no' or answer == 'n':
35-
os.system('cls' if os.name == 'nt' else 'clear')
37+
elif answer == "no" or answer == "n":
38+
os.system("cls" if os.name == "nt" else "clear")
3639
print("Thank you for playing!\n")
3740
input("Press the 'Enter' key to exit the game.")
38-
os.system('cls' if os.name == 'nt' else 'clear')
41+
os.system("cls" if os.name == "nt" else "clear")
3942
quit()
4043

4144

@@ -54,10 +57,11 @@ def random_col(board):
5457

5558
def game():
5659
global board
57-
os.system('cls' if os.name == 'nt' else 'clear')
60+
os.system("cls" if os.name == "nt" else "clear")
5861
print(
59-
"Welcome to Battleship.\n\nA ship, one cell long, has been randomly placed on the below %dx%d grid.\nYou have %d turns to find it.\n" % (
60-
size, size, size))
62+
"Welcome to Battleship.\n\nA ship, one cell long, has been randomly placed on the below %dx%d grid.\nYou have %d turns to find it.\n"
63+
% (size, size, size)
64+
)
6165

6266
# Randomly places Battleship
6367
ship_row = random_row(board)
@@ -98,21 +102,25 @@ def game():
98102

99103
# Checks if Player wins
100104
if guess_row == ship_row and guess_col == ship_col:
101-
os.system('cls' if os.name == 'nt' else 'clear')
102-
input("Congratulations! You sank my battleship!\n\nPress enter to continue.")
105+
os.system("cls" if os.name == "nt" else "clear")
106+
input(
107+
"Congratulations! You sank my battleship!\n\nPress enter to continue."
108+
)
103109
board = []
104110
new_game()
105111
break
106112
else: # Guesses are outside of playing field
107-
if (guess_row > size or guess_row < 0) or (guess_col > size or guess_col < 0):
113+
if (guess_row > size or guess_row < 0) or (
114+
guess_col > size or guess_col < 0
115+
):
108116
print("Oops, that's not even in the ocean.")
109117
# Player previously guessed their current guesses
110118
elif board[guess_row][guess_col] == "X":
111-
os.system('cls' if os.name == 'nt' else 'clear')
119+
os.system("cls" if os.name == "nt" else "clear")
112120
print("You guessed that one already. Good job, you wasted a turn.\n")
113121
print_board(board)
114122
else: # User misses
115-
os.system('cls' if os.name == 'nt' else 'clear')
123+
os.system("cls" if os.name == "nt" else "clear")
116124
print("Miss!\n")
117125
board[guess_row][guess_col] = "X"
118126
print_board(board)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
This project is designed to extract large datasets of book information from Goodreads based on user ratings. It includes a Python script, main.py, which scrapes book data from Goodreads pages and saves it to an Excel file.
2+
3+
Provide Input:
4+
Enter the exact link to the book list on the Goodreads website.
5+
Specify the minimum rating threshold for the books you want to extract.
6+
Input the total number of web pages in your book list.
7+
8+
Data Extraction:
9+
The script will start extracting book data based on the specified criteria.
10+
It will create an Excel file named books.xlsx in the project directory.
11+
The extracted book information will be saved in this file.
12+
Excel File:
13+
14+
You can find the extracted book data in the books.xlsx file in the project folder.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from bs4 import BeautifulSoup as bs
2+
import requests
3+
from openpyxl import Workbook
4+
5+
title = []
6+
author = []
7+
rating = []
8+
9+
wb = Workbook()
10+
ws = wb.active
11+
ws["A1"].value = "Title"
12+
ws["B1"].value = "Author"
13+
ws["C1"].value = "Ratings"
14+
15+
16+
def link(url, pages):
17+
for i in range(1, pages + 1):
18+
title = []
19+
author = []
20+
rating = []
21+
try:
22+
response = requests.get(f"{url}?page={i}")
23+
except:
24+
print("Tracked All The Pages! ")
25+
break
26+
27+
html = response.text
28+
data = bs(html, "html.parser")
29+
30+
titles = data.find_all("span", itemprop="name", role="heading")
31+
for j in titles:
32+
title.append(j.string)
33+
34+
authors = data.find_all("a", class_="authorName")
35+
for j in authors:
36+
author.append(j.string)
37+
38+
ratings = data.find_all("span", class_="minirating")
39+
for j in ratings:
40+
rating.append(j.get_text().replace(" ", "")[0:4])
41+
42+
for j in range(len(title)):
43+
try:
44+
rating_float = float(rating[j].strip())
45+
if rating_float >= rating_threshold:
46+
ws.append([title[j], author[j], rating_float])
47+
except ValueError:
48+
print(f"Skipping item with invalid rating: '{rating[j]}'")
49+
50+
print(f"Successfully extracted page {i}")
51+
52+
53+
if __name__ == "__main__":
54+
try:
55+
url = input(
56+
"Enter the exact link of the book list from the goodreads website: "
57+
)
58+
except:
59+
print("Enter a Valid Link! ")
60+
61+
while True:
62+
try:
63+
rating_threshold = float(
64+
input("Enter the minimum ratings you want to extract: ")
65+
)
66+
break
67+
except ValueError:
68+
print("Enter a valid number")
69+
70+
while True:
71+
try:
72+
pages = int(input("Enter the total number of Web Pages in Your List: "))
73+
break
74+
except ValueError:
75+
print("Please input a numerical value! ")
76+
77+
print("Extracting the Data..........................")
78+
79+
link(url, pages)
80+
81+
wb.save("books.xlsx")
82+
print("Excel File Saved Succesfully, Check Your Folder For The File")

projects/Calculate Age/calculate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
from calendar import isleap
33

4+
45
# judge the leap year
56
def judge_leap_year(year):
67
if isleap(year):
@@ -34,7 +35,7 @@ def month_days(month, leap_year):
3435

3536
# calculate the days
3637
for y in range(begin_year, end_year):
37-
if (judge_leap_year(y)):
38+
if judge_leap_year(y):
3839
day = day + 366
3940
else:
4041
day = day + 365

projects/Calculator/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def division():
4848

4949

5050
def average():
51-
"""This function takes space seperated number series and then convert it to a list.
51+
"""This function takes space seperated number series and then convert it to a list.
5252
Then calculates the average of that list of numbers."""
5353

5454
nums = list(map(int, input("Enter all numbers seperated by space: ").split()))

projects/Coin Flip/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Coin Flip
2+
3+
This is a Python program used to simulate a coin toss, in which a user is asked to pick a side (heads or tails), and the program selects a result at random between the two options. If the user's choice matches the result, they win the coin toss.
4+
5+
### How to Play
6+
7+
1. When the program is initiated, you will be prompted to choose either "heads" or "tails".
8+
2. The program will then determine the winning result by random chance, and display it.
9+
3. If your choice matches the result, you win the coin toss. If not, you'll receive a "OOF" message to indicate a loss.
10+
4. After the end of each round, you will be asked if you want to play again. Type "yes" to continue playing or "no" to exit the program.
11+
12+
Enjoy!

0 commit comments

Comments
 (0)