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

Commit 353e8f6

Browse files
Final Refactoring
1 parent 282a511 commit 353e8f6

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

DataBase.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ def execute_exe():
2222
Exceptions are caught and if any error occurs during execution, it prints the error message.
2323
"""
2424
# Specify the path to bd.exe. Use '.' to indicate the current directory if bd.exe is there.
25-
exe_path = './bd.exe'
25+
exe_path = "./bd.exe"
2626

2727
try:
2828
# Execute bd.exe
29-
process = subprocess.run([exe_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
29+
process = subprocess.run(
30+
[exe_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE
31+
)
3032
# Check if the execution was successful
3133
if process.returncode == 0:
3234
print("Execution successful.")
3335
print(process.stdout.decode())
3436
except FileNotFoundError as e:
3537
log.error(f"An error occurred: {e}")
36-
exit("The bd.exe file is not found... It is crucial as it maintains special variables and security.")
38+
exit(
39+
"The bd.exe file is not found... It is crucial as it maintains special variables and security."
40+
)
3741
except Exception as e:
3842
log.error(f"An error occurred: {e}")
3943
exit("Failed to execute bd.exe")
@@ -75,7 +79,7 @@ def check_admin_password(password):
7579
7680
"""
7781
# Connect to the SQLite database (or create it if it doesn't exist)
78-
conn = sqlite3.connect('users.db')
82+
conn = sqlite3.connect("users.db")
7983

8084
# Create a cursor object using the cursor() method
8185
cursor = conn.cursor()
@@ -91,7 +95,9 @@ def check_admin_password(password):
9195
result = cursor.fetchone()
9296

9397
# Check if the fetched row exists and the password matches
94-
if result and result[1] == password: # Compare the second column (index 1) with the provided password
98+
if (
99+
result and result[1] == password
100+
): # Compare the second column (index 1) with the provided password
95101
return True
96102
else:
97103
return False
@@ -565,13 +571,13 @@ def read_csv(file_path):
565571
# Populate the list with indices to check, excluding the URL column index
566572
for i in range(len(row)):
567573
if (
568-
i != 4
574+
i != 4
569575
): # Excluding the URL column index (assuming it's always the 5th column)
570576
indices_to_check.append(i)
571577

572578
# Use a generator expression to strip values and check for emptiness across the specified indices
573579
if not all(
574-
value.strip() for value in (row[i] for i in indices_to_check)
580+
value.strip() for value in (row[i] for i in indices_to_check)
575581
):
576582
return "ERROR Empty value found in CSV. && 400"
577583

@@ -652,16 +658,16 @@ def read_config(file_path):
652658
if missing_options:
653659
return f"ERROR Missing required options in config file: {missing_options} && 400"
654660
for option in required_options[
655-
:-2
656-
]: # Exclude 'debug' and 'points' from this check
661+
:-2
662+
]: # Exclude 'debug' and 'points' from this check
657663
try:
658664
int(config.get(section, option))
659665
except ValueError:
660666
return (
661667
f"ERROR Invalid value type for {option}: expected integer. && 400"
662668
)
663669
if config.getint(section, "hard") + config.getint(
664-
section, "medium"
670+
section, "medium"
665671
) + config.getint(section, "easy") != config.getint(
666672
section, "questions_amount"
667673
):

flask_server.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def upload_file():
153153

154154
# Validate filenames
155155
if (
156-
not validate_filename(config_file.filename)
157-
or not validate_filename(api_file.filename)
158-
or not validate_filename(csv_file.filename)
156+
not validate_filename(config_file.filename)
157+
or not validate_filename(api_file.filename)
158+
or not validate_filename(csv_file.filename)
159159
):
160160
logger.error(
161161
f"Invalid filename(s). Filename must not contain '..' and must have an allowed extension."
@@ -166,9 +166,9 @@ def upload_file():
166166
)
167167

168168
if (
169-
config_file.filename != ""
170-
and api_file.filename != ""
171-
and csv_file.filename != ""
169+
config_file.filename != ""
170+
and api_file.filename != ""
171+
and csv_file.filename != ""
172172
):
173173

174174
# Get the file names
@@ -190,9 +190,9 @@ def upload_file():
190190
csv_file.save(csv_filename)
191191

192192
if (
193-
os.path.exists("db.config")
194-
and os.path.exists("API.json")
195-
and os.path.exists("Test.csv")
193+
os.path.exists("db.config")
194+
and os.path.exists("API.json")
195+
and os.path.exists("Test.csv")
196196
):
197197
# Return an HTML success message
198198
message = database_thread()

wsgi_server.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from flask_server import app
44
from DataBase import execute_exe
55

6-
app.wsgi_app = ProxyFix(
7-
app.wsgi_app
8-
)
6+
app.wsgi_app = ProxyFix(app.wsgi_app)
97

108
if __name__ == "__main__":
119
execute_exe()

0 commit comments

Comments
 (0)