-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.py
837 lines (737 loc) · 25.2 KB
/
functions.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
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
import time
from typing import Callable, TypeVar
from os import mkdir, makedirs, rmdir
from shutil import rmtree
from colors import *
from exceptions import *
import re
import readchar
import sys
from security import *
NoneOrStr = TypeVar('NoneOrStr', None, str)
NoneOrStrOrInt = TypeVar('NoneOrStrOrInt', None, str, int)
ListOrString = TypeVar('ListOrString', list, str)
def colorprompt(prompt: str, out=sys.stdout, char_color=fore["reset"]):
"""
This Will Act Like Input. But Characters That User Enters Will Be Colored :)
Args :
* prompt -> The Text For Print And Wait For Input.
* out -> Just Standard Output. DO NOT TOUCH THIS :/
* char_color -> The Color Of Character. Each Character Will Have This
Color.
"""
out.write(prompt)
out.flush()
password = ""
while True:
ch = str(readchar.readchar(), encoding='UTF-8')
if ch == '\r':
break
elif ch == '\b':
out.write('\b \b')
password = password[0:len(password)-1]
out.flush()
elif ch == "\x03":
print("\n")
raise KeyboardInterrupt("You Pressed Ctrl+C")
else:
password += ch
out.write(char_color + ch + fore["reset"])
out.flush()
print()
return password
def passprompt(prompt: str, out=sys.stdout, mask_color=fore["reset"], mask='*') -> str:
"""
This Will Get Password And Replace Characters With A Mask For Example '*'.
Args :
* prompt -> The Text For Print And Wait For Input.
* out -> Just Standard Output. DO NOT TOUCH THIS :/
* mask_color -> The Color Of Mask. For Example You Can Print Red Stars For
Each Character :))
* mask -> The Mask. Every Character That User Type, Will Be Replaced With
This Character :)
"""
out.write(prompt)
out.flush()
password = ""
while True:
ch = str(readchar.readchar(), encoding='UTF-8')
if ch == '\r':
break
elif ch == '\b':
out.write('\b \b')
password = password[0:len(password)-1]
out.flush()
elif ch == "\x03":
print("\n")
raise KeyboardInterrupt("You Pressed Ctrl+C")
else:
password += ch
out.write(mask_color + mask + fore["reset"])
out.flush()
print()
return password
def escape_translator(target, char: str) -> list:
"""
This Function Will Help You To Recover Escaped Characters That Wrongly Splitted.
Args :
* target -> A List Of Splitted String/ A String That You Want To Escape.
* char -> The Character That You Want To Escape.
Example :
```escape_translator("Hello Lets Escape All < That Have \ Like \< . All \< Will Be Escaped.","<")```
Out :
`['Hello Lets Escape All ', ' That Have \\ Like \\< . All \\< Will Be Escaped.']`
"""
if type(target) == str:
target = target.split(char)
elif type(target) == list:
pass
else:
raise TypeError("Type Should Be List Or String.")
ans = []
escape = False
for i in target:
print(i, ans)
if i[-1] == "\\":
if escape:
ans[-1] = ans[-1] + char + i
else:
ans.append(i)
escape = True
else:
if escape:
ans[-1] = ans[-1] + char + i
else:
ans.append(i)
escape = False
return ans
def colorize(string: str) -> str:
"""
It Will Colorize The Input.
Example :
```colorize("(Fore.GREEN)[Hello !]")```
Output :
* Green Foreground -> |Hello !|
Possible Colors:
```
fore = {
"green" : Fore.GREEN,
"black":Fore.BLACK,
"red":Fore.RED,
"yellow":Fore.YELLOW,
"blue":Fore.BLUE,
"cyan":Fore.CYAN,
"light_black":Fore.LIGHTBLACK_EX,
"light_blue":Fore.LIGHTBLUE_EX,
"light_cyan":Fore.LIGHTCYAN_EX,
"light_green":Fore.LIGHTGREEN_EX,
"light_magenta":Fore.LIGHTMAGENTA_EX,
"light_red":Fore.LIGHTRED_EX,
"light_white":Fore.LIGHTWHITE_EX,
"light_yellow":Fore.LIGHTYELLOW_EX,
"magenta":Fore.MAGENTA,
"reset":Fore.RESET,
"white":Fore.WHITE
}
back = {
"green":Back.GREEN,
"black":Back.BLACK,
"red":Back.RED,
"yellow":Back.YELLOW,
"blue":Back.BLUE,
"cyan":Back.CYAN,
"light_black":Back.LIGHTBLACK_EX,
"light_blue":Back.LIGHTBLUE_EX,
"light_cyan":Back.LIGHTCYAN_EX,
"light_green":Back.LIGHTGREEN_EX,
"light_magenta":Back.LIGHTMAGENTA_EX,
"light_red":Back.LIGHTRED_EX,
"light_white":Back.LIGHTWHITE_EX,
"light_yellow":Back.LIGHTYELLOW_EX,
"magenta":Back.MAGENTA,
"reset":Back.RESET,
"white":Back.WHITE
}
```
You Can Always Access The Colors Like That :
* pysha.fore[...]
* pysha.back[...]
"""
data = re.findall("\(Back|\(Fore\.[A-Z]*\)\[[^\[\]]*\]", string)
print(data)
for i in data:
tp = i.split('.')[0][1:].strip()
colr = i.split('.')[1].split(')')[0].strip()
text = '['.join(i.split('[')[1:])[:-1]
if tp.lower() == "fore":
c = getattr(Fore, colr)
string = string.replace(i, c + text + Fore.RESET)
elif tp.lower() == "back":
c = getattr(Back, colr)
string = string.replace(i, c + text + Back.RESET)
else:
raise TypeError("Type Must Be Back Or Fore.")
return string
def make_possibles(data):
"""
Tries To Get Possible Situations Of For Loops ( Max 3 Variable ).
"""
if len(data.keys()) == 1:
return list(range(list(data.values())[0]))
elif len(data.keys()) == 2:
temp = []
for i in range(list(data.values())[0]):
for j in range(list(data.values())[1]):
temp.append([i, j])
return temp
elif len(data.keys()) == 3:
temp = []
for i in range(list(data.values())[0]):
for j in range(list(data.values())[1]):
for z in range(list(data.values())[2]):
temp.append([i, j, z])
return temp
else:
pass
def display(temp: dict, string: str, c=True) -> None:
"""
Related To Loop Command. It Will Print String And Replace _i_ , _i++_ ... With The Value.
Args :
* temp -> Carries Variables.
* string -> The String Pattern That Should Be Printed In Output.
* c -> If Its True, Answer Will colorized. And Else Won't Be Colorized.
"""
ans = string
for i, j in temp.items():
ans = (ans.replace(f"_{i}_", str(j)).replace(
f"_{i}++_", str(j+1)).replace(f"_{i}--_", str(j-1)))
if not c:
print(ans)
else:
print(colorize(ans))
def get_ans(temp: dict, string: str, c=True) -> str:
"""
Related To Loop Command. It Will Get Input And Replace _i_ , _i++_ ... With The Value.
Args :
* temp -> Carries Variables.
* string -> The String Pattern That Should Be Printed In Output.
* c -> If Its True, Answer Will colorized. And Else Won't Be Colorized.
"""
ans = string
for i, j in temp.items():
ans = (ans.replace(f"_{i}_", str(j)).replace(
f"_{i}++_", str(j+1)).replace(f"_{i}--_", str(j-1)))
if not c:
return input(ans)
else:
return input(colorize(ans))
def loop(cmd: str, mode='p', c=True) -> NoneOrStr:
"""
All Descriptions From This Function Came In `classes.py` - command Class.
"""
if mode == "p": # Print Mode
alls = cmd.split(">")[0][1:]
string = cmd.split("{")[1][:-1]
arr_data = []
dic_tar = {}
for i in alls.split(','):
itemp = i.split(':')
arr_data.append(itemp[0].strip())
dic_tar[itemp[0].strip()] = int(itemp[1].strip())
if len(dic_tar.keys()) >= 4:
raise LoopError(
"Loops With 4 Or More Variables Are Not Supported In This Version.")
tars = make_possibles(dic_tar)
for i in tars:
temp = {}
if not (type(i) == int) and len(i) == 2:
temp = {arr_data[0]: i[0], arr_data[1]: i[1]}
elif not (type(i) == int) and len(dic_tar) == 3:
temp = {arr_data[0]: i[0], arr_data[1]: i[1], arr_data[2]: i[2]}
else:
temp = {arr_data[0]: i[0]}
display(temp, string, c)
elif mode == 'i': # input Mode
alls = cmd.split(">")[0][1:]
string = cmd.split("{")[1][:-1]
arr_data = []
dic_tar = {}
for i in alls.split(','):
itemp = i.split(':')
arr_data.append(itemp[0].strip())
dic_tar[itemp[0].strip()] = int(itemp[1].strip())
if len(dic_tar.keys()) >= 4:
raise LoopError(
"Loops With 4 Or More Variables Are Not Supported In This Version.")
tars = make_possibles(dic_tar)
x = 0
y = 0
z = 0
ls = []
if len(dic_tar) == 2:
x = (list(dic_tar.values())[0])
y = (list(dic_tar.values())[1])
ls = [["" for _ in range(y)] for __ in range(x)]
elif len(dic_tar) == 1:
x = (list(dic_tar.values())[0])
ls = ["" for _ in range(x)]
elif len(dic_tar) == 3:
x = (list(dic_tar.values())[0])
y = (list(dic_tar.values())[1])
z = (list(dic_tar.values())[2])
ls = [[["" for _ in range(z)] for __ in range(y)]
for ___ in range(x)]
x = 0
y = 0
z = 0
for i in tars:
temp = {}
if not (type(i) == int) and len(i) == 2:
temp = {arr_data[0]: i[0], arr_data[1]: i[1]}
try:
ls[x][y] = get_ans(temp, string, c)
ls[x][y + 1]
y += 1
except:
try:
ls[x + 1][y]
x += 1
y = 0
except:
pass
elif not (type(i) == int) and len(i) == 3:
temp = {arr_data[0]: i[0], arr_data[1]: i[1], arr_data[2]: i[2]}
try:
ls[x][y][z] = get_ans(temp, string, c)
ls[x][y][z + 1]
z += 1
except:
try:
ls[x][y + 1][z]
y += 1
z = 0
except:
try:
ls[x + 1][y][z]
x += 1
y = 0
z = 0
except:
pass
else:
temp = {arr_data[0]: i}
try:
ls[x] = get_ans(temp, string, c)
ls[x]
x += 1
except:
pass
return ls
else:
raise ModeError("Mode Should Be 'p' Or 'i' !")
def condition(check: str, p=True, **kwargs) -> NoneOrStrOrInt:
"""
Descrioptions Are Available In 'classes.py' And In command Class.
"""
if not re.match("""(\"?)[ -~]+(\"?)(>|<|==|>=|<=)(\"?)[ -~]+(\"?)\?(\"?)[ -~]+(\"?):(\"?)[ -~]+(\"?)""", ''.join(check.split(' '))):
raise ConditionError("An Error In Parsing Condition :(")
if "eval" in check:
if not check[check.find("eval") - 1:].startswith("\eval"):
raise SecurityError("Using This Funcion Is Forbidden.")
if "exec" in check:
if not check[check.find("exec") - 1:].startswith("\exec"):
raise SecurityError("Using This Funcion Is Forbidden.")
index_of_ok_sign = not_between_index("?", check)
p1 = index_split(check, index_of_ok_sign)[0].strip()
p2 = index_split(check, index_of_ok_sign)[1].strip()
ans = eval(p1, kwargs, {})
index_of_ok_sign = not_between_index(":", p2)
ok = index_split(p2, index_of_ok_sign)[0].strip()
not_ok = index_split(p2, index_of_ok_sign)[1].strip()
if ans:
if p:
print(eval(ok, kwargs))
else:
return eval(ok, kwargs)
else:
if p:
print(eval(not_ok, kwargs))
else:
return eval(not_ok, kwargs)
def write_file(file_name: str, text: ListOrString) -> bool:
"""
You Can Write Into A File :)
Args :
* file_name
* text
Returns True If Its Successfully Done, Else Return False
"""
if type(text) == str:
try:
a = open(file_name, "w")
a.write(text)
a.close()
return True
except:
return False
elif type(text) == list:
try:
a = open(file_name, "w")
a.writelines(text)
a.close()
return True
except:
return False
def read_file(file_name: str, mode="s") -> ListOrString:
"""
You Can Read Data From A File :)
Args :
* file_name
* mode(Default:'s') : The Mode Can Be 's' Or 'l' Means List Or String.
If You Want To Get Output As String Mode 's' Will
Be Good For You And If You Want To Get As list
Mode 'l' Is Good For You.
Returns list of lines Of The File If mode Is 'l', string of lines
If mode is 's'.
"""
try:
a = open(file_name, "r")
d = a.readlines()
a.close()
if mode == "s":
return "".join(d)
elif mode == "l":
return d
else:
raise ModeError(
f"Mode {mode} Not Found ! Mode Should Be 's'(string) Or 'l'(List)")
except:
return ""
def append_file(file_name: str, text: str) -> bool:
"""
You Can Append to A File.
Args :
* file_name
* text
Returns True If Its Successfully Done, Else Return False
"""
if type(text) == str:
try:
a = open(file_name, "a")
a.write(text)
a.close()
return True
except:
return False
elif type(text) == list:
try:
a = open(file_name, "a")
a.writelines(text)
a.close()
return True
except:
return False
def create_dir(dir_name: str, create_parents=False) -> bool:
"""
Tries To Create A Directory.
Args :
* dir_name -> Directory Name. You Can Pass An String Like 'test' Or
'test/test1/test2' For Directory. But If You Want To
Make Parents Too, You Have To Pass Next Argument Manually
Too.
* create_parents(Default:False) -> If Its False, Parents Will Not Be
Created If They Are Not Exists.
And If Its True, Parents Will Be
Created Too !
Returns True If Its Successfully Done, Else Return False
"""
if create_parents:
try:
makedirs(dir_name)
return True
except:
return False
else:
try:
mkdir(dir_name)
return True
except:
return False
def replace_in_file(file_name: str, data_to_replace: dict) -> bool:
"""
Tries To Replace A Dictionary.
Args :
* file_name -> File Name. You Can Pass File Name That You Want Data
To Change.
* data_to_replace -> Data That You Want To Replace As Dictinary.
For Example : {'test':'test1'} Will Replace All
'test' With 'test1' In The File.
Returns True If Its Successfully Done, Else Return False
"""
f = open(file_name, "r")
data = f.readlines()
f.close()
for i in data:
for key, value in data_to_replace.items():
if key in i:
i = i.replace(key, value)
f = open(file_name, "w")
f.writelines(data)
f.close()
def rm_dir(dir_name: str, force=False) -> bool:
"""
Tries To Remove A Directory.
Args :
* dir_name -> Directory Name. You Can Pass An String Like 'test' Or
'test/test1/test2' For Directory. If You Want To Force
Remove That Childs Will Remove Too, Pass Next Argument
Manually.
* force(Default:False) -> If Its False And If directory Has Childs,
Directory Won't Be Removed.But If Its False
Doesn't Matter What We Are Cold-Blood Murderes
And We Kill Them All :)
Returns True If Its Successfully Done, Else Return False
"""
if not force:
try:
rmdir(dir_name)
return True
except:
return False
else:
try:
rmtree(dir_name)
return True
except:
return False
def between(string, string_to_check, start_sign='"', end_sign='"', exact=False, case_sensetive=True):
"""
Checks If An String Exists Between Two Characters In Another String.
Args :
* string -> A Simple String. (We Need To Check If This String Exists
In Another String Or Not) For Example If You Want To Check
If 'hello' is between " Characters, You Need To Pass hello
As This Argument.
* string_to_check -> A Big String That We Want To Check And Dive In :)
For Example 'hello My Name Is Arshia And "hello" Is
ok Now As i think :)' And Pass It As This Argument.
* start_sign -> This Should Be The Start Character That You Are Looking For.
For Example You Can Pass " As This Argument ( Continue Of Previous
Part Example ) . But In Another Example That You Want To Check A Tag For
Example html Tag You Can Pass "<" As Start.
* end_sign -> This Should Be The Start Character That You Are Looking For.
For Example You Can Pass " As This Argument ( Continue Of Previous
Part Example ) . Continue Of Tag Example You Can Pass ">" As End.
* exact -> Basically, Checks For <html> Not <*html*>.This Argument Will Check
For exact Value. For Example If This Option Was False And You Want
To Check For Tags In String "This <html Test Fake Text> Is Ok." It
Will Return True But If This Option Is True,For That String Will
Return False. Because It Looks For Exact "<html>" Not < Then Anything
Then html Then Again Anything And > Character.
* case_sensetive -> If Its True, Lower Case Or Upper Case In Words Are Important.
For Example If Its True, "Html" Is Different From "html" But
If Its False, "Html" And "html" Are Equal.
Example :
1. between(":",'The : Is Not Between "" Chars.','"') Returns :
1. False
2. between(":",'The ":" Is Between "" Chars !','"') Returns :
2. True
Returns True If Its Found In target Text Else, Returns False.
"""
is_in = False
ts = ""
for c, i in enumerate(string_to_check):
if is_in:
if i == end_sign:
is_in = False
ts = ""
else:
if i == start_sign:
is_in = True
if is_in:
ts += i
if not exact:
if case_sensetive:
if string in ts:
return True
else:
if string.lower() in ts.lower():
return True
else:
if case_sensetive:
if start_sign + string + end_sign in ts:
return True
else:
if (start_sign + string + end_sign).lower() in ts.lower():
return True
return False
def between_index(string, string_to_check, start_sign='"', end_sign='"', exact=False, case_sensetive=True, start=0):
"""
Acts Like Between Function But It Will Return Index Insted Of Boolean Value.
"""
is_in = False
ts = ""
for c, i in enumerate(string_to_check[start:]):
if is_in:
if i == end_sign:
is_in = False
ts = ""
else:
if i == start_sign:
is_in = True
if is_in:
ts += i
if not exact:
if case_sensetive:
if string in ts:
return (c - len(string) + 1 + start)
else:
if string.lower() in ts.lower():
return (c - len(string) + 1 + start)
else:
if case_sensetive:
if start_sign + string + end_sign in ts:
return (c - len(string) + 1 + start)
else:
if (start_sign + string + end_sign).lower() in ts.lower():
return (c - len(string) + 1 + start)
return -1
def not_between_index(string, string_to_check, start_sign='"', end_sign='"', case_sensetive=True, start=0):
"""
Reverse Of Between Plus Index Of Target.
Args :
* string -> A Simple String. (We Need To Check If This String Exists
In Another String Or Not) For Example If You Want To Check
If 'hello' is not between " Characters, You Need To Pass hello
As This Argument.
* string_to_check -> A Big String That We Want To Check And Dive In :)
For Example 'hello My Name Is Arshia And "hello" Is
ok Now As i think :)' And Pass It As This Argument.
* start_sign -> This Should Be The Start Character That You Are Looking For.
For Example You Can Pass " As This Argument ( Continue Of Previous
Part Example ) . But In Another Example That You Want To Check Text
That Does Not In A Tag For Example html Tag You Can Pass "<" As Start.
* end_sign -> This Should Be The Start Character That You Are Looking For.
For Example You Can Pass " As This Argument ( Continue Of Previous
Part Example ) . Continue Of Tag Example You Can Pass ">" As End.
* case_sensetive -> If Its True, Lower Case Or Upper Case In Words Are Important.
For Example If Its True, "Html" Is Different From "html" But
If Its False, "Html" And "html" Are Equal.
Example :
* not_between_index(":",'Arshia Said : "Hello ! There Is : Hiding Here :)"','"','"')
* Returns :
`12`
* not_between_index(":",'":" Is Not Out Of "" Sign. But Now : It Is.','"','"')
* Returns :
`35`
Returns True If Its Found Out Of target Sign, Else Returns False.
"""
is_in = False
ts = ""
for c, i in enumerate(string_to_check[start:]):
if is_in:
if i == end_sign:
is_in = False
else:
if i == start_sign:
is_in = True
ts = ""
if not is_in:
ts += i
if case_sensetive:
if string in ts:
return (c - len(string) + 1 + start)
else:
if string.lower() in ts.lower():
return (c - len(string) + 1 + start)
return -1
def index_split(string, ind):
"""
Split String By Index.
Example :
```index_split("Hello My Name Is Arshia",10)```
Returns :
```['Hello My N', 'me Is Arshia']```
"""
return [string[:ind], string[ind + 1:]]
def delay_loop(delay: int, func: Callable, count: int = -1, *args, **kwargs):
"""
This Function Will Try To Loop A Function In Specific count/infinite count.
Example :
* delay_loop(10,func,5,args,kwargs)
In Every 10 Seconds Function func(args,kwargs) Will Be Called 5 Times.
"""
if count == -1:
index = 0
while True:
time.sleep(delay)
index += 1
func(index, *args, **kwargs)
else:
for index in range(count):
time.sleep(delay)
func(index, *args, **kwargs)
def merge(*args, force_list=False, dont_change=False):
"""
This Function Will Merge Some List Or Some Dict Or Some Dict And List !
Example :
```merge(["a","b"],{"c":"d","e":"f"},["g","h"])```
Returns :
```{"a":"","b":"","c":"","d":"","e":"","f":"","g":"","h":""}```
Example :
```merge(["a","b"],{"c":"d","e":"f"},["g","h"],force_list=True)```
Returns :
```["a","b","c","e","d","f","g","h"]```
Example :
```merge(["a","b"],{"c":"d","e":"f"},["g","h"],force_list=True,dont_change=True)```
Returns :
```["a","b","c","d","e","f","g","h"]```
Example:
```merge(["a","b"],["c","d","e","f"],["g","h"])```
Returns :
```["a","b","c","d","e","f","g","h"]```
In Every 10 Seconds Function func(args,kwargs) Will Be Called 5 Times.
"""
if list(filter(lambda x: type(x) == dict, args)):
if not force_list:
ans = {}
for i in args:
if type(i) == list:
ans[i] = ""
elif type(i) == dict:
ans.update(i)
return ans
else:
ans = []
for i in args:
if type(i) == list:
ans.extend(i)
elif type(i) == dict:
if dont_change:
for a, b in i.items():
ans.extend([a, b])
else:
ans.extend(i.keys())
ans.extend(i.values())
return ans
else:
ans = []
for i in args:
ans.extend(i)
return ans
def make_array(dimentions):
"""
Make An Array In Dimentions That You Gave.
"""
ans = [None for _ in range(dimentions[-1])]
for i in dimentions[:-1][::-1]:
ans = [ans for _ in range(i)]
return ans
def set_array(array, dimentions, value):
"""
Set An Array Value In Complicated Dimentions.
"""
for i in dimentions:
array = array[i]
array = value
return array