diff --git a/projects/Chat Application/chatapp.py b/projects/Chat Application/chatapp.py index 53cdc288c..7045aa7e5 100644 --- a/projects/Chat Application/chatapp.py +++ b/projects/Chat Application/chatapp.py @@ -2,7 +2,7 @@ import threading # Server configuration -HOST = '127.0.0.1' +HOST = "127.0.0.1" PORT = 12345 # Create a server socket @@ -12,6 +12,7 @@ clients = [] + def handle_client(client_socket, addr): with client_socket: print(f"New connection from {addr}") @@ -24,14 +25,18 @@ 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() @@ -39,14 +44,16 @@ def main(): 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)) @@ -58,5 +65,6 @@ def main(): message = input() client_socket.send(message.encode()) -if __name__ == '__main__': + +if __name__ == "__main__": main() diff --git a/projects/Data_Abstractor/Website/__init__.py b/projects/Data_Abstractor/Website/__init__.py index fb4a8c3f1..a1dedf1ba 100644 --- a/projects/Data_Abstractor/Website/__init__.py +++ b/projects/Data_Abstractor/Website/__init__.py @@ -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 \ No newline at end of file + app.register_blueprint(views, url_prefix="/") + + return app diff --git a/projects/Data_Abstractor/Website/views.py b/projects/Data_Abstractor/Website/views.py index e0796a386..39c182105 100644 --- a/projects/Data_Abstractor/Website/views.py +++ b/projects/Data_Abstractor/Website/views.py @@ -1,41 +1,62 @@ 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) @@ -43,40 +64,40 @@ def index(): 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) @@ -84,19 +105,19 @@ def index(): 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) @@ -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) \ No newline at end of file + return render_template("table.html", data=data, header=column_name) diff --git a/projects/Data_Abstractor/main.py b/projects/Data_Abstractor/main.py index 020b9bd98..c83794642 100644 --- a/projects/Data_Abstractor/main.py +++ b/projects/Data_Abstractor/main.py @@ -2,5 +2,5 @@ app = create_app() -if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file +if __name__ == "__main__": + app.run(debug=True) diff --git a/projects/Guess The Word/Guess_the_word.py b/projects/Guess The Word/Guess_the_word.py index 67caa3cd1..db8836b90 100644 --- a/projects/Guess The Word/Guess_the_word.py +++ b/projects/Guess The Word/Guess_the_word.py @@ -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) @@ -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) @@ -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() diff --git a/projects/Loan Calculator/main.py b/projects/Loan Calculator/main.py index fee4ffc06..692da11cd 100644 --- a/projects/Loan Calculator/main.py +++ b/projects/Loan Calculator/main.py @@ -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 @@ -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() diff --git a/projects/Mineral Processing Technology-Image Analytics/code.py b/projects/Mineral Processing Technology-Image Analytics/code.py index 2de46850d..b8ec50722 100644 --- a/projects/Mineral Processing Technology-Image Analytics/code.py +++ b/projects/Mineral Processing Technology-Image Analytics/code.py @@ -1,6 +1,7 @@ import cv2 import os import numpy as np + # Input and output folders input_folder = "input" output_folder = "output" @@ -9,6 +10,7 @@ if not os.path.exists(output_folder): os.makedirs(output_folder) + # Function to process an image def process_image(filename): # Read the image @@ -38,15 +40,15 @@ def process_image(filename): area = cv2.contourArea(contour) # Calculate the major axis as the longest distance between any two points - #points = contour.squeeze() - #distances = [((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5 for p1 in points for p2 in points] - #major_axis = max(distances) + # points = contour.squeeze() + # distances = [((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5 for p1 in points for p2 in points] + # major_axis = max(distances) # Calculate the major axis points points = contour.squeeze() max_distance = 0 major_axis_points = None for i, p1 in enumerate(points): - for p2 in points[i + 1:]: + for p2 in points[i + 1 :]: distance = np.linalg.norm(p1 - p2) if distance > max_distance: max_distance = distance @@ -61,8 +63,8 @@ def process_image(filename): # Calculate the centroid of the contour M = cv2.moments(contour) - cx = int(M['m10'] / M['m00']) - cy = int(M['m01'] / M['m00']) + cx = int(M["m10"] / M["m00"]) + cy = int(M["m01"] / M["m00"]) centroid = (cx, cy) # Draw the minimum enclosing circle @@ -70,17 +72,49 @@ def process_image(filename): # Draw a marker at the centroid cv2.circle(img_processed, centroid, 5, (0, 0, 255), -1) # Red circle - # Display the calculations as text - cv2.putText(img_processed, f"Total surface area: {area:.2f}", (cx - 40, cy - 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) - cv2.putText(img_processed, f"Total Perimeter: {perimeter:.2f}", (cx - 60, cy + 40), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) - cv2.putText(img_processed, f"Centroid: ({cx},{cy})", (cx - 40, cy + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) - cv2.putText(img_processed, f"Major Axis Length: {max_distance:.2f}", (cx - 60, cy + 60),cv2.FONT_HERSHEY_SIMPLEX, 0.5,(0, 0, 255), 2) + cv2.putText( + img_processed, + f"Total surface area: {area:.2f}", + (cx - 40, cy - 20), + cv2.FONT_HERSHEY_SIMPLEX, + 0.5, + (0, 0, 255), + 2, + ) + cv2.putText( + img_processed, + f"Total Perimeter: {perimeter:.2f}", + (cx - 60, cy + 40), + cv2.FONT_HERSHEY_SIMPLEX, + 0.5, + (0, 0, 255), + 2, + ) + cv2.putText( + img_processed, + f"Centroid: ({cx},{cy})", + (cx - 40, cy + 20), + cv2.FONT_HERSHEY_SIMPLEX, + 0.5, + (0, 0, 255), + 2, + ) + cv2.putText( + img_processed, + f"Major Axis Length: {max_distance:.2f}", + (cx - 60, cy + 60), + cv2.FONT_HERSHEY_SIMPLEX, + 0.5, + (0, 0, 255), + 2, + ) # Save the processed image with calculations output_filename = os.path.join(output_folder, os.path.basename(filename)) cv2.imwrite(output_filename, img_processed) + # Process each image in the input folder for filename in os.listdir(input_folder): if filename.endswith((".jpg", ".png")): diff --git a/projects/Windows Logo/windows_logo.py b/projects/Windows Logo/windows_logo.py index 4b95371fa..3106bdcc7 100644 --- a/projects/Windows Logo/windows_logo.py +++ b/projects/Windows Logo/windows_logo.py @@ -1,24 +1,25 @@ import turtle -t=turtle.Turtle() -s=turtle.Screen() + +t = turtle.Turtle() +s = turtle.Screen() t.speed(2) s.bgcolor("black") t.penup() -t.goto(-50,60) +t.goto(-50, 60) t.pendown() t.color("#00adef") t.begin_fill() -t.goto(100,100) -t.goto(100,-100) -t.goto(-50,-60) -t.goto(-50,60) +t.goto(100, 100) +t.goto(100, -100) +t.goto(-50, -60) +t.goto(-50, 60) t.end_fill() t.color("black") -t.goto(15,100) +t.goto(15, 100) t.color("black") t.width(10) -t.goto(15,-100) +t.goto(15, -100) t.penup() -t.goto(100,0) +t.goto(100, 0) t.pendown() -t.goto(-100,0) +t.goto(-100, 0) diff --git a/projects/inventory management/main.py b/projects/inventory management/main.py index e722d351d..76d43ba91 100644 --- a/projects/inventory management/main.py +++ b/projects/inventory management/main.py @@ -1,115 +1,163 @@ import tkinter import mysql.connector as q -con=q.connect(host="localhost", user="root", passwd="", database="records") -cursor=con.cursor() -#Adding record to an empty table(inventory) +con = q.connect(host="localhost", user="root", passwd="", database="records") +cursor = con.cursor() + +# Adding record to an empty table(inventory) + def ADD(): - pid=int(input("Enter the product id:")) - pname=input("Enter the product name: ") - pcost=int(input("Enter the product cost:")) - pqty=int(input("Enter the product quantity:")) - query="insert into inventory values({},'{}',{},{})".format(pid,pname,pcost,pqty) + pid = int(input("Enter the product id:")) + pname = input("Enter the product name: ") + pcost = int(input("Enter the product cost:")) + pqty = int(input("Enter the product quantity:")) + query = "insert into inventory values({},'{}',{},{})".format( + pid, pname, pcost, pqty + ) cursor.execute(query) con.commit() print("Data Inserted successfully") -#Displaying record in List form - + +# Displaying record in List form + + def Display(): cursor.execute("select * from inventory") - record=cursor.fetchall() - print("ID"," ","Name"," ","Cost","","Quantity") + record = cursor.fetchall() + print("ID", " ", "Name", " ", "Cost", "", "Quantity") for i in record: print(i) - print("Total Number of record=",cursor.rowcount) + print("Total Number of record=", cursor.rowcount) + + +# Searching product on the basis of product code -#Searching product on the basis of product code def Search(): - val=int(input("Enter the product code to search:")) - flag=0 + val = int(input("Enter the product code to search:")) + flag = 0 cursor.execute("select * from inventory") - record=cursor.fetchall() + record = cursor.fetchall() for i in record: - if i[0]==val: - flag=1 - print("ID"," ","Name"," ","Cost","","Quantity") + if i[0] == val: + flag = 1 + print("ID", " ", "Name", " ", "Cost", "", "Quantity") print(i) - if flag==0: + if flag == 0: print("---Record not found---") - + + # Updating existing record on the basis of product ID + def Update(): - code=int(input("Enter the product id to update:")) - pid=int(input("Enter product id:")) - pname=input("Enter product name:") - pcost=int(input("Enter the product cost:")) - pqty=int(input("Enter the product quantity:")) - query="update inventory set PID={},PNAME='{}',PCOST={},PQTY={} where PID={}".format(pid,pname,pcost,pqty,code) + code = int(input("Enter the product id to update:")) + pid = int(input("Enter product id:")) + pname = input("Enter product name:") + pcost = int(input("Enter the product cost:")) + pqty = int(input("Enter the product quantity:")) + query = ( + "update inventory set PID={},PNAME='{}',PCOST={},PQTY={} where PID={}".format( + pid, pname, pcost, pqty, code + ) + ) cursor.execute(query) con.commit() print("Data Updated SuccessfullY") + # Deleting records + def Delete(): - val=int(input("Enter product ID whose records are to be deleted:")) - query="delete from inventory where PID={}".format(val) + val = int(input("Enter product ID whose records are to be deleted:")) + query = "delete from inventory where PID={}".format(val) cursor.execute(query) con.commit() - if cursor.rowcount>0: + if cursor.rowcount > 0: print("Record Successfully Deleted") else: print("Product not found") - + + def check(): - if e1.get()=="Admin" and e2.get()=="1234": - win=tkinter.Tk() + if e1.get() == "Admin" and e2.get() == "1234": + win = tkinter.Tk() win.title("Inventory") win.configure(bg="SteelBlue1") - win.geometry('500x400') + win.geometry("500x400") login.destroy() - l=tkinter.Label(win,text='Welcome to Super Market',font=('Arial',18,'bold'),bg="SteelBlue1",fg="Black") + l = tkinter.Label( + win, + text="Welcome to Super Market", + font=("Arial", 18, "bold"), + bg="SteelBlue1", + fg="Black", + ) l.pack(side="top") - search=tkinter.Button(win,text="Search",font=('Arial',10,'bold'),command=Search,bg="azure") - add=tkinter.Button(win,text=' Add ',font=('Arial',10,'bold'),command=ADD,bg="azure") - update=tkinter.Button(win,text="Update",font=('Arial',10,'bold'),command=Update,bg='azure') - display=tkinter.Button(win,text="Display",font=('Arial',10,'bold'),command=Display,bg="azure") - delete=tkinter.Button(win,text=" Delete ",font=('Arial',10,'bold'),command=Delete,bg="azure") - e=tkinter.Button(win,text=' Exit ',font=('Arial',10,'bold'),command=win.destroy,bg="azure") - add.place(x=90,y=100) - display.place(x=90,y=200) - search.place(x=300,y=100) - update.place(x=195,y=150) - delete.place(x=300,y=200) - e.place(x=200,y=250) + search = tkinter.Button( + win, text="Search", font=("Arial", 10, "bold"), command=Search, bg="azure" + ) + add = tkinter.Button( + win, text=" Add ", font=("Arial", 10, "bold"), command=ADD, bg="azure" + ) + update = tkinter.Button( + win, text="Update", font=("Arial", 10, "bold"), command=Update, bg="azure" + ) + display = tkinter.Button( + win, text="Display", font=("Arial", 10, "bold"), command=Display, bg="azure" + ) + delete = tkinter.Button( + win, text=" Delete ", font=("Arial", 10, "bold"), command=Delete, bg="azure" + ) + e = tkinter.Button( + win, + text=" Exit ", + font=("Arial", 10, "bold"), + command=win.destroy, + bg="azure", + ) + add.place(x=90, y=100) + display.place(x=90, y=200) + search.place(x=300, y=100) + update.place(x=195, y=150) + delete.place(x=300, y=200) + e.place(x=200, y=250) win.mainloop() - else: - l1=tkinter.Label(login,text="Login Unsuccessful!!",font=("Arial",10,"bold"),fg="black",bg="light salmon") - l1.place(x=110,y=170) - - -login=tkinter.Tk() + l1 = tkinter.Label( + login, + text="Login Unsuccessful!!", + font=("Arial", 10, "bold"), + fg="black", + bg="light salmon", + ) + l1.place(x=110, y=170) + + +login = tkinter.Tk() login.geometry("400x220") login.configure(bg="light salmon") login.title("Authorised Login Only") -o=tkinter.Label(login,text='Login',font=('Arial',18,'bold'),bg='light salmon',fg="black") -o.pack(side='top') - -l1=tkinter.Label(login,text="Username",font=("Arial",10,'bold'),bg="white") -l1.place(x=10,y=50) -e1=tkinter.Entry(login,width=25,font=("Arial",10,'bold')) -e1.place(x=150,y=50) -l2=tkinter.Label(login,text= "Password",font=("Arial",10,'bold'),bg="white") -l2.place(x=10,y=80) -e2=tkinter.Entry(login,width=25,font=(10),show="*") -e2.place(x=150,y=80) -q=tkinter.Button(login,text="Submit",font=("Arial",10,"bold"),command=check) -q.place(x=225,y=120) -z=tkinter.Button(login,text="EXIT",font=("Arial",10,"bold"),command=login.destroy) -z.place(x=125,y=120) \ No newline at end of file +o = tkinter.Label( + login, text="Login", font=("Arial", 18, "bold"), bg="light salmon", fg="black" +) +o.pack(side="top") + +l1 = tkinter.Label(login, text="Username", font=("Arial", 10, "bold"), bg="white") +l1.place(x=10, y=50) +e1 = tkinter.Entry(login, width=25, font=("Arial", 10, "bold")) +e1.place(x=150, y=50) +l2 = tkinter.Label(login, text="Password", font=("Arial", 10, "bold"), bg="white") +l2.place(x=10, y=80) +e2 = tkinter.Entry(login, width=25, font=(10), show="*") +e2.place(x=150, y=80) +q = tkinter.Button(login, text="Submit", font=("Arial", 10, "bold"), command=check) +q.place(x=225, y=120) +z = tkinter.Button( + login, text="EXIT", font=("Arial", 10, "bold"), command=login.destroy +) +z.place(x=125, y=120)