Skip to content

Commit ae6e2f6

Browse files
authored
Merge branch 'main' into main
2 parents da62f84 + eaa9d06 commit ae6e2f6

File tree

23 files changed

+796
-138
lines changed

23 files changed

+796
-138
lines changed

README.md

Lines changed: 175 additions & 82 deletions
Large diffs are not rendered by default.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import socket
2+
import threading
3+
4+
# Server configuration
5+
HOST = "127.0.0.1"
6+
PORT = 12345
7+
8+
# Create a server socket
9+
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10+
server_socket.bind((HOST, PORT))
11+
server_socket.listen()
12+
13+
clients = []
14+
15+
16+
def handle_client(client_socket, addr):
17+
with client_socket:
18+
print(f"New connection from {addr}")
19+
clients.append(client_socket)
20+
while True:
21+
data = client_socket.recv(1024)
22+
if not data:
23+
break
24+
for client in clients:
25+
if client != client_socket:
26+
client.send(data)
27+
28+
29+
def main():
30+
print(f"Server listening on {HOST}:{PORT}")
31+
while True:
32+
client_socket, addr = server_socket.accept()
33+
client_handler = threading.Thread(
34+
target=handle_client, args=(client_socket, addr)
35+
)
36+
client_handler.start()
37+
38+
39+
if __name__ == "__main__":
40+
main()
41+
42+
43+
import socket
44+
import threading
45+
46+
# Client configuration
47+
HOST = "127.0.0.1"
48+
PORT = 12345
49+
50+
51+
def receive_messages(client_socket):
52+
while True:
53+
data = client_socket.recv(1024).decode()
54+
print(data)
55+
56+
57+
def main():
58+
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
59+
client_socket.connect((HOST, PORT))
60+
61+
receive_thread = threading.Thread(target=receive_messages, args=(client_socket,))
62+
receive_thread.start()
63+
64+
while True:
65+
message = input()
66+
client_socket.send(message.encode())
67+
68+
69+
if __name__ == "__main__":
70+
main()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Chat Application
2+
3+
Chat Application is a simple Python-based chat system that demonstrates basic communication between a server and clients using sockets. This example provides a basic console-based chat system and serves as a starting point for more complex chat applications.
4+
5+
## Usage
6+
7+
1. **Server (chat_server.py)**:
8+
9+
- Run the `chat_server.py` script to start the server. It will listen for incoming client connections on the specified IP address and port (e.g., `127.0.0.1:12345`).
10+
11+
- The server forwards messages from one client to all other connected clients.
12+
13+
2. **Client (chat_client.py)**:
14+
15+
- Run the `chat_client.py` script on multiple machines to create client instances.
16+
17+
- Clients connect to the server and can communicate with each other.
18+
19+
- Messages sent by one client are broadcast to all connected clients.
20+
21+
3. **Customization**:
22+
23+
- You can modify the server IP address and port in the scripts for your specific network configuration.
24+
25+
- Extend the application to include features like user authentication, private messages, and a graphical user interface (GUI).
26+
27+
4. **Requirements**:
28+
29+
- Python 3.x
30+
31+
## Example
32+
33+
Imagine you want to create a basic chat system to allow users on different machines to communicate with each other. You can run the server on one machine and connect clients from multiple other machines to start a simple chat session.
34+
35+
## License
36+
37+
This project is open-source and available under the [MIT License](LICENSE).
38+
39+
Feel free to expand and customize this code to build more advanced chat applications with additional features, security, and user interfaces. If you have questions or encounter issues, please create an issue in the [GitHub repository](https://github.com/yourusername/chat-application).
40+
41+
Enjoy exploring the world of chat systems with Python!
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)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import random
2+
3+
# List of words for the game
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+
26+
27+
# Function to choose a random word from the list
28+
def choose_random_word(word_list):
29+
return random.choice(word_list)
30+
31+
32+
# Function to play the word guessing game
33+
def word_guessing_game():
34+
word_to_guess = choose_random_word(word_list)
35+
guessed_letters = []
36+
attempts = 6
37+
38+
print("Welcome to the Word Guessing Game!")
39+
print("You have 6 attempts to guess the word.")
40+
print("_ " * len(word_to_guess))
41+
42+
while attempts > 0:
43+
guess = input("Guess a letter: ").lower()
44+
45+
if len(guess) != 1 or not guess.isalpha():
46+
print("Please enter a single letter.")
47+
continue
48+
49+
if guess in guessed_letters:
50+
print("You've already guessed that letter.")
51+
continue
52+
53+
guessed_letters.append(guess)
54+
55+
if guess in word_to_guess:
56+
print("Correct guess!")
57+
remaining_letters = [
58+
letter if letter in guessed_letters else "_" for letter in word_to_guess
59+
]
60+
print(" ".join(remaining_letters))
61+
if "_" not in remaining_letters:
62+
print("Congratulations! You've guessed the word:", word_to_guess)
63+
break
64+
else:
65+
attempts -= 1
66+
if attempts < 3:
67+
print(f"It is a name of a programming language")
68+
print(f"Wrong guess. You have {attempts} attempts remaining.")
69+
70+
if attempts == 0:
71+
print("You've run out of attempts. The word was:", word_to_guess)
72+
73+
74+
# Start the game
75+
word_guessing_game()

0 commit comments

Comments
 (0)