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

Commit 0c90614

Browse files
committed
Fix code style issues with Black
1 parent c25d044 commit 0c90614

4 files changed

Lines changed: 85 additions & 50 deletions

File tree

projects/MQTT Client/MqttClient.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,51 @@
44

55
# Reading broker credentials
66
BROKER = config("BROKER")
7-
PORT = int(config("PORT"))
8-
TOPIC = config("TOPIC")
9-
USER = config("USER")
10-
PASS = config("PASS")
7+
PORT = int(config("PORT"))
8+
TOPIC = config("TOPIC")
9+
USER = config("USER")
10+
PASS = config("PASS")
1111

1212
# Create a randdom id for login in MQTT
13-
CLIENT_ID = f'id-mqtt-{randint(0,100)}'
13+
CLIENT_ID = f"id-mqtt-{randint(0,100)}"
14+
1415

1516
# Create a client to interact with MQTT
1617
def connectMqtt() -> mqtt_client:
1718
def on_connect(client, userdata, flags, rc):
1819
if rc == 0:
19-
print('[MQTT] Connected to server.')
20+
print("[MQTT] Connected to server.")
2021
else:
21-
print('[MQTT] Failure to connect.')
22-
22+
print("[MQTT] Failure to connect.")
23+
2324
client = mqtt_client.Client(CLIENT_ID)
2425
client.username_pw_set(USER, PASS)
2526
client.on_connect = on_connect
26-
client.connect(BROKER,PORT)
27+
client.connect(BROKER, PORT)
2728

2829
return client
2930

31+
3032
# Receiving messages sendings with MQTT
3133
def subscribe(client: mqtt_client):
3234
def on_message(client, userdata, msg):
3335
print(
34-
f'[MQTT] Received message from {msg.topic} topic:',
35-
f'\n{msg.payload.decode()}'
36+
f"[MQTT] Received message from {msg.topic} topic:",
37+
f"\n{msg.payload.decode()}",
3638
)
3739

3840
client.subscribe(TOPIC)
3941
client.on_message = on_message
4042

43+
4144
# Publishing messages with MQTT
42-
def publish(client, msg='Hello MQTT'):
43-
result = client.publish(TOPIC,msg)
44-
45-
if __name__ == '__main__':
45+
def publish(client, msg="Hello MQTT"):
46+
result = client.publish(TOPIC, msg)
47+
48+
49+
if __name__ == "__main__":
4650
client = connectMqtt()
4751
subscribe(client)
4852
publish(client)
49-
publish(client, msg='Custom Messages Working!')
50-
client.loop_forever()
53+
publish(client, msg="Custom Messages Working!")
54+
client.loop_forever()

projects/PDF_Reader/PDF_Reader.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
load_dotenv()
1616
openai_api_key = os.getenv("API_KEY")
17-
openai.openai_api_key=openai_api_key
17+
openai.openai_api_key = openai_api_key
1818

1919
loader = PyPDFLoader("promptEngineering.pdf")
2020
docs = loader.load_and_split()
@@ -25,36 +25,44 @@
2525
vectorstore = Chroma.from_documents(documents, embeddings)
2626
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
2727

28+
2829
def originalText(docs):
29-
text=str(docs)
30+
text = str(docs)
3031
regex = r"(Document)|(page_content=)|(metadata={'source':)|('page': \d})\)|(\\n)"
31-
text=re.sub(regex, "", text)
32+
text = re.sub(regex, "", text)
3233
return text
3334

34-
text=originalText(docs)
35+
36+
text = originalText(docs)
3537
print("Text in pdf", text)
3638

39+
3740
def summarizeText():
3841
llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")
3942
chain = load_summarize_chain(llm, chain_type="stuff")
4043
return chain.run(docs)
4144

42-
summary=summarizeText()
45+
46+
summary = summarizeText()
4347
print("Summary of text in pdf", summary)
4448

49+
4550
def QA(query):
46-
qa = ConversationalRetrievalChain.from_llm(OpenAI(temperature=0), vectorstore.as_retriever(), memory=memory)
51+
qa = ConversationalRetrievalChain.from_llm(
52+
OpenAI(temperature=0), vectorstore.as_retriever(), memory=memory
53+
)
4754
query = "What is prompt engineering?"
4855
result = qa({"question": query})
49-
result=str(result['chat_history'][1])
50-
result=result.split('content=\'')[1]
56+
result = str(result["chat_history"][1])
57+
result = result.split("content='")[1]
5158
return result
5259

60+
5361
print("INSTRUCTIONS:")
54-
print("Enter the question you want to ask from pdf text OR press \"-1\" to STOP")
55-
while(True):
56-
user_input=input("Enter your question: ")
57-
if(user_input=="-1"):
62+
print('Enter the question you want to ask from pdf text OR press "-1" to STOP')
63+
while True:
64+
user_input = input("Enter your question: ")
65+
if user_input == "-1":
5866
break
5967
else:
6068
print(QA(user_input))

projects/Port_Scaner/port_scanner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import socket
22
import pyfiglet
33

4+
45
def int_checker(x):
56
while True:
67
try:
@@ -11,6 +12,7 @@ def int_checker(x):
1112
x = input("Enter the port to check: ")
1213
return x
1314

15+
1416
def port_checker(port):
1517
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1618
result = sock.connect_ex(("127.0.0.1", port))
@@ -21,6 +23,7 @@ def port_checker(port):
2123

2224
sock.close()
2325

26+
2427
print(pyfiglet.figlet_format("Port Scanner"))
2528
print("Port Scanner")
2629
port_to_check = int_checker(input("Enter the port to check: "))

projects/Type Racer Game/type_racer.py

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# Flag to indicate whether the game has started
2828
game_started = False
2929

30+
3031
# Function to start the game with a countdown
3132
def start_game():
3233
global start_time, current_sentence, timer_duration, score, game_started
@@ -49,17 +50,21 @@ def start_game():
4950
sentence_label.config(text=current_sentence)
5051
input_box.delete(0, tk.END)
5152
input_box.focus()
52-
input_box.config(foreground='black', width=40) # Reset text color and increase width
53+
input_box.config(
54+
foreground="black", width=40
55+
) # Reset text color and increase width
5356
game_started = True # Set the game started flag
5457
start_main_timer() # Start the main game timer after the countdown
5558

59+
5660
# Function to reset the game
5761
def reset_game():
5862
global game_started
5963
game_started = False
6064
countdown_label.config(text="")
6165
submit_score() # Submit the score to reset the progress bar
6266

67+
6368
# Function to start the main game timer
6469
def start_main_timer():
6570
global timer_duration, game_started
@@ -72,14 +77,16 @@ def start_main_timer():
7277
timer_label.config(text="Time's up!")
7378
submit_score()
7479

80+
7581
# Function to handle typing and change text color
7682
def check_input(event):
7783
input_text = input_box.get()
7884
if current_sentence.startswith(input_text):
79-
input_box.config(foreground='green') # Correct text color
85+
input_box.config(foreground="green") # Correct text color
8086
update_progress_bar(len(input_text))
8187
else:
82-
input_box.config(foreground='red') # Incorrect text color
88+
input_box.config(foreground="red") # Incorrect text color
89+
8390

8491
# Function to handle submission of score
8592
def submit_score():
@@ -88,40 +95,49 @@ def submit_score():
8895
time_taken = round(end_time - start_time, 2)
8996
if input_box.get() == current_sentence:
9097
wpm = calculate_wpm(time_taken, len(current_sentence.split()))
91-
result_label.config(text=f"Correct! Time taken: {time_taken} seconds, WPM: {wpm}", foreground='green')
98+
result_label.config(
99+
text=f"Correct! Time taken: {time_taken} seconds, WPM: {wpm}",
100+
foreground="green",
101+
)
92102
reset_progress_bar()
93103
animate_result_label()
94104
current_sentence = random.choice(sentences) # Select a new random sentence
95105
start_game()
96106
else:
97-
result_label.config(text=f"Incorrect. Time taken: {time_taken} seconds", foreground='red')
107+
result_label.config(
108+
text=f"Incorrect. Time taken: {time_taken} seconds", foreground="red"
109+
)
98110
animate_result_label()
99111

112+
100113
# Function to animate the result label
101114
def animate_result_label():
102-
result_label.config(foreground='red')
103-
root.after(100, lambda: result_label.config(foreground='black'))
104-
root.after(200, lambda: result_label.config(foreground='red'))
105-
root.after(300, lambda: result_label.config(foreground='black'))
106-
root.after(400, lambda: result_label.config(foreground='red'))
107-
root.after(500, lambda: result_label.config(foreground='black'))
108-
root.after(600, lambda: result_label.config(foreground='red'))
109-
root.after(700, lambda: result_label.config(foreground='black'))
110-
root.after(800, lambda: result_label.config(foreground='red'))
111-
root.after(900, lambda: result_label.config(foreground='black'))
112-
root.after(1000, lambda: result_label.config(foreground='red'))
113-
root.after(1100, lambda: result_label.config(text="", foreground='black'))
115+
result_label.config(foreground="red")
116+
root.after(100, lambda: result_label.config(foreground="black"))
117+
root.after(200, lambda: result_label.config(foreground="red"))
118+
root.after(300, lambda: result_label.config(foreground="black"))
119+
root.after(400, lambda: result_label.config(foreground="red"))
120+
root.after(500, lambda: result_label.config(foreground="black"))
121+
root.after(600, lambda: result_label.config(foreground="red"))
122+
root.after(700, lambda: result_label.config(foreground="black"))
123+
root.after(800, lambda: result_label.config(foreground="red"))
124+
root.after(900, lambda: result_label.config(foreground="black"))
125+
root.after(1000, lambda: result_label.config(foreground="red"))
126+
root.after(1100, lambda: result_label.config(text="", foreground="black"))
127+
114128

115129
# Function to update the progress bar
116130
def update_progress_bar(length):
117131
progress = min(length / len(current_sentence), 1.0) * 100
118132
progressbar_label.config(text=f"Progress: {int(progress)}%")
119-
progressbar['value'] = progress
133+
progressbar["value"] = progress
134+
120135

121136
# Function to reset the progress bar
122137
def reset_progress_bar():
123138
progressbar_label.config(text="Progress: 0%")
124-
progressbar['value'] = 0
139+
progressbar["value"] = 0
140+
125141

126142
# Countdown timer function
127143
def countdown():
@@ -132,12 +148,14 @@ def countdown():
132148
timer_duration -= 1
133149
root.after(1000, countdown)
134150

151+
135152
# Function to calculate WPM
136153
def calculate_wpm(time_taken, word_count):
137154
minutes = time_taken / 60
138155
wpm = (word_count / 5) / minutes
139156
return round(wpm)
140157

158+
141159
# Initialize the GUI
142160
root = tk.Tk()
143161
root.geometry("800x400")
@@ -149,13 +167,15 @@ def calculate_wpm(time_taken, word_count):
149167
style.configure("TLabel", foreground="black", font=("Arial", 14))
150168
style.configure("TButton", font=("Arial", 16))
151169

152-
sentence_label = ttk.Label(root, text=current_sentence, wraplength=700, justify='left')
170+
sentence_label = ttk.Label(root, text=current_sentence, wraplength=700, justify="left")
153171
input_box = ttk.Entry(root, font=("Arial", 16), width=40) # Increase width
154172
submit_button = ttk.Button(root, text="Submit", command=submit_score)
155173
reset_button = ttk.Button(root, text="Reset", command=reset_game)
156174
result_label = ttk.Label(root)
157175
progressbar_label = ttk.Label(root, text="Progress: 0%")
158-
progressbar = ttk.Progressbar(root, orient=tk.HORIZONTAL, length=200, mode="determinate")
176+
progressbar = ttk.Progressbar(
177+
root, orient=tk.HORIZONTAL, length=200, mode="determinate"
178+
)
159179
timer_label = ttk.Label(root, text=f"Time left: {timer_duration} seconds")
160180
countdown_label = ttk.Label(root, font=("Arial", 24), foreground="red")
161181

0 commit comments

Comments
 (0)