Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Dec 28, 2023
1 parent 25a6afb commit eaa9d06
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 143 deletions.
18 changes: 13 additions & 5 deletions projects/Chat Application/chatapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import threading

# Server configuration
HOST = '127.0.0.1'
HOST = "127.0.0.1"
PORT = 12345

# Create a server socket
Expand All @@ -12,6 +12,7 @@

clients = []


def handle_client(client_socket, addr):
with client_socket:
print(f"New connection from {addr}")
Expand All @@ -24,29 +25,35 @@ def handle_client(client_socket, addr):
if client != client_socket:
client.send(data)


def main():
print(f"Server listening on {HOST}:{PORT}")
while True:
client_socket, addr = server_socket.accept()
client_handler = threading.Thread(target=handle_client, args=(client_socket, addr))
client_handler = threading.Thread(
target=handle_client, args=(client_socket, addr)
)
client_handler.start()

if __name__ == '__main__':

if __name__ == "__main__":
main()


import socket
import threading

# Client configuration
HOST = '127.0.0.1'
HOST = "127.0.0.1"
PORT = 12345


def receive_messages(client_socket):
while True:
data = client_socket.recv(1024).decode()
print(data)


def main():
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((HOST, PORT))
Expand All @@ -58,5 +65,6 @@ def main():
message = input()
client_socket.send(message.encode())

if __name__ == '__main__':

if __name__ == "__main__":
main()
9 changes: 5 additions & 4 deletions projects/Data_Abstractor/Website/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from flask import Flask


def create_app():
app = Flask(__name__)
app.secret_key = 'AhjcaD8aDAOfa8fnkadsh' #These are random letters used as the API key for this project.
app.secret_key = "AhjcaD8aDAOfa8fnkadsh" # These are random letters used as the API key for this project.

from .views import views

app.register_blueprint(views, url_prefix='/')
return app
app.register_blueprint(views, url_prefix="/")

return app
95 changes: 59 additions & 36 deletions projects/Data_Abstractor/Website/views.py
Original file line number Diff line number Diff line change
@@ -1,102 +1,123 @@
from flask import Blueprint, render_template, request, flash
import duckdb

views = Blueprint('views', __name__)
views = Blueprint("views", __name__)
# Read data using DuckDB
db = duckdb.connect()
db.execute("CREATE TEMPORARY TABLE attributes AS SELECT * FROM read_csv_auto('user_attributes.csv')")
db.execute("CREATE TEMPORARY TABLE events AS SELECT * FROM read_csv_auto('user_events.csv')")
db.execute(
"CREATE TEMPORARY TABLE attributes AS SELECT * FROM read_csv_auto('user_attributes.csv')"
)
db.execute(
"CREATE TEMPORARY TABLE events AS SELECT * FROM read_csv_auto('user_events.csv')"
)

@views.route('/')

@views.route("/")
def home():
return render_template("home.html")

@views.route('/query_output', methods=['GET', 'POST'])

@views.route("/query_output", methods=["GET", "POST"])
def index():
#Create a SQL query as a string to execute in DuckDB
if request.method == 'POST':
# Create a SQL query as a string to execute in DuckDB
if request.method == "POST":
print(request.form)
attr = request.form
age_from = attr.get('age_from')
age_to = attr.get('age_to')
gender_male = attr.get('male')
gender_female = attr.get('female')
input_location = attr.get('input_location')
input_date = attr.get('input_date')
input_sub_plan = attr.get('input_sub_plan')
input_device = attr.get('input_device')
age_from = attr.get("age_from")
age_to = attr.get("age_to")
gender_male = attr.get("male")
gender_female = attr.get("female")
input_location = attr.get("input_location")
input_date = attr.get("input_date")
input_sub_plan = attr.get("input_sub_plan")
input_device = attr.get("input_device")

column_name = ['User ID', 'User Name', 'Age', 'Gender', 'Country', 'Sign-UP Date', 'Subscription Plan', 'Device', 'Login', 'Added To Cart', 'Purchased Item', 'Time of Event']
column_name = [
"User ID",
"User Name",
"Age",
"Gender",
"Country",
"Sign-UP Date",
"Subscription Plan",
"Device",
"Login",
"Added To Cart",
"Purchased Item",
"Time of Event",
]
selected_queries = []
query_select = ["SELECT a.*,e.* EXCLUDE user_ID FROM attributes a INNER JOIN events e ON a.user_ID = e.user_ID WHERE"]
query_select = [
"SELECT a.*,e.* EXCLUDE user_ID FROM attributes a INNER JOIN events e ON a.user_ID = e.user_ID WHERE"
]
parameters = []
query_orderer = []
# Check for the attributes which are selected and add them to the SQL query
if attr.get('age')=='on':
if attr.get("age") == "on":
selected_queries.append(age_from)
selected_queries.append(age_to)
if age_from is not '' and age_to is not '':
if age_from is not "" and age_to is not "":
query_for_age = "(a.age BETWEEN ? AND ?) AND"
query_select.append(query_for_age)
parameters.append(age_from)
parameters.append(age_to)
else:
query_for_age = "(a.age BETWEEN 18 AND 60) AND"
query_select.append(query_for_age)
if attr.get('gender') == 'on':
if gender_female == 'female' and gender_male == 'male':

if attr.get("gender") == "on":
if gender_female == "female" and gender_male == "male":
selected_queries.append(gender_female)
query_for_gender_all = "a.gender == 'Female' OR a.gender == 'Male' AND"
query_select.append(query_for_gender_all)
elif gender_female == 'female':
elif gender_female == "female":
selected_queries.append(gender_female)
query_for_female = "a.gender == 'Female' AND"
query_select.append(query_for_female)
elif gender_male == 'male':
elif gender_male == "male":
selected_queries.append(gender_male)
query_for_male = "a.gender == 'Male' AND"
query_select.append(query_for_male)
if attr.get('location') == 'on':

if attr.get("location") == "on":
selected_queries.append(input_location)
query_for_location = "UPPER(a.location) == UPPER(?) AND"
query_select.append(query_for_location)
parameters.append(input_location)
if attr.get('signup_date') == 'on':

if attr.get("signup_date") == "on":
selected_queries.append(input_date)
query_for_date = "(a.signup_date == ?) AND"
parameters.append(input_date)
query_select.append(query_for_date)

if attr.get('sub_plan') == 'on':
if attr.get("sub_plan") == "on":
selected_queries.append(input_sub_plan)
query_for_plan = "(UPPER(a.sub_plan) == UPPER(?)) AND"
parameters.append(input_sub_plan)
query_select.append(query_for_plan)

if attr.get('device') == 'on':
if attr.get("device") == "on":
selected_queries.append(input_device)
query_for_device = "(UPPER(a.device_type) == UPPER(?))"
parameters.append(input_device)
query_select.append(query_for_device)

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

if attr.get('event_1') == 'on':
if attr.get("event_1") == "on":
selected_queries.append(login)
query_for_login = " ORDER BY e.login,a.user_ID;"
query_orderer.append(query_for_login)
elif attr.get('event_2') == 'on':
elif attr.get("event_2") == "on":
selected_queries.append(added_to_cart)
query_for_cart = " ORDER BY e.added_to_cart,a.user_ID;"
query_orderer.append(query_for_cart)
elif attr.get('event_3') == 'on':
elif attr.get("event_3") == "on":
selected_queries.append(purchased_item)
query_for_purchased_item = " ORDER BY e.purchased_item,a.user_ID;"
query_orderer.append(query_for_purchased_item)
elif attr.get('time_stamp') == 'on':
elif attr.get("time_stamp") == "on":
selected_queries.append(time_stamp)
query_for_time = " ORDER BY e.time_stamp,a.user_ID;"
query_orderer.append(query_for_time)
Expand All @@ -105,7 +126,9 @@ def index():
query_orderer.append(query_order)

query_selection = query_selection + " ".join(query_orderer)
print(query_selection, parameters) # Logs out the SQL query before running (For Debugging purposes)
print(
query_selection, parameters
) # Logs out the SQL query before running (For Debugging purposes)

data = db.execute(query_selection, parameters).fetchall()
return render_template("table.html", data = data, header = column_name)
return render_template("table.html", data=data, header=column_name)
4 changes: 2 additions & 2 deletions projects/Data_Abstractor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

app = create_app()

if __name__ == '__main__':
app.run(debug=True)
if __name__ == "__main__":
app.run(debug=True)
29 changes: 27 additions & 2 deletions projects/Guess The Word/Guess_the_word.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import random

# List of words for the game
word_list = ["python", "java", "javascript", "ruby", "php", "html", "css", "csharp", "angular", "golang", "c", "dotnet", "perl", "rust", "scala", "dart", "fortran", "cobol", "haskell"]
word_list = [
"python",
"java",
"javascript",
"ruby",
"php",
"html",
"css",
"csharp",
"angular",
"golang",
"c",
"dotnet",
"perl",
"rust",
"scala",
"dart",
"fortran",
"cobol",
"haskell",
]


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


# Function to play the word guessing game
def word_guessing_game():
word_to_guess = choose_random_word(word_list)
Expand All @@ -32,7 +54,9 @@ def word_guessing_game():

if guess in word_to_guess:
print("Correct guess!")
remaining_letters = [letter if letter in guessed_letters else '_' for letter in word_to_guess]
remaining_letters = [
letter if letter in guessed_letters else "_" for letter in word_to_guess
]
print(" ".join(remaining_letters))
if "_" not in remaining_letters:
print("Congratulations! You've guessed the word:", word_to_guess)
Expand All @@ -46,5 +70,6 @@ def word_guessing_game():
if attempts == 0:
print("You've run out of attempts. The word was:", word_to_guess)


# Start the game
word_guessing_game()
10 changes: 7 additions & 3 deletions projects/Loan Calculator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def main():

# Get user input
principal = floatValidation("Enter the loan amount: $")
annual_interest_rate = floatValidation("Enter the annual interest rate (as a percentage): ")
annual_interest_rate = floatValidation(
"Enter the annual interest rate (as a percentage): "
)
months = intValidtaion("Enter the loan term (in months): ")

# Calculate monthly payment
Expand All @@ -36,16 +38,18 @@ def floatValidation(question):
value = float(input(question))
return value
except ValueError:
print('Input should be a valid number')
print("Input should be a valid number")
continue


def intValidtaion(question):
while True:
try:
value = int(input(question))
return value
except ValueError:
print('Input should be a valid number')
print("Input should be a valid number")


if __name__ == "__main__":
main()
Loading

0 comments on commit eaa9d06

Please sign in to comment.