-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalBasics.py
More file actions
468 lines (464 loc) · 38.4 KB
/
TerminalBasics.py
File metadata and controls
468 lines (464 loc) · 38.4 KB
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
from sys import stdin, stderr
from typing import Any
from string import digits, ascii_letters
from colorama import Fore
import datetime
def createtable(*args: list | str, space: int, title: bool = False, format: int = 1, export:str = None, foot:str = None, nullentity:str = "__NULL__",
leftbodyborder:str = "|", rightbodyborder:str = "|", lefttitleborder:str = "|", righttitleborder:str = "|",
topborder:str = "=", middleborder:str = "=", underborder:str = "=", head:str = None, leftheadborder:str = "|", rightheadborder:str = "|",
leftfootborder:str = "|", rightfootborder:str = "|") -> None:
"""
Creates a table in terminal that based on the row lists you give.
The example of usage is shown in ExampleFor_createtable.py
"""
class TableNeeds:
@staticmethod
def findlongestlist() -> int:
longestlist = 0
for lists in args:
if len(lists) > longestlist:
longestlist = len(lists)
else: continue
return longestlist
@staticmethod
def listobjectlongs(sumobjectlen:str, strlists:list, i:int) -> None:
if i < len(strlists):
sumobjectlen += strlists[i] + " " * (space - len(strlists[i]))
else:
sumobjectlen += nullentity + " " * (space - len(nullentity))
return sumobjectlen
@staticmethod
def listobjectcompiler(sumobjectlen, strlists, i) -> int:
if i < len(strlists):
sumobjectlen = len(sumobjectlen.removesuffix(" " * (space - len(strlists[i]))))
else:
sumobjectlen = len(sumobjectlen.removesuffix(" " * (space - len(nullentity))))
return sumobjectlen
@staticmethod
def findlongestlistobjectformat1(longestlist) -> int:
longestlistobjectformat1 = 0
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
sumobjectlen = ""
for i in range(longestlist):
sumobjectlen = TableNeeds.listobjectlongs(sumobjectlen, strlists, i)
sumobjectlen = TableNeeds.listobjectcompiler(sumobjectlen, strlists, i)
if sumobjectlen > longestlistobjectformat1:
longestlistobjectformat1 = sumobjectlen
else:continue
return longestlistobjectformat1
@staticmethod
def findlongestlistobjectformat2(longestlist) -> int:
longestlistobjectformat2 = 0
for i in range(longestlist):
sumobjectlen = ""
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
sumobjectlen = TableNeeds.listobjectlongs(sumobjectlen, strlists, i)
sumobjectlen = TableNeeds.listobjectcompiler(sumobjectlen, strlists, i)
if sumobjectlen > longestlistobjectformat2:
longestlistobjectformat2 = sumobjectlen
else:continue
return longestlistobjectformat2
class TablePatterns:
@staticmethod
def tablepattern1(strlists, longestlist, i, longestlistobjectformat1, listlong, titled = True):
if i < len(strlists):
if i != longestlist - 1:
print(strlists[i] + " " * (space - len(strlists[i])), end="", flush=True)
listlong += len(strlists[i] + " " * (space - len(strlists[i])))
return listlong
else:
print(strlists[i], end="", flush=True)
listlong += len(strlists[i])
print(" " * (longestlistobjectformat1 - listlong), end=f" {rightbodyborder}", flush=True) if titled == True else print(" " * (longestlistobjectformat1 - listlong), end=f" {righttitleborder}", flush=True)
return listlong
else:
if i != longestlist - 1:
print(nullentity + " " * (space - len(nullentity)), end="", flush=True)
listlong += len(nullentity + " " * (space - len(nullentity)))
return listlong
else:
print(nullentity, end="", flush=True)
listlong += len(nullentity)
print(" " * (longestlistobjectformat1 - listlong), end=f" {rightbodyborder}", flush=True) if titled == True else print(" " * (longestlistobjectformat1 - listlong), end=f" {righttitleborder}", flush=True)
return listlong
@staticmethod
def tablepattern2(strlists, i, longestlistobjectformat2, listlong, listnumber, titled = True) -> Any:
if i < len(strlists):
if listnumber != len(args):
print(strlists[i] + " " * (space - len(strlists[i])), end="", flush=True)
listlong += len(strlists[i] + " " * (space - len(strlists[i])))
listnumber += 1
yield listnumber
yield listlong
else:
print(strlists[i], end="", flush=True)
listlong += len(strlists[i])
print(" " * (longestlistobjectformat2 - listlong), end=f" {rightbodyborder}", flush=True) if titled == True else print(" " * (longestlistobjectformat2 - listlong), end=f" {righttitleborder}", flush=True)
yield listnumber
yield listlong
else:
if listnumber != len(args):
print(nullentity + " " * (space - len(nullentity)), end="", flush=True)
listlong += len(nullentity + " " * (space - len(nullentity)))
listnumber += 1
yield listnumber
yield listlong
else:
print(nullentity, end="", flush=True)
listlong += len(nullentity)
print(" " * (longestlistobjectformat2 - listlong), end=f" {rightbodyborder}", flush=True) if titled == True else print(" " * (longestlistobjectformat2 - listlong), end=f" {righttitleborder}", flush=True)
yield listnumber
yield listlong
class TableFormatsNoTitle:
@staticmethod
def printtableformat1(longestlist, longestlistobjectformat1) -> None:
if head != None:
print(topborder * (longestlistobjectformat1 + 2 + len(leftheadborder) + len(rightheadborder)), flush=True)
print(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else print(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder, flush=True)
print(topborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)), end="", flush=True)
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
print(f"\n{leftbodyborder} ", end="", flush=True)
listlong = 0
for i in range(longestlist):
listlong = TablePatterns.tablepattern1(strlists, longestlist, i, longestlistobjectformat1, listlong)
print(flush=True)
print(underborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)), flush=True)
if foot != None:
print()
print(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder) if len(foot) % 2 == 0 else print(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder, flush=True)
print(underborder * (longestlistobjectformat1 + 2 + len(leftfootborder) + len(rightfootborder)), flush=True)
@staticmethod
def printtableformat2(longestlist, longestlistobjectformat2) -> None:
if head != None:
print(topborder * (longestlistobjectformat2 + 2 + len(leftheadborder) + len(rightheadborder)), flush=True)
print(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else print(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder, flush=True)
print(topborder * (longestlistobjectformat2 + 2 + len(leftheadborder) + len(rightheadborder)), end="", flush=True)
for i in range(longestlist):
print(f"\n{leftbodyborder} ", end="", flush=True)
listlong = 0
listnumber = 1
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
values = TablePatterns.tablepattern2(strlists, i, longestlistobjectformat2, listlong, listnumber)
listnumber = next(values)
listlong = next(values)
print(flush=True)
print(underborder * (longestlistobjectformat2 + 2 + len(leftbodyborder) + len(rightbodyborder)), end="", flush=True)
if foot != None:
print()
print(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder) if len(foot) % 2 == 0 else print(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder, flush=True)
print(underborder * (longestlistobjectformat2 + 2 + len(leftfootborder) + len(rightfootborder)), flush=True)
class TableFormatWithTitle:
@staticmethod
def printtableformat1(longestlist, longestlistobjectformat1) -> None:
titled = False
if head != None:
print()
print(topborder * (longestlistobjectformat1 + 2 + len(leftheadborder) + len(rightheadborder)), flush=True)
print(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else print(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder)
print(topborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)), end="", flush=True)
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
print(f"\n{leftbodyborder} ", end="", flush=True) if titled == True else print(f"\n{lefttitleborder} ", end="", flush=True)
listlong = 0
for i in range(longestlist):
listlong = TablePatterns.tablepattern1(strlists, longestlist, i, longestlistobjectformat1, listlong, titled)
if titled == False:
print(flush=True)
print(middleborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)), end="", flush=True)
titled = True
print(flush=True)
print(underborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)), flush=True)
if foot != None:
print(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder) if len(foot) % 2 == 0 else print(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder, flush=True)
print(underborder * (longestlistobjectformat1 + 2 + len(leftfootborder) + len(rightfootborder)), flush=True)
@staticmethod
def printtableformat2(longestlist, longestlistobjectformat2) -> None:
titled = False
if head != None:
print()
print(topborder * (longestlistobjectformat2 + 2 + len(leftheadborder) + len(rightheadborder)), flush=True)
print(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else print(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder)
print(topborder * (longestlistobjectformat2 + 2 + len(leftbodyborder) + len(rightbodyborder)), end="", flush=True)
for i in range(longestlist):
print(f"\n{leftbodyborder} ", end="", flush=True) if titled == True else print(f"\n{lefttitleborder} ", end="", flush=True)
listlong = 0
listnumber = 1
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
values = TablePatterns.tablepattern2(strlists, i, longestlistobjectformat2, listlong, listnumber, titled)
listnumber = next(values)
listlong = next(values)
if titled == False:
print(flush=True)
print(middleborder * (longestlistobjectformat2 + 2 + len(lefttitleborder) + len(righttitleborder)), end="", flush=True)
titled = True
print(flush=True)
print(underborder * (longestlistobjectformat2 + 2 + len(leftbodyborder) + len(rightbodyborder)), end="", flush=True)
if foot != None:
print()
print(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder) if len(foot) % 2 == 0 else print(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder, flush=True)
print(underborder * (longestlistobjectformat2 + 2 + len(leftfootborder) + len(rightfootborder)), flush=True)
class ExportTable:
class TablePatternsExport:
@staticmethod
def tablepattern1export(strlists, longestlist, i, longestlistobjectformat1, listlong, titled = True):
try:
if i < len(strlists):
if i != longestlist - 1:
with open(f"{export}", "a") as file:
file.write(strlists[i] + " " * (space - len(strlists[i])))
listlong += len(strlists[i] + " " * (space - len(strlists[i])))
return listlong
else:
with open(f"{export}", "a") as file:
file.write(strlists[i])
listlong += len(strlists[i])
file.write(" " * (longestlistobjectformat1 - listlong) + f" {rightbodyborder}") if titled else file.write(" " * (longestlistobjectformat1 - listlong) + f" {righttitleborder}")
return listlong
else:
if i != longestlist - 1:
with open(f"{export}", "a") as file:
file.write(nullentity + " " * (space - len(nullentity)))
listlong += len(nullentity + " " * (space - len(nullentity)))
return listlong
else:
with open(f"{export}", "a") as file:
file.write(nullentity)
listlong += len(nullentity)
file.write(" " * (longestlistobjectformat1 - listlong) + f" {rightbodyborder}") if titled else file.write(" " * (longestlistobjectformat1 - listlong) + f" {righttitleborder}")
return listlong
except:
print(Fore.RED + "An error occured while exporting the table")
@staticmethod
def tablepattern2export(strlists, i, longestlistobjectformat2, listlong, listnumber, titled = True) -> Any:
try:
if i < len(strlists):
if listnumber != len(args):
with open(f"{export}", "a") as file:
file.write(strlists[i] + " " * (space - len(strlists[i])))
listlong += len(strlists[i] + " " * (space - len(strlists[i])))
listnumber += 1
yield listnumber
yield listlong
else:
with open(f"{export}", "a") as file:
file.write(strlists[i])
listlong += len(strlists[i])
file.write(" " * (longestlistobjectformat2 - listlong) + f" {rightbodyborder}") if titled else file.write(" " * (longestlistobjectformat2 - listlong) + f" {righttitleborder}")
yield listnumber
yield listlong
else:
if listnumber != len(args):
with open(f"{export}", "a") as file:
file.write(nullentity + " " * (space - len(nullentity)))
listlong += len(nullentity + " " * (space - len(nullentity)))
listnumber += 1
yield listnumber
yield listlong
else:
with open(f"{export}", "a") as file:
file.write(nullentity)
listlong += len(nullentity)
file.write(" " * (longestlistobjectformat2 - listlong) + f" {rightbodyborder}") if titled else file.write(" " * (longestlistobjectformat2 - listlong) + f" {righttitleborder}")
yield listnumber
yield listlong
except:
print(Fore.RED + "An error occured while exporting the table")
class ExportTableNoTitle:
@staticmethod
def exporttableformat1(longestlist, longestlistobjectformat1) -> None:
try:
if head != None:
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat1 + 2 + len(leftheadborder) + len(rightheadborder)) + "\n")
file.write(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else file.write(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder)
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)))
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
with open(f"{export}", "a") as file:
file.write(f"\n{leftbodyborder} ")
listlong = 0
for i in range(longestlist):
listlong = ExportTable.TablePatternsExport.tablepattern1export(strlists, longestlist, i, longestlistobjectformat1, listlong)
with open(f"{export}", "a") as file:
file.write("\n" + underborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)))
if foot != None:
with open(f"{export}", "a") as file:
file.write("\n")
file.write(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n") if len(foot) % 2 == 0 else file.write(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n")
file.write(underborder * (longestlistobjectformat1 + 2 + len(leftfootborder) + len(rightfootborder)) + "\n")
print(Fore.GREEN + f"The table has been created at '{export}' file | {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}")
except:
print(Fore.RED + "An error occured while exporting the table")
@staticmethod
def exporttableformat2(longestlist, longestlistobjectformat2) -> None:
try:
if head != None:
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat2 + 2 + len(leftheadborder) + len(rightheadborder)) + "\n")
file.write(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else file.write(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder)
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat2 + 2 + len(leftbodyborder) + len(rightbodyborder)))
for i in range(longestlist):
with open(f"{export}", "a") as file:
file.write(f"\n{leftbodyborder} ")
listlong = 0
listnumber = 1
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
values = ExportTable.TablePatternsExport.tablepattern2export(strlists, i, longestlistobjectformat2, listlong, listnumber)
listnumber = next(values)
listlong = next(values)
with open(f"{export}", "a") as file:
file.write("\n")
file.write(underborder * (longestlistobjectformat2 + 2 + len(leftbodyborder) + len(rightbodyborder)))
if foot != None:
with open(f"{export}", "a") as file:
file.write("\n")
file.write(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n") if len(foot) % 2 == 0 else file.write(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n")
file.write(underborder * (longestlistobjectformat2 + 2 + len(leftfootborder) + len(rightfootborder)) + "\n")
print(Fore.GREEN + f"The table has been created at '{export}' file | {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}")
except:
print(Fore.RED + "An error occured while exporting the table")
class ExportTableWithTitle:
@staticmethod
def exporttableformat1(longestlist, longestlistobjectformat1) -> None:
try:
titled = False
if head != None:
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat1 + 2 + len(leftheadborder) + len(rightheadborder)) + "\n")
file.write(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else file.write(leftheadborder + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat1 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder)
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)))
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
with open(f"{export}", "a") as file:
file.write(f"\n{leftbodyborder} ")
listlong = 0
for i in range(longestlist):
listlong = ExportTable.TablePatternsExport.tablepattern1export(strlists, longestlist, i, longestlistobjectformat1, listlong)
if titled == False:
with open(f"{export}", "a") as file:
file.write("\n")
file.write(middleborder * (longestlistobjectformat1 + 2 + len(lefttitleborder) + len(righttitleborder)))
titled = True
with open(f"{export}", "a") as file:
file.write("\n")
file.write(underborder * (longestlistobjectformat1 + 2 + len(leftbodyborder) + len(rightbodyborder)))
if foot != None:
with open(f"{export}", "a") as file:
file.write("\n")
file.write(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n") if len(foot) % 2 == 0 else file.write(leftfootborder + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat1 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n")
file.write(underborder * (longestlistobjectformat1 + 2 + len(leftfootborder) + len(rightfootborder)) + "\n")
print(Fore.GREEN + f"The table has been created at '{export}' file | {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}")
except:
print(Fore.RED + "An error occured while exporting the table")
@staticmethod
def exporttableformat2(longestlist, longestlistobjectformat2) -> None:
try:
titled = False
if head != None:
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat2 + 2 + len(leftheadborder) + len(rightheadborder)) + "\n")
file.write(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder) if len(head) % 2 == 0 else file.write(leftheadborder + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2 + 1) + head + " " * int((longestlistobjectformat2 + len(leftheadborder) + len(rightheadborder)) / 2 - len(head) / 2) + rightheadborder)
with open(f"{export}", "a") as file:
file.write("\n" + topborder * (longestlistobjectformat2 + 2 + len(leftbodyborder) + len(rightbodyborder)))
for i in range(longestlist):
with open(f"{export}", "a") as file:
file.write(f"\n{leftbodyborder} ")
listlong = 0
listnumber = 1
for lists in args:
strlists = list(map(lambda x: nullentity if x == "" else str(x), lists))
values = ExportTable.TablePatternsExport.tablepattern2export(strlists, i, longestlistobjectformat2, listlong, listnumber)
listnumber = next(values)
listlong = next(values)
if titled == False:
with open(f"{export}", "a") as file:
file.write("\n")
file.write(middleborder * (longestlistobjectformat2 + 2 + len(lefttitleborder) + len(righttitleborder)))
titled = True
with open(f"{export}", "a") as file:
file.write("\n")
file.write(underborder * (longestlistobjectformat2 + 2 + len(leftbodyborder) + len(rightbodyborder)))
if foot != None:
with open(f"{export}", "a") as file:
file.write("\n")
file.write(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n") if len(foot) % 2 == 0 else file.write(leftfootborder + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2 + 1) + foot + " " * int((longestlistobjectformat2 + len(leftfootborder) + len(rightfootborder)) / 2 - len(foot) / 2) + rightfootborder + "\n")
file.write(underborder * (longestlistobjectformat2 + 2 + len(leftfootborder) + len(rightfootborder)) + "\n")
print(Fore.GREEN + f"The table has been created at '{export}' file | {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}")
except:
print(Fore.RED + "An error occured while exporting the table")
if export == None:
if format == 1 and title == False:
TableFormatsNoTitle.printtableformat1(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat1(TableNeeds.findlongestlist()))
elif format == 2 and title == False:
TableFormatsNoTitle.printtableformat2(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat2(TableNeeds.findlongestlist()))
elif format == 1 and title == True:
TableFormatWithTitle.printtableformat1(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat1(TableNeeds.findlongestlist()))
elif format == 2 and title == True:
TableFormatWithTitle.printtableformat2(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat2(TableNeeds.findlongestlist()))
else:
if format == 1 and title == False:
ExportTable.ExportTableNoTitle.exporttableformat1(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat1(TableNeeds.findlongestlist()))
elif format == 2 and title == False:
ExportTable.ExportTableNoTitle.exporttableformat2(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat2(TableNeeds.findlongestlist()))
elif format == 1 and title == True:
ExportTable.ExportTableWithTitle.exporttableformat1(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat1(TableNeeds.findlongestlist()))
elif format == 2 and title == True:
ExportTable.ExportTableWithTitle.exporttableformat2(TableNeeds.findlongestlist(), TableNeeds.findlongestlistobjectformat2(TableNeeds.findlongestlist()))
def onlystr(*args: str | list, remove_spaces:bool = False) -> str | list[str]:
"""
This function takes strings or lists as parameter and deletes every non-string element from it.
Please use this function with 'next()' method.
"""
for inputs in args:
if isinstance(inputs, str):
yield inputs.translate(str.maketrans("", "", digits)).replace(" ", "") if remove_spaces else inputs.translate(str.maketrans("", "", digits))
elif isinstance(inputs, list):
strlist = [x for x in list(map(lambda x: str(x).translate(str.maketrans("", "", digits)).replace(" ", "") if remove_spaces else str(x).translate(str.maketrans("", "", digits)), inputs)) if str(x) != ""]
yield strlist
def onlyint(*args: str | list, remove_spaces:bool = False) -> int | list[int]:
"""
This function takes strings or lists as parameter and deletes every non-integer element from it.
Please use this function with 'next()' method.
"""
for inputs in args:
if isinstance(inputs, str):
yield int(inputs.translate(str.maketrans("", "", ascii_letters)).replace(" ", "")) if remove_spaces else int(inputs.translate(str.maketrans("", "", ascii_letters)))
if isinstance(inputs, list):
intlist = [int(x) for x in list(map(lambda x: str(x).translate(str.maketrans("", "", ascii_letters)).replace(" ", "") if remove_spaces else str(x).translate(str.maketrans("", "", ascii_letters)), inputs)) if str(x) != ""]
yield intlist
def strdenied(inputmassage: str, deniedmassage: str) -> int:
"""
This function continues to ask for an input that only contains integer elements
"""
print(inputmassage, end="", flush=True)
for inputs in stdin:
try:
assert inputs.replace("\n", "").isdigit() == True
break
except AssertionError:
stderr.write(deniedmassage)
stderr.flush()
return int(inputs)
def intdenied(inputmassage: str, deniedmassage: str) -> str:
"""
This function continues to ask for an input that only contains string elements
"""
print(inputmassage, end="", flush=True)
for inputs in stdin:
try:
for x in inputs.replace("\n", ""):
assert x.isdigit() != True
break
except AssertionError:
stderr.write(deniedmassage)
stderr.flush()
return inputs.replace("\n", "")