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

Commit afac058

Browse files
Merge branch 'main' into main
2 parents 3c1064a + af783b5 commit afac058

107 files changed

Lines changed: 7682 additions & 515 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: 202 additions & 109 deletions
Large diffs are not rendered by default.

projects/AWS_s3_upload/main.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import boto3
22
from botocore.exceptions import NoCredentialsError
33

4-
ACCESS_KEY = ''
5-
SECRET_KEY = ''
6-
LOCAL_FILE = 'local_file_name'
7-
BUCKET_NAME = 'bucket_name'
8-
S3_FILE_NAME = 'file_name_on_s3'
4+
ACCESS_KEY = ""
5+
SECRET_KEY = ""
6+
LOCAL_FILE = "local_file_name"
7+
BUCKET_NAME = "bucket_name"
8+
S3_FILE_NAME = "file_name_on_s3"
9+
910

1011
def upload_to_s3(local_file, bucket, s3_file):
11-
## This function is responsible for uploading the file into the S3 bucket using the specified credentials.
12-
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
13-
aws_secret_access_key=SECRET_KEY)
12+
## This function is responsible for uploading the file into the S3 bucket using the specified credentials.
13+
s3 = boto3.client(
14+
"s3", aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY
15+
)
1416
try:
1517
s3.upload_file(local_file, bucket, s3_file)
1618
print("Upload Successful")
@@ -23,4 +25,4 @@ def upload_to_s3(local_file, bucket, s3_file):
2325
return False
2426

2527

26-
result = upload_to_s3(LOCAL_FILE, BUCKET_NAME, S3_FILE_NAME)
28+
result = upload_to_s3(LOCAL_FILE, BUCKET_NAME, S3_FILE_NAME)
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)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import tkinter as tk
2+
from math import sin, cos, pi
3+
4+
5+
def update_clock():
6+
current_time = time_var.get()
7+
seconds = current_time % 60
8+
minutes = (current_time // 60) % 60
9+
hours = (current_time // 3600) % 12
10+
11+
seconds_angle = 90 - seconds * 6
12+
minutes_angle = 90 - minutes * 6 - seconds * 0.1
13+
hours_angle = 90 - (hours * 30 + minutes * 0.5)
14+
15+
canvas.delete("all")
16+
17+
canvas.create_oval(50, 50, 250, 250)
18+
19+
for i in range(1, 13):
20+
angle = 90 - i * 30
21+
x = 150 + 85 * cos(angle * (pi / 180))
22+
y = 150 - 85 * sin(angle * (pi / 180))
23+
canvas.create_text(x, y, text=str(i), font=("Arial", 12, "bold"))
24+
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)
28+
29+
time_var.set(current_time + 1)
30+
31+
root.after(1000, update_clock)
32+
33+
34+
def draw_hand(x, y, angle, length, width):
35+
radian_angle = angle * (pi / 180)
36+
end_x = x + length * cos(radian_angle)
37+
end_y = y - length * sin(radian_angle)
38+
canvas.create_line(x, y, end_x, end_y, width=width)
39+
40+
41+
root = tk.Tk()
42+
root.title("Analog Clock")
43+
44+
canvas = tk.Canvas(root, width=350, height=350)
45+
canvas.pack()
46+
47+
time_var = tk.IntVar()
48+
time_var.set(10 * 3600)
49+
50+
update_clock()
51+
root.mainloop()

projects/AnalogClock/analog_clock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import tkinter as tk
2+
from math import sin, cos, pi
3+
4+
def update_clock():
5+
current_time = time_var.get()
6+
seconds = current_time % 60
7+
minutes = (current_time // 60) % 60
8+
hours = (current_time // 3600) % 12
9+
10+
# Calculation of the angles for the clock hands (in degrees)
11+
seconds_angle = 90 - seconds * 6
12+
minutes_angle = 90 - minutes * 6 - seconds * 0.1
13+
hours_angle = 90 - (hours * 30 + minutes * 0.5)
14+
15+
canvas.delete("all") #Deletes all previous drawings
16+
17+
canvas.create_oval(50, 50, 250, 250) #To draw clock face
18+
19+
for i in range(1, 13): # Drawing clock numbers
20+
angle = 90 - i * 30 #Calculation of the angle for each number
21+
x = 150 + 85 * cos(angle * (pi / 180))
22+
y = 150 - 85 * sin(angle * (pi / 180))
23+
canvas.create_text(x, y, text=str(i), font=("Arial", 12, "bold"))
24+
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)
28+
29+
time_var.set(current_time + 1) # Updating the time
30+
31+
root.after(1000, update_clock) # Updating the clock every 1000ms (1 second)
32+
33+
def draw_hand(x, y, angle, length, width):
34+
radian_angle = angle * (pi / 180)
35+
end_x = x + length * cos(radian_angle)
36+
end_y = y - length * sin(radian_angle)
37+
canvas.create_line(x, y, end_x, end_y, width=width)
38+
39+
root = tk.Tk() # Creating the main window
40+
root.title("Analog Clock")
41+
42+
canvas = tk.Canvas(root, width=350, height=350)
43+
canvas.pack()
44+
45+
time_var = tk.IntVar()
46+
time_var.set(10 * 3600)
47+
48+
update_clock() # Starting the clock update function
49+
root.mainloop() # Running the Tkinter main loop
50+

projects/Battleship/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Py-Battleship
2+
3+
[![License](https://img.shields.io/static/v1?label=License&message=GPL-3-0&color=blue&?style=plastic&logo=appveyor)](https://opensource.org/license/GPL-3-0)
4+
5+
## Table Of Content
6+
7+
- [Description](#description)
8+
- [Installation](#installation)
9+
- [Usage](#usage)
10+
- [GitHub](#github)
11+
- [License](#license)
12+
13+
14+
![GitHub repo size](https://img.shields.io/github/repo-size/robertlent/py_battleship?style=plastic)
15+
16+
![GitHub top language](https://img.shields.io/github/languages/top/robertlent/py_battleship?style=plastic)
17+
18+
19+
20+
## Description
21+
22+
Battleship is a Python command line game.
23+
24+
The player can choose the size of the grid, from 5x5 up to 15x15, and the ship will be randomly placed in that grid. The size of the grid also determines the number of turns the user gets, from 5 to 15.
25+
26+
The game handles incorrect entries and can be replayed repeatedly.
27+
28+
29+
30+
## Installation
31+
32+
Download main.py, change to the directory where you downloaded the file and run it using `python3 main.py`
33+
34+
Py-Battleship is built with the following tools and libraries: <ul><li>Python</li></ul>
35+
36+
37+
38+
## Usage
39+
40+
1. Enter 'yes' or 'y' to start a new game
41+
- Any input besides those two and 'no' or 'n' will be ignored
42+
2. You will be prompted to choose a number from 5 to 15, which sets the game board size and number of guesses to that number
43+
3. You will be prompted to choose a row number and then to choose a column number
44+
- If either guess is less than 5 or more than the previously provided maximum, you will be prompted to choose a valid selection
45+
- If you enter a row or column that you already guessed, you will be told such and you will have used a turn
46+
4. The game continues until you either make a correct guess or run out of guesses
47+
5. You will then be asked if you want to start a new game
48+
49+
50+
## GitHub
51+
52+
<a href="https://github.com/robertlent"><strong>robertlent</a></strong>
53+
54+
55+
## License
56+
57+
[![License](https://img.shields.io/static/v1?label=Licence&message=GPL-3-0&color=blue)](https://opensource.org/license/GPL-3-0)
58+
59+

projects/Battleship/main.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import os
2+
from random import randint
3+
4+
board = []
5+
size = 5
6+
7+
8+
def new_game():
9+
global size
10+
os.system("cls" if os.name == "nt" else "clear")
11+
answer = input("Do you want to start a new game of Battleship? ").lower()
12+
13+
if answer not in ["yes", "y", "no", "n"]:
14+
new_game()
15+
else:
16+
if answer == "yes" or answer == "y":
17+
while True:
18+
try:
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+
)
25+
if size not in range(5, 16):
26+
raise ValueError()
27+
except ValueError:
28+
print("You did not enter a number!")
29+
continue
30+
else:
31+
break
32+
33+
# Creates the playing board's size, based on the size chosen by the player.
34+
for x in range(0, size):
35+
board.append(["O"] * size)
36+
game()
37+
elif answer == "no" or answer == "n":
38+
os.system("cls" if os.name == "nt" else "clear")
39+
print("Thank you for playing!\n")
40+
input("Press the 'Enter' key to exit the game.")
41+
os.system("cls" if os.name == "nt" else "clear")
42+
quit()
43+
44+
45+
def print_board(board):
46+
for row in board:
47+
print(" ".join(row))
48+
49+
50+
def random_row(board):
51+
return randint(0, len(board) - 1)
52+
53+
54+
def random_col(board):
55+
return randint(0, len(board[0]) - 1)
56+
57+
58+
def game():
59+
global board
60+
os.system("cls" if os.name == "nt" else "clear")
61+
print(
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+
)
65+
66+
# Randomly places Battleship
67+
ship_row = random_row(board)
68+
ship_col = random_col(board)
69+
70+
# The next two lines are for debugging purposes. They display the position of the battleship.
71+
# print(ship_row + 1)
72+
# print(ship_col + 1)
73+
74+
print_board(board)
75+
76+
# Give the user the amount of turns they chose, between 5 and 10.
77+
for turn in range(size):
78+
print("\nTurn", turn + 1, "of", size, "\n")
79+
80+
# Check if Guess Row and Column are numbers before continuing
81+
while True:
82+
try:
83+
guess_row = int(input("Guess Row: ")) - 1
84+
if guess_row not in range(0, size):
85+
raise ValueError()
86+
except ValueError:
87+
print("Enter a valid selection!")
88+
continue
89+
else:
90+
break
91+
92+
while True:
93+
try:
94+
guess_col = int(input("Guess Column: ")) - 1
95+
if guess_col not in range(0, size):
96+
raise ValueError()
97+
except ValueError:
98+
print("Enter a valid selection!")
99+
continue
100+
else:
101+
break
102+
103+
# Checks if Player wins
104+
if guess_row == ship_row and guess_col == ship_col:
105+
os.system("cls" if os.name == "nt" else "clear")
106+
input(
107+
"Congratulations! You sank my battleship!\n\nPress enter to continue."
108+
)
109+
board = []
110+
new_game()
111+
break
112+
else: # Guesses are outside of playing field
113+
if (guess_row > size or guess_row < 0) or (
114+
guess_col > size or guess_col < 0
115+
):
116+
print("Oops, that's not even in the ocean.")
117+
# Player previously guessed their current guesses
118+
elif board[guess_row][guess_col] == "X":
119+
os.system("cls" if os.name == "nt" else "clear")
120+
print("You guessed that one already. Good job, you wasted a turn.\n")
121+
print_board(board)
122+
else: # User misses
123+
os.system("cls" if os.name == "nt" else "clear")
124+
print("Miss!\n")
125+
board[guess_row][guess_col] = "X"
126+
print_board(board)
127+
else:
128+
input("\nGame Over\n\nPress enter to continue.")
129+
board = []
130+
new_game()
131+
132+
133+
new_game()
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.

0 commit comments

Comments
 (0)