-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
383 lines (308 loc) · 11.7 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# Import necessary modules
import random
import os
import datetime
import json
import base64
import time
# Try to import the 'CurrencyRates' class from the 'forex_python.converter' module.
# If it's not installed, attempt to install it using pip.
try:
from forex_python.converter import CurrencyRates
except:
os.system("pip install forex_python ")
from forex_python.converter import CurrencyRates
# Import functions from other modules
from functions.login_signup import (
signup,
login,
change_password,
logged,
data_refresh,
save_data
)
from functions.accounting import (
deposit,
withdraw,
get_deposit_history,
get_withdrawal_history,
export_transactions_to_csv,
)
# Define colors for console output
bcolors = [
'\033[94m', # Blue
'\033[96m', # Cyan
'\033[92m', # Green
'\033[93m', # Yellow
'\033[1;33m', # Bold Yellow
]
# File paths and checking
user_file = "data/users.json"
cookie_file = "data/cookie.txt"
csv_export_file = "data/transactions.csv"
folder_paths = ["data"]
for folder_path in folder_paths:
os.makedirs(folder_path, exist_ok=True)
# Initialize currency converter
currency_converter = CurrencyRates()
# Initialize users dictionary or load existing user data from a file
try:
with open(user_file, "r") as file:
users = json.load(file)
except FileNotFoundError:
users = {}
# Function to clear the screen
def clear_screen():
# Check if the operating system is Windows
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
# Function for user input
def inputf(output):
return input(f"\n\n\t\033[1;97m[>] {output}")
# Function to print text with a simulated typing effect
def printf(text, base_delay=0.023, jitter=0.02):
for char in text:
delay = max(0, base_delay + random.uniform(-jitter, jitter))
# Print the character with a small delay
print(char, end='', flush=True)
time.sleep(delay)
# Function to create a formatted table
def create_table(text):
terminal_width = os.get_terminal_size().columns
border = '*' * (terminal_width - 2)
text_lines = text.split('\n')
formatted_text = ''
for line in text_lines:
formatted_text += f"| {line.center(terminal_width - 4)} |\n"
table = f"{border}\n{formatted_text}{border}"
return table
# Currency Converter function
def convert_currency():
try:
source_currency = inputf("Enter source currency (e.g., USD): ").upper()
target_currency = inputf("Enter target currency (e.g., EUR): ").upper()
amount = float(inputf("Enter the amount to convert: "))
result = currency_converter.convert(
source_currency, target_currency, amount)
printf(
f"\n\t Result :> {amount} {source_currency} is approximately {result} {target_currency}")
except Exception as e:
print("Error performing currency conversion:", str(e))
# Function for user input with password complexity check
def input_password(output, login=False):
trying = 1
while True:
password = input(f"{output}")
if is_password_complex(password):
return password
else:
if login:
trying += 1
if trying == 4:
print("\n\t[+] Entering the password is restricted ")
main()
print("\n\t[+] Password must be at least 6 characters long and contain at least one uppercase letter, one lowercase letter, and one digit. (e.g., inTe1@)")
# Function to check password complexity
def is_password_complex(password):
if len(password) < 6:
return False
if not any(char.isupper() for char in password):
return False
if not any(char.islower() for char in password):
return False
if not any(char.isdigit() for char in password):
return False
return True
# Main function for accounting operations
def accounting_main(user_data, username):
if user_data:
while True:
user_data = data_refresh(username)
clear_screen()
# Randomly select text colors
color1 = random.choice(bcolors)
color2 = random.choice(bcolors)
while color1 == color2:
color2 = random.choice(bcolors)
printf(color1)
print(
create_table(
f"\n\tAccount Management ( Your ID: {user_data['id']} and Balance : {user_data['balance']} )\n"
)
)
printf(color2)
printf("\n\t1. Deposit Money\n", base_delay=0.01)
printf("\t2. Withdraw Money\n", base_delay=0.01)
printf("\t3. View Deposit History\n", base_delay=0.01)
printf("\t4. View Withdrawal History\n", base_delay=0.01)
printf("\t5. Change Password\n", base_delay=0.01)
printf("\t6. Export Data\n ", base_delay=0.01)
printf("\t7. Convert Currency\n", base_delay=0.01)
printf("\t8. Back\n", base_delay=0.01)
printf("\t9. Account Delete \n", base_delay=0.01)
printf("\t10. Logout\n", base_delay=0.01)
choice = inputf("\tEnter your choice: ")
if choice == "1":
amount = float(inputf("\n\tEnter the amount to deposit: "))
target_id = inputf(
"\n\tEnter the target user's ID or username: ")
result = deposit(users, user_data['id'], target_id, amount)
if result:
user_data = data_refresh(username)
printf(
f"\n\t[+] Deposited {amount} into {result}'s account. New balance: {user_data['balance']}"
)
else:
printf("\t [+] User(s) not found.")
elif choice == "2":
amount = float(inputf("\n\tEnter the amount to withdraw: "))
result = withdraw(users, user_data['id'], amount)
if isinstance(result, str):
printf(f"\n\t[+] {result}")
else:
user_data = data_refresh(username)
printf(
f"\n\t[+] Withdrawn {amount}. New balance: {user_data['balance']}"
)
elif choice == "3":
deposit_history = get_deposit_history(users[username])
if deposit_history:
printf("\nDeposit History:")
for transaction in deposit_history:
printf(
f"\n\t [×] Timestamp: {transaction['timestamp']}, Amount: {transaction['amount']}, Target User ID: {transaction['target_user']}"
)
else:
printf("\n\tNo deposit history.")
elif choice == "4":
withdrawal_history = get_withdrawal_history(users[username])
if withdrawal_history:
printf("\nWithdrawal History:")
for transaction in withdrawal_history:
printf(
f"\n\t [×] Timestamp: {transaction['timestamp']}, Amount: {transaction['amount']}"
)
else:
printf("\n\tNo withdrawal history.")
elif choice == "5":
old_password = input_password(
"\n\t\033[1;97m[>] Enter your old password: ")
new_password = input_password(
"\n\t\033[1;97m[>] Enter your new password: ")
result = change_password(
users, username, old_password, new_password)
printf("\n" + result)
elif choice == "6":
if not username:
printf("You need to log in to export data.")
else:
export_transactions_to_csv(username)
printf(
"\n[+] Transaction data exported to CSV file. (data/transactions.csv}")
elif choice == "7":
convert_currency()
elif choice == "8":
break
elif choice == "9":
ch = inputf(
"Do you want to Delete your account? (0-no/1-yes): ")
if "0" not in ch:
del users[username]
save_data(users)
os.system("rm -rf data/cookie.txt")
main()
elif choice == "10":
ch = inputf("Do you want to logout? (0-no/1-yes): ")
if "0" not in ch:
os.system("rm -rf data/cookie.txt")
main()
input("\n\n\t :> ")
else:
printf("You are not logged in. Please log in or sign up first.")
# Main function for the entire application
def main():
global username
while True:
clear_screen()
color1 = random.choice(bcolors)
color2 = random.choice(bcolors)
while color1 == color2:
color2 = random.choice(bcolors)
printf(color1)
print(
create_table(
f"\nWelcome to Accounting System\n ( by Intelliblitz Team ) \n"
)
)
printf(color2)
printf("\n\t1. Sign up\n")
printf("\t2. Log in\n")
printf("\t3. Quit\n")
choice = inputf("Enter your choice: ")
if choice == "1":
while True:
username = inputf("Enter your username: ")
if username:
break
else:
printf("\n\t[•] Username is Empty ! \n")
password = input_password(
"\n\t\033[1;97m[>] Enter your password ( length: 6):\033[0m ")
data = signup(users, username, password)
if type(data) == str:
print("")
printf(data)
inputf("")
else:
printf(
"\n\t[•] The password will be saved automatically ! ", base_delay=0.025)
inputf("")
accounting_main(data, username)
elif choice == "2":
try:
check, username = logged()
except Exception as b:
printf(
f"\n\t If the password is correct, the username is incorrect, try again \n"
)
os.system("rm -rf data/cookie.txt")
inputf("")
main()
if check:
accounting_main(check, username)
else:
while True:
username = inputf("Enter your username: ")
if username:
break
else:
printf("\n\t[•] Username is Empty !\n ")
password = input_password(
"\n\t\033[1;97m[>] Enter your password ( length: 6):\033[0m ", login=True)
data = login(users, username, password)
if type(data) == str:
print("")
printf(data)
inputf("")
else:
logged(username, password)
printf(
"\n\t[•] The password will be saved automatically ! ", base_delay=0.025)
inputf("")
accounting_main(data, username)
elif choice == "3":
break
# Entry point of the application
def run():
try:
main()
printf(
"\n [•] Thank you for using CLI Accounting system ( by Intelliblitz Team ). Goodbye!")
exit()
except:
pass
# Check if the script is being run directly
if __name__ == "__main__":
run()