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

Commit eaa9d06

Browse files
committed
Fix code style issues with Black
1 parent 25a6afb commit eaa9d06

9 files changed

Lines changed: 287 additions & 143 deletions

File tree

projects/Chat Application/chatapp.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import threading
33

44
# Server configuration
5-
HOST = '127.0.0.1'
5+
HOST = "127.0.0.1"
66
PORT = 12345
77

88
# Create a server socket
@@ -12,6 +12,7 @@
1212

1313
clients = []
1414

15+
1516
def handle_client(client_socket, addr):
1617
with client_socket:
1718
print(f"New connection from {addr}")
@@ -24,29 +25,35 @@ def handle_client(client_socket, addr):
2425
if client != client_socket:
2526
client.send(data)
2627

28+
2729
def main():
2830
print(f"Server listening on {HOST}:{PORT}")
2931
while True:
3032
client_socket, addr = server_socket.accept()
31-
client_handler = threading.Thread(target=handle_client, args=(client_socket, addr))
33+
client_handler = threading.Thread(
34+
target=handle_client, args=(client_socket, addr)
35+
)
3236
client_handler.start()
3337

34-
if __name__ == '__main__':
38+
39+
if __name__ == "__main__":
3540
main()
3641

3742

3843
import socket
3944
import threading
4045

4146
# Client configuration
42-
HOST = '127.0.0.1'
47+
HOST = "127.0.0.1"
4348
PORT = 12345
4449

50+
4551
def receive_messages(client_socket):
4652
while True:
4753
data = client_socket.recv(1024).decode()
4854
print(data)
4955

56+
5057
def main():
5158
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5259
client_socket.connect((HOST, PORT))
@@ -58,5 +65,6 @@ def main():
5865
message = input()
5966
client_socket.send(message.encode())
6067

61-
if __name__ == '__main__':
68+
69+
if __name__ == "__main__":
6270
main()
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from flask import Flask
22

3+
34
def create_app():
45
app = Flask(__name__)
5-
app.secret_key = 'AhjcaD8aDAOfa8fnkadsh' #These are random letters used as the API key for this project.
6+
app.secret_key = "AhjcaD8aDAOfa8fnkadsh" # These are random letters used as the API key for this project.
67

78
from .views import views
89

9-
app.register_blueprint(views, url_prefix='/')
10-
11-
return app
10+
app.register_blueprint(views, url_prefix="/")
11+
12+
return app
Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,123 @@
11
from flask import Blueprint, render_template, request, flash
22
import duckdb
33

4-
views = Blueprint('views', __name__)
4+
views = Blueprint("views", __name__)
55
# Read data using DuckDB
66
db = duckdb.connect()
7-
db.execute("CREATE TEMPORARY TABLE attributes AS SELECT * FROM read_csv_auto('user_attributes.csv')")
8-
db.execute("CREATE TEMPORARY TABLE events AS SELECT * FROM read_csv_auto('user_events.csv')")
7+
db.execute(
8+
"CREATE TEMPORARY TABLE attributes AS SELECT * FROM read_csv_auto('user_attributes.csv')"
9+
)
10+
db.execute(
11+
"CREATE TEMPORARY TABLE events AS SELECT * FROM read_csv_auto('user_events.csv')"
12+
)
913

10-
@views.route('/')
14+
15+
@views.route("/")
1116
def home():
1217
return render_template("home.html")
1318

14-
@views.route('/query_output', methods=['GET', 'POST'])
19+
20+
@views.route("/query_output", methods=["GET", "POST"])
1521
def index():
16-
#Create a SQL query as a string to execute in DuckDB
17-
if request.method == 'POST':
22+
# Create a SQL query as a string to execute in DuckDB
23+
if request.method == "POST":
1824
print(request.form)
1925
attr = request.form
20-
age_from = attr.get('age_from')
21-
age_to = attr.get('age_to')
22-
gender_male = attr.get('male')
23-
gender_female = attr.get('female')
24-
input_location = attr.get('input_location')
25-
input_date = attr.get('input_date')
26-
input_sub_plan = attr.get('input_sub_plan')
27-
input_device = attr.get('input_device')
26+
age_from = attr.get("age_from")
27+
age_to = attr.get("age_to")
28+
gender_male = attr.get("male")
29+
gender_female = attr.get("female")
30+
input_location = attr.get("input_location")
31+
input_date = attr.get("input_date")
32+
input_sub_plan = attr.get("input_sub_plan")
33+
input_device = attr.get("input_device")
2834

29-
column_name = ['User ID', 'User Name', 'Age', 'Gender', 'Country', 'Sign-UP Date', 'Subscription Plan', 'Device', 'Login', 'Added To Cart', 'Purchased Item', 'Time of Event']
35+
column_name = [
36+
"User ID",
37+
"User Name",
38+
"Age",
39+
"Gender",
40+
"Country",
41+
"Sign-UP Date",
42+
"Subscription Plan",
43+
"Device",
44+
"Login",
45+
"Added To Cart",
46+
"Purchased Item",
47+
"Time of Event",
48+
]
3049
selected_queries = []
31-
query_select = ["SELECT a.*,e.* EXCLUDE user_ID FROM attributes a INNER JOIN events e ON a.user_ID = e.user_ID WHERE"]
50+
query_select = [
51+
"SELECT a.*,e.* EXCLUDE user_ID FROM attributes a INNER JOIN events e ON a.user_ID = e.user_ID WHERE"
52+
]
3253
parameters = []
3354
query_orderer = []
3455
# Check for the attributes which are selected and add them to the SQL query
35-
if attr.get('age')=='on':
56+
if attr.get("age") == "on":
3657
selected_queries.append(age_from)
3758
selected_queries.append(age_to)
38-
if age_from is not '' and age_to is not '':
59+
if age_from is not "" and age_to is not "":
3960
query_for_age = "(a.age BETWEEN ? AND ?) AND"
4061
query_select.append(query_for_age)
4162
parameters.append(age_from)
4263
parameters.append(age_to)
4364
else:
4465
query_for_age = "(a.age BETWEEN 18 AND 60) AND"
4566
query_select.append(query_for_age)
46-
47-
if attr.get('gender') == 'on':
48-
if gender_female == 'female' and gender_male == 'male':
67+
68+
if attr.get("gender") == "on":
69+
if gender_female == "female" and gender_male == "male":
4970
selected_queries.append(gender_female)
5071
query_for_gender_all = "a.gender == 'Female' OR a.gender == 'Male' AND"
5172
query_select.append(query_for_gender_all)
52-
elif gender_female == 'female':
73+
elif gender_female == "female":
5374
selected_queries.append(gender_female)
5475
query_for_female = "a.gender == 'Female' AND"
5576
query_select.append(query_for_female)
56-
elif gender_male == 'male':
77+
elif gender_male == "male":
5778
selected_queries.append(gender_male)
5879
query_for_male = "a.gender == 'Male' AND"
5980
query_select.append(query_for_male)
60-
61-
if attr.get('location') == 'on':
81+
82+
if attr.get("location") == "on":
6283
selected_queries.append(input_location)
6384
query_for_location = "UPPER(a.location) == UPPER(?) AND"
6485
query_select.append(query_for_location)
6586
parameters.append(input_location)
66-
67-
if attr.get('signup_date') == 'on':
87+
88+
if attr.get("signup_date") == "on":
6889
selected_queries.append(input_date)
6990
query_for_date = "(a.signup_date == ?) AND"
7091
parameters.append(input_date)
7192
query_select.append(query_for_date)
7293

73-
if attr.get('sub_plan') == 'on':
94+
if attr.get("sub_plan") == "on":
7495
selected_queries.append(input_sub_plan)
7596
query_for_plan = "(UPPER(a.sub_plan) == UPPER(?)) AND"
7697
parameters.append(input_sub_plan)
7798
query_select.append(query_for_plan)
7899

79-
if attr.get('device') == 'on':
100+
if attr.get("device") == "on":
80101
selected_queries.append(input_device)
81102
query_for_device = "(UPPER(a.device_type) == UPPER(?))"
82103
parameters.append(input_device)
83104
query_select.append(query_for_device)
84105

85106
query_selection = " ".join(query_select).rstrip("AND")
86107

87-
if attr.get('event_1') == 'on':
108+
if attr.get("event_1") == "on":
88109
selected_queries.append(login)
89110
query_for_login = " ORDER BY e.login,a.user_ID;"
90111
query_orderer.append(query_for_login)
91-
elif attr.get('event_2') == 'on':
112+
elif attr.get("event_2") == "on":
92113
selected_queries.append(added_to_cart)
93114
query_for_cart = " ORDER BY e.added_to_cart,a.user_ID;"
94115
query_orderer.append(query_for_cart)
95-
elif attr.get('event_3') == 'on':
116+
elif attr.get("event_3") == "on":
96117
selected_queries.append(purchased_item)
97118
query_for_purchased_item = " ORDER BY e.purchased_item,a.user_ID;"
98119
query_orderer.append(query_for_purchased_item)
99-
elif attr.get('time_stamp') == 'on':
120+
elif attr.get("time_stamp") == "on":
100121
selected_queries.append(time_stamp)
101122
query_for_time = " ORDER BY e.time_stamp,a.user_ID;"
102123
query_orderer.append(query_for_time)
@@ -105,7 +126,9 @@ def index():
105126
query_orderer.append(query_order)
106127

107128
query_selection = query_selection + " ".join(query_orderer)
108-
print(query_selection, parameters) # Logs out the SQL query before running (For Debugging purposes)
129+
print(
130+
query_selection, parameters
131+
) # Logs out the SQL query before running (For Debugging purposes)
109132

110133
data = db.execute(query_selection, parameters).fetchall()
111-
return render_template("table.html", data = data, header = column_name)
134+
return render_template("table.html", data=data, header=column_name)

projects/Data_Abstractor/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
app = create_app()
44

5-
if __name__ == '__main__':
6-
app.run(debug=True)
5+
if __name__ == "__main__":
6+
app.run(debug=True)

projects/Guess The Word/Guess_the_word.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import random
22

33
# List of words for the game
4-
word_list = ["python", "java", "javascript", "ruby", "php", "html", "css", "csharp", "angular", "golang", "c", "dotnet", "perl", "rust", "scala", "dart", "fortran", "cobol", "haskell"]
4+
word_list = [
5+
"python",
6+
"java",
7+
"javascript",
8+
"ruby",
9+
"php",
10+
"html",
11+
"css",
12+
"csharp",
13+
"angular",
14+
"golang",
15+
"c",
16+
"dotnet",
17+
"perl",
18+
"rust",
19+
"scala",
20+
"dart",
21+
"fortran",
22+
"cobol",
23+
"haskell",
24+
]
25+
526

627
# Function to choose a random word from the list
728
def choose_random_word(word_list):
829
return random.choice(word_list)
930

31+
1032
# Function to play the word guessing game
1133
def word_guessing_game():
1234
word_to_guess = choose_random_word(word_list)
@@ -32,7 +54,9 @@ def word_guessing_game():
3254

3355
if guess in word_to_guess:
3456
print("Correct guess!")
35-
remaining_letters = [letter if letter in guessed_letters else '_' for letter in word_to_guess]
57+
remaining_letters = [
58+
letter if letter in guessed_letters else "_" for letter in word_to_guess
59+
]
3660
print(" ".join(remaining_letters))
3761
if "_" not in remaining_letters:
3862
print("Congratulations! You've guessed the word:", word_to_guess)
@@ -46,5 +70,6 @@ def word_guessing_game():
4670
if attempts == 0:
4771
print("You've run out of attempts. The word was:", word_to_guess)
4872

73+
4974
# Start the game
5075
word_guessing_game()

projects/Loan Calculator/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def main():
2020

2121
# Get user input
2222
principal = floatValidation("Enter the loan amount: $")
23-
annual_interest_rate = floatValidation("Enter the annual interest rate (as a percentage): ")
23+
annual_interest_rate = floatValidation(
24+
"Enter the annual interest rate (as a percentage): "
25+
)
2426
months = intValidtaion("Enter the loan term (in months): ")
2527

2628
# Calculate monthly payment
@@ -36,16 +38,18 @@ def floatValidation(question):
3638
value = float(input(question))
3739
return value
3840
except ValueError:
39-
print('Input should be a valid number')
41+
print("Input should be a valid number")
4042
continue
4143

44+
4245
def intValidtaion(question):
4346
while True:
4447
try:
4548
value = int(input(question))
4649
return value
4750
except ValueError:
48-
print('Input should be a valid number')
51+
print("Input should be a valid number")
52+
4953

5054
if __name__ == "__main__":
5155
main()

0 commit comments

Comments
 (0)