-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrklpy_lib.py
2044 lines (1737 loc) · 68.8 KB
/
rklpy_lib.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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
def clc():
print('\033[H\033[J')
def isextension(input_args): #find type of file in a string with at least one dot(*.)
#input_args='hellow world.rkl'
str=input_args
s=len(str)
#rstr=str
vez=1
#encontrado=0
found=0
rstr=''
ext=''
rext=''
for i in range(1,s + 1):
rstr += str[len(str) - i]
if (str[len(str) - i]=='.') and vez==1:
found=i-1
vez=vez+1
for x in range(0, found):
rext=rext+rstr[x]
for i in range(1, len(rext) + 1):
ext += rext[len(rext) - i]
if found==0:
ext='mp4'
elif len(ext)>3:
ext='mp4'
elif len(ext)<3:
ext='mp4'
elif ext=='5':
ext='mp4'
elif ' ' in ext:
ext='mp4'
output_args=ext
return output_args
#answ=isextension('hellow world')
def is_extension(input_str,min_chars=1,max_chars=100,not_ext_found_return=''):
#input_args='hellow world.rkl'
"""
*SHORT DESCRIPTION________________________________________________________
Identify the extension of a string of characters, aka, a full file name.
*ARGUMENTS________________________________________________________________
input_dtr = 'some string.txt'
max_chars = 3 ### Max number of characters allowed for the extension.
not_ext_found_return= 'Not_Found_case_extension'
*DESCRIPTION_______________________________________________________________
This function returns the extension identifiable in a string.
You can delimite the maximum number of characters with max_chars that
usually are strings, it's usually 3 or 4, as in 'my_file.doc' or
'my_file.docx' and differentiate between 'my_file.asdafd', which probably
is not a valid file extension but could be the result of a virus creating
files.
With the not_ext_found_return argument you can determine the output of this
function as anything you prefer:
is_extension(input_str,max_chars,False)
is_extension(input_str,max_chars,'Not_Found')
is_extension(input_str,max_chars,0)
This is usefull if what you are doing is changing the extension of
multiple files whit different file extensions.
*EXAMPLES___________________________________________________________________
Input : is_extension('myfile.homework.pdf',1,'Not_ext')
Output:'Not_ext'
Input : is_extension('myfile homework pdf',3,False)
Output: False
Input : is_extension('myfile.homework.pdf',4,'Not_ext')
Output: 'pdf'
"""
str=input_str
s=len(str)
#rstr=str
vez=1
#encontrado=0
found=0
rstr=''
ext=''
rext=''
for i in range(1,s + 1):
rstr += str[len(str) - i]
if (str[len(str) - i]=='.') and vez==1:
found=i-1
vez=vez+1
for x in range(0, found):
rext=rext+rstr[x]
for i in range(1, len(rext) + 1):
ext += rext[len(rext) - i]
if found==0:
ext=not_ext_found_return
elif len(ext)>max_chars:
ext=not_ext_found_return
elif len(ext)<min_chars:
ext=not_ext_found_return
elif ' ' in ext:
ext=not_ext_found_return
output_args=ext
return output_args
#answ=isextension('hellow world')
def sorti(lst): #sort a list as an insensitive case
lst2 = [[x for x in range(0, 2)] for y in range(0, len(lst))]
for i in range(0, len(lst)):
lst2[i][0] = lst[i].lower()
lst2[i][1] = lst[i]
lst2.sort()
for i in range(0, len(lst)):
lst[i] = lst2[i][1]
return lst
def getAllFiles(path,files_ext='*',auto_sort=True):
import os
filelist=[os.path.join(r,file) for r,d,f in os.walk(path) for file in f]
sf=len(filelist) #number of files in path direcctory
files_ext=files_ext.lower()
if files_ext != '*':
kon=0
filelist2=[]
for i in range(0, sf):
ext=is_extension(filelist[i],1,100,'Not_an_extension').lower()
if files_ext==ext:
filelist2.append(kon)
filelist2[kon]=filelist[i];
kon=kon+1;
#end if
#end for
else:
filelist2=filelist
if auto_sort:
return sorti(filelist2);
return filelist
def getFiles(path,files_ext=''):
#if path[-1] != '/':path+='/'
import os
filelist=[]
files_here=os.listdir(path)
#print(files_ext,files_here)
for file in files_here:
# if '.' not in os.path.basename(file):
# continue
ext=os.path.splitext(file)[-1].replace('.','')
if files_ext:
# if os.path.isfile(file) and ext in files_ext:
if ext in files_ext:
f=os.path.join(path, file)
if os.path.isdir(f):
continue
filelist.append(f)
else:
file_path=os.path.join(path, file)
if os.path.isfile(file_path):
filelist.append(file_path)
#filelist=[f.replace('/','\\') for f in filelist]
filelist=sorti(filelist)
return filelist
#path='C:\\c\\Python_projects\\RKL_channel\\xml2'
#files_ext='xml'
#xmls=getAllFiles(path,files_ext)
def strjoin(list): #join a list of strings
joined=''
for i in range(0, len(list)):
joined=joined+list[i]
return joined
#answ=strjoin(['hellow', 'world'])
def ensure_dir(file_path):
import os
directory = os.path.dirname(file_path)
if not os.path.exists(directory):
os.makedirs(directory)
def ensure_dir2(directory):
import os
if not os.path.exists(directory):
os.makedirs(directory)
##________________PENDING FUNCTIONS_______________##
def titlexml( str ):
#eliminate the already in xml format
str = str.replace(":", "")
str = str.replace("&", "&")
str = str.replace("<", "<")
str = str.replace(">", ">")
str = str.replace(""", "\"")
str = str.replace(''','\'')
#end eliminate the already in xml format
str = str.replace("&", " & ")
str = str.replace("<", "<")
str = str.replace(">", ">")
str = str.replace("\"", """)
str = str.replace('\'', ''')
str=regexrepi('[^ 0-9a-zñ&;,.//?¿!¡=)(_:-]','*',str)
# nnt=''
# for c in str:
# rep=c.encode("unicode_escape").decode('utf-8')
# if len(rep)>1:
# # print(c,repr(rep),rep[2:])
# nnt+='&#'+rep[2:]+';'
# else:
# nnt+=c
# str=nnt
return str
def xmltext( str ):
from xml.sax.saxutils import unescape
from xml.sax.saxutils import escape
str=unescape(str)
str=escape(str)
#eliminate the already in xml format
str = str.replace('’','’');
str = str.replace('†','†')
str = str.replace("&", "&")
str = str.replace("<", "<")
str = str.replace(">", ">")
str = str.replace(""", "\"")
str = str.replace(''', '\'')
str = str.replace('‘', '\'')
str = str.replace('’', '\'')
str = str.replace('“','"')
str = str.replace('”','"')
str = str.replace(' ',' ')
str = str.replace('…','...')
######################################################################
str=str.replace('>','>')
str=str.replace('¡','¡')
str=str.replace('¢','¢')
str=str.replace('£','£')
str=str.replace('¤','¤')
str=str.replace('¥','¥')
str=str.replace('¦','¦')
str=str.replace('§','§')
str=str.replace('¨','¨')
str=str.replace('©','©')
str=str.replace('ª','ª')
str=str.replace('«','«')
str=str.replace('¬','¬')
str=str.replace('®','®')
str=str.replace('¯','¯')
str=str.replace('°','°')
str=str.replace('±','±')
str=str.replace('²','²')
str=str.replace('³','³')
str=str.replace('´','´')
str=str.replace('µ','µ')
str=str.replace('¶','¶')
str=str.replace('·','·')
str=str.replace('¸','¸')
str=str.replace('¹','¹')
str=str.replace('º','º')
str=str.replace('»','»')
str=str.replace('¼','¼')
str=str.replace('½','½')
str=str.replace('¾','¾')
str=str.replace('¿','¿')
str=str.replace('À','À')
str=str.replace('Á','Á')
str=str.replace('Â','Â')
str=str.replace('Ã','Ã')
str=str.replace('Ä','Ä')
str=str.replace('Å','Å')
str=str.replace('Æ','Æ')
str=str.replace('Ç','Ç')
str=str.replace('È','È')
str=str.replace('É','É')
str=str.replace('Ê','Ê')
str=str.replace('Ë','Ë')
str=str.replace('Ì','Ì')
str=str.replace('Í','Í')
str=str.replace('Î','Î')
str=str.replace('Ï','Ï')
str=str.replace('Ð','Ð')
str=str.replace('Ñ','Ñ')
str=str.replace('Ò','Ò')
str=str.replace('Ó','Ó')
str=str.replace('Ô','Ô')
str=str.replace('Õ','Õ')
str=str.replace('Ö','Ö')
str=str.replace('×','×')
str=str.replace('Ø','Ø')
str=str.replace('Ù','Ù')
str=str.replace('Ú','Ú')
str=str.replace('Û','Û')
str=str.replace('Ü','Ü')
str=str.replace('Ý','Ý')
str=str.replace('Þ','Þ')
str=str.replace('ß','ß')
str=str.replace('à','à')
str=str.replace('á','á')
str=str.replace('â','â')
str=str.replace('ã','ã')
str=str.replace('ä','ä')
str=str.replace('å','å')
str=str.replace('æ','æ')
str=str.replace('ç','ç')
str=str.replace('è','è')
str=str.replace('é','é')
str=str.replace('ê','ê')
str=str.replace('ë','ë')
str=str.replace('ì','ì')
str=str.replace('í','í')
str=str.replace('î','î')
str=str.replace('ï','ï')
str=str.replace('ð ;','ð')
str=str.replace('ñ','ñ')
str=str.replace('ò','ò')
str=str.replace('ó','ó')
str=str.replace('ô','ô')
str=str.replace('õ','õ')
str=str.replace('ö','ö')
str=str.replace('÷','÷')
str=str.replace('ø','ø')
str=str.replace('ù','ù')
str=str.replace('ú','ú')
str=str.replace('û','û')
str=str.replace('ü','ü')
str=str.replace('ý','ý')
str=str.replace('þ','þ')
str=str.replace('ÿ','ÿ')
str=str.replace('Œ','Œ')
str=str.replace('œ','œ')
str=str.replace('Š','Š')
str=str.replace('š','š')
str=str.replace('Ÿ','Ÿ')
str=str.replace('ƒ','ƒ')
str=str.replace('ˆ','ˆ')
str=str.replace('˜','˜ ')
str=str.replace('Α','Α')
str=str.replace('Β','Β')
str=str.replace('Γ','Γ')
str=str.replace('Δ','Δ')
str=str.replace('Ε','Ε')
str=str.replace('Ζ','Ζ')
str=str.replace('Η','Η')
str=str.replace('Θ','Θ')
str=str.replace('Ι','Ι')
str=str.replace('Κ','Κ')
str=str.replace('Λ','Λ')
str=str.replace('Μ','Μ')
str=str.replace('Ν','Ν')
str=str.replace('Ξ','Ξ')
str=str.replace('Ο','Ο')
str=str.replace('Π','Π')
str=str.replace('Ρ','Ρ')
str=str.replace('Σ','Σ')
str=str.replace('Τ','Τ')
str=str.replace('Υ','Υ')
str=str.replace('Φ','Φ')
str=str.replace('Χ','Χ')
str=str.replace('Ψ','Ψ')
str=str.replace('Ω','Ω')
str=str.replace('α','α')
str=str.replace('β','β')
str=str.replace('γ','γ')
str=str.replace('δ','δ')
str=str.replace('ε','ε')
str=str.replace('ζ','ζ')
str=str.replace('η','η')
str=str.replace('θ','θ')
str=str.replace('ι','ι')
str=str.replace('κ','κ')
str=str.replace('λ','λ')
str=str.replace('μ','μ')
str=str.replace('ν','ν')
str=str.replace('ξ','ξ')
str=str.replace('ο','ο')
str=str.replace('π','π')
str=str.replace('ρ','ρ')
str=str.replace('ς','ς')
str=str.replace('σ','σ')
str=str.replace('τ','τ')
str=str.replace('υ','υ')
str=str.replace('φ','φ')
str=str.replace('χ','χ')
str=str.replace('ψ','ψ')
str=str.replace('ω','ω')
str=str.replace('ϑ','ϑ')
str=str.replace('ϒ','ϒ')
str=str.replace('ϖ','ϖ')
str=str.replace('–','–')
str=str.replace('—','—')
str=str.replace('‘','‘')
str=str.replace('’','’')
str=str.replace('‚','‚')
str=str.replace('“','“')
str=str.replace('”','”')
str=str.replace('„','„')
str=str.replace('†','†')
str=str.replace('‡','‡')
str=str.replace('•','•')
str=str.replace('…','…')
str=str.replace('‰','‰')
str=str.replace('′','′')
str=str.replace('″','″')
str=str.replace('‹','‹')
str=str.replace('›','›')
str=str.replace('‾','‾')
str=str.replace('⁄','⁄')
str=str.replace('€','€')
str=str.replace('™','™')
str=str.replace('←','←')
str=str.replace('↑','↑')
str=str.replace('→','→')
str=str.replace('↓','↓')
str=str.replace('↔','↔')
str=str.replace('⇒','⇒')
str=str.replace('⇔','⇔')
str=str.replace('∀','∀')
str=str.replace('∂','∂')
str=str.replace('∇','∇')
str=str.replace('∏','∏')
str=str.replace('∑','∑')
str=str.replace('−','−')
str=str.replace('√','√')
str=str.replace('∞','∞')
str=str.replace('∧','∧')
str=str.replace('∨','∨')
str=str.replace('∩','∩')
str=str.replace('∪','∪')
str=str.replace('∫','∫')
str=str.replace('∴','∴')
str=str.replace('≈','≈')
str=str.replace('≠','≠')
str=str.replace('≡','≡')
str=str.replace('≤','≤')
str=str.replace('≥','≥')
str=str.replace('⊥','⊥')
str=str.replace('⟨','〈')
str=str.replace('⟩','〉')
str=str.replace('◊','◊')
str=str.replace('♠','♠')
str=str.replace('♣','♣')
str=str.replace('♥','♥')
str=str.replace('♦','♦')
######################################################################
#end eliminate the already in xml format
str = str.replace('"','"');
str = str.replace('“','"');
str = str.replace('”','"');
str = str.replace('‘','\'');
str = str.replace('’','\'');
str = str.replace('†','†')
str = str.replace("&", "&")
str = str.replace("<", "<")
str = str.replace(">", ">")
str = str.replace("\"", """)
str = str.replace('\'', ''')
######################################## str = str.replace('//', '⁄')
#####################################################################
str=str.replace('>','>')
str=str.replace('¡','¡')
str=str.replace('¢','¢')
str=str.replace('£','£')
str=str.replace('¤','¤')
str=str.replace('¥','¥')
str=str.replace('¦','¦')
str=str.replace('§','§')
str=str.replace('¨','¨')
str=str.replace('©','©')
str=str.replace('ª','ª')
str=str.replace('«','«')
str=str.replace('¬','¬')
str=str.replace('®','®')
str=str.replace('¯','¯')
str=str.replace('°','°')
str=str.replace('±','±')
str=str.replace('²','²')
str=str.replace('³','³')
str=str.replace('´','´')
str=str.replace('µ','µ')
str=str.replace('¶','¶')
str=str.replace('·','·')
str=str.replace('¸','¸')
str=str.replace('¹','¹')
str=str.replace('º','º')
str=str.replace('»','»')
str=str.replace('¼','¼')
str=str.replace('½','½')
str=str.replace('¾','¾')
str=str.replace('¿','¿')
str=str.replace('À','À')
str=str.replace('Á','Á')
str=str.replace('Â','Â')
str=str.replace('Ã','Ã')
str=str.replace('Ä','Ä')
str=str.replace('Å','Å')
str=str.replace('Æ','Æ')
str=str.replace('Ç','Ç')
str=str.replace('È','È')
str=str.replace('É','É')
str=str.replace('Ê','Ê')
str=str.replace('Ë','Ë')
str=str.replace('Ì','Ì')
str=str.replace('Í','Í')
str=str.replace('Î','Î')
str=str.replace('Ï','Ï')
str=str.replace('Ð','Ð')
str=str.replace('Ñ','Ñ')
str=str.replace('Ò','Ò')
str=str.replace('Ó','Ó')
str=str.replace('Ô','Ô')
str=str.replace('Õ','Õ')
str=str.replace('Ö','Ö')
str=str.replace('×','×')
str=str.replace('Ø','Ø')
str=str.replace('Ù','Ù')
str=str.replace('Ú','Ú')
str=str.replace('Û','Û')
str=str.replace('Ü','Ü')
str=str.replace('Ý','Ý')
str=str.replace('Þ','Þ')
str=str.replace('ß','ß')
str=str.replace('à','à')
str=str.replace('á','á')
str=str.replace('â','â')
str=str.replace('ã','ã')
str=str.replace('ä','ä')
str=str.replace('å','å')
str=str.replace('æ','æ')
str=str.replace('ç','ç')
str=str.replace('è','è')
str=str.replace('é','é')
str=str.replace('ê','ê')
str=str.replace('ë','ë')
str=str.replace('ì','ì')
str=str.replace('í','í')
str=str.replace('î','î')
str=str.replace('ï','ï')
str=str.replace('ð','ð ;')
str=str.replace('ñ','ñ')
str=str.replace('ò','ò')
str=str.replace('ó','ó')
str=str.replace('ô','ô')
str=str.replace('õ','õ')
str=str.replace('ö','ö')
str=str.replace('÷','÷')
str=str.replace('ø','ø')
str=str.replace('ù','ù')
str=str.replace('ú','ú')
str=str.replace('û','û')
str=str.replace('ü','ü')
str=str.replace('ý','ý')
str=str.replace('þ','þ')
str=str.replace('ÿ','ÿ')
str=str.replace('Œ','Œ')
str=str.replace('œ','œ')
str=str.replace('Š','Š')
str=str.replace('š','š')
str=str.replace('Ÿ','Ÿ')
str=str.replace('ƒ','ƒ')
str=str.replace('ˆ','ˆ')
str=str.replace('˜ ','˜')
str=str.replace('Α','Α')
str=str.replace('Β','Β')
str=str.replace('Γ','Γ')
str=str.replace('Δ','Δ')
str=str.replace('Ε','Ε')
str=str.replace('Ζ','Ζ')
str=str.replace('Η','Η')
str=str.replace('Θ','Θ')
str=str.replace('Ι','Ι')
str=str.replace('Κ','Κ')
str=str.replace('Λ','Λ')
str=str.replace('Μ','Μ')
str=str.replace('Ν','Ν')
str=str.replace('Ξ','Ξ')
str=str.replace('Ο','Ο')
str=str.replace('Π','Π')
str=str.replace('Ρ','Ρ')
str=str.replace('Σ','Σ')
str=str.replace('Τ','Τ')
str=str.replace('Υ','Υ')
str=str.replace('Φ','Φ')
str=str.replace('Χ','Χ')
str=str.replace('Ψ','Ψ')
str=str.replace('Ω','Ω')
str=str.replace('α','α')
str=str.replace('β','β')
str=str.replace('γ','γ')
str=str.replace('δ','δ')
str=str.replace('ε','ε')
str=str.replace('ζ','ζ')
str=str.replace('η','η')
str=str.replace('θ','θ')
str=str.replace('ι','ι')
str=str.replace('κ','κ')
str=str.replace('λ','λ')
str=str.replace('μ','μ')
str=str.replace('ν','ν')
str=str.replace('ξ','ξ')
str=str.replace('ο','ο')
str=str.replace('π','π')
str=str.replace('ρ','ρ')
str=str.replace('ς','ς')
str=str.replace('σ','σ')
str=str.replace('τ','τ')
str=str.replace('υ','υ')
str=str.replace('φ','φ')
str=str.replace('χ','χ')
str=str.replace('ψ','ψ')
str=str.replace('ω','ω')
str=str.replace('ϑ','ϑ')
str=str.replace('ϒ','ϒ')
str=str.replace('ϖ','ϖ')
str=str.replace('–','–')
str=str.replace('—','—')
str=str.replace('‘','‘')
str=str.replace('’','’')
str=str.replace('‚','‚')
str=str.replace('“','“')
str=str.replace('”','”')
str=str.replace('„','„')
str=str.replace('†','†')
str=str.replace('‡','‡')
str=str.replace('•','•')
str=str.replace('…','…')
str=str.replace('‰','‰')
str=str.replace('′','′')
str=str.replace('″','″')
str=str.replace('‹','‹')
str=str.replace('›','›')
str=str.replace('‾','‾')
str=str.replace('⁄','⁄')
str=str.replace('€','€')
str=str.replace('™','™')
str=str.replace('←','←')
str=str.replace('↑','↑')
str=str.replace('→','→')
str=str.replace('↓','↓')
str=str.replace('↔','↔')
str=str.replace('⇒','⇒')
str=str.replace('⇔','⇔')
str=str.replace('∀','∀')
str=str.replace('∂','∂')
str=str.replace('∇','∇')
str=str.replace('∏','∏')
str=str.replace('∑','∑')
str=str.replace('−','−')
str=str.replace('√','√')
str=str.replace('∞','∞')
str=str.replace('∧','∧')
str=str.replace('∨','∨')
str=str.replace('∩','∩')
str=str.replace('∪','∪')
str=str.replace('∫','∫')
str=str.replace('∴','∴')
str=str.replace('≈','≈')
str=str.replace('≠','≠')
str=str.replace('≡','≡')
str=str.replace('≤','≤')
str=str.replace('≥','≥')
str=str.replace('⊥','⊥')
str=str.replace('〈','⟨')
str=str.replace('〉','⟩')
str=str.replace('◊','◊')
str=str.replace('♠','♠')
str=str.replace('♣','♣')
str=str.replace('♥','♥')
str=str.replace('♦','♦')
#####################################################################
str=regexrepi('[^ 0-9a-zñ&;,.?¿!¡=)(_:#-/]','*',str)
return str
#def xmltext_rare(text):
# text=xmltext(text)
# #text=text.replace('&','&')
# #text=text.replace("<", "<")
# #text=text.replace(">", ">")
# #text=text.replace("'", '\'')
# text=text.replace(""", "\"")
# return text
def urlxml(url):
from urllib.parse import quote
url=url.replace('%20',' ');
url=url.replace('%2b','+');
url=url.replace('%2B','+');
if 'www.dropbox.com' in url:
url=url.replace('www.dropbox.com','dl.dropboxusercontent.com');
url=url.replace('?dl=0','?dl=1');
#end
url=quote(url, safe='')
url=url.replace('%2F','/');
url=url.replace('%3A',':');
urlx=url
return urlx
def url_dropbox(url):
if 'www.dropbox.com' in url:
url=url.replace('www.dropbox.com','dl.dropboxusercontent.com');
url=url.replace('?dl=0','?dl=1');
return url
#ur=urlxml('https://www.dropbox.com/s/ftitwyhmeg1ici0/A.Christmas.Horror.Story.2015.BDRip.x264-ROVERS.mkv.mp4?dl=0&x?3----KÃ-mpfer-')
#ur=urlxml('_@')
##________________________________________________##
def regexpi_2(patern, string):
import re
string=string.lower()
result = re.match(patern, string,flags=re.IGNORECASE)
result=result.group(0)
return result
def regexpi(find_str,from_string):
find_str=find_str.lower()
from_string=from_string.lower()
result=find_str in from_string
return result
def regexpi_count(find_str,from_string):
find_str=find_str.lower()
from_string=from_string.lower()
result=find_str in from_string
if result:
result=len(from_string.split(find_str))-1
else:
result=0
return result
#a=regexpi('patern','oPatErnsdfgh')
def regexrep(patern, repwith, from_string): #replace a patern with something else from a string
from re import sub
replaced=sub(patern, repwith, from_string)
return replaced
#b='ASA- - Fafdsffv s123fdf1414 ASAÑñDa+a112*1á´ésdâsdsäëïöüàèìòù~.,_;'
#a=regexrep('[a-z _Ññâêîôûáéíóúäëïöüàèìòù^\W]','',b)
#a=regexrep('[^A-Z0-9]','',b)
def regexrepi(patern, repwith, from_string): #replace a patern with something else from a string, case insensitive
import re
pattern = re.compile(patern, re.IGNORECASE)
replaced=pattern.sub(repwith, from_string)
return replaced
def animef_db(searchfor):
#searchfor='overlord movie 1'
norm_chars_param='[^a-zA-Z0-9 ]' #normalaize characters in the names, replaced to ' '
searchfor=regexrep(norm_chars_param,' ',searchfor)
searchfor=regexrep(' ',' ',searchfor)
searchfor=searchfor.strip()
nm=searchfor.split()
nop=len(nm) #number of words
#adb=open('ANIME.datb','r').read()
adb=open('ANIME.datb', encoding="utf8").read()
adb2=adb.splitlines()
adb2=sorti(adb2)
resreal=-2;respar=-2;res=-2;respart=-2;respart_lazy=-2
ovs=len(adb2); #overall size
info=[]
namesdb=[]
postersdb=[]
descdb=[]
for i in range(0, ovs):
info.append(i)
info[i]=adb2[i].split('<<')
namesdb.append(i)
namesdb[i]=info[i][1]
postersdb.append(i)
postersdb[i]=info[i][2]
descdb.append(i)
descdb[i]=info[i][3]
#end for
names_all_lazy=[]
namesforsearch=namesdb
coincidences_old=0
coincidences_old_lazy=0
lazy_c=0
for i in range(0, ovs):
namesforsearch[i]=regexrep(norm_chars_param,' ',namesforsearch[i])
namesforsearch[i]=regexrep(' ','',namesforsearch[i])
namesforsearch[i]=namesforsearch[i].strip()
nm2=namesforsearch[i].split()
npfs=len(nm2) #number of words in the for search name
ifound=regexpi(searchfor,namesforsearch[i])
if ifound and nop==npfs:
resreal=i
if ifound and nop<npfs:
respar=i
elif ifound==False:
coincidences=0
for j in range(0,npfs):
if len(nm2[j])>1 and regexpi(nm2[j],searchfor):
#print(nm2[j],searchfor,i)
coincidences=coincidences+1
#end for
if coincidences>0 and coincidences>coincidences_old:
respart=i
coincidences_old=coincidences
#end if
#end if, elif
if ifound==False:
coincidences=0
for j in range(0,nop):
if regexpi(nm[j],namesforsearch[i]):
coincidences=coincidences+1
#end for
if coincidences>0 and coincidences>coincidences_old_lazy:
respart_lazy=i
names_all_lazy.append(lazy_c)
names_all_lazy[lazy_c]=namesforsearch[i]
lazy_c=lazy_c+1
#if len(namesforsearch[i])<len(namesforsearch[respart_lazy_old]):
# respart_lazy=respart_lazy_old
#end if
coincidences_old_lazy=coincidences
#end if
#end for
if respart>-1:
res=respart
if respart_lazy>-1:
res=respart_lazy
if respar>-1:
res=respar
if resreal>-1:
res=resreal
if res>-1:
N=namesdb[res]
P=postersdb[res]
D=descdb[res]
else:
N='Not_Found'
P='Not_Found'
D='Not_Found'
#end if, else
#print(searchfor,res,N)
#print(names_all_lazy)
#print(namesdb[respart],namesdb[respart_lazy],namesdb[respar],namesdb[resreal])
return [N,P,D]
#searchfor='black clover'
#def animef_db(searchfor):
def search_in_standard_database(searchfor,datb_dir):
"""
*SHORT DESCRIPTION________________________________________________________
Search a term in a standard *.datb file.
*ARGUMENTS________________________________________________________________
searchfor = 'some string'
datb_dir = 'C:\\Some\\Absolute\\Path\\To\\my_database.datb'
*OR
datb_dir = 'Some_Relative_Path_To\\my_database.datb'
*DESCRIPTION_______________________________________________________________
This function returns an array containing [Name,info_1,info_2] from a
standard *.datb file, being the "Name" result the best match for the
"searchfor" input acording to the logic within this function.
The more accurate input as the "searchfor" variable according to the
information within the *.datb file, the better the results.
*EXAMPLE___________________________________________________________________
Input : search_in_standard_database('dragon ball super','ANIME.datb')
Output:
['Dragon Ball Super',
'http://images.animeadvice.com/assets/media/1/7/6/23671.jpg',
'animestreams.tv: Synopsis: Reuniting the franchise's iconic characters, Dragon Ball Super will follow the aftermath of Goku's fierce battle with Majin Buu as he attempts to maintain earth's fragile peace.']
"""
#searchfor='searchterm'
norm_chars_param='[^a-zA-Z0-9 ]' #normalaize characters in the names, replaced to ' '
searchfor=regexrep(norm_chars_param,' ',searchfor)
searchfor=regexrep(' ',' ',searchfor)
searchfor=searchfor.strip()
nm=searchfor.split()
nop=len(nm) #number of words
#adb=open('ANIME.datb','r').read()
adb=open(datb_dir,'r', encoding="utf8").read()
adb2=adb.splitlines()
adb2=sorti(adb2)
resreal=-2;respar=-2;res=-2;respart=-2;respart_lazy=-2
ovs=len(adb2); #overall size
info=[]
namesdb=[]
postersdb=[]
descdb=[]
for i in range(0, ovs):
info.append(i)
info[i]=adb2[i].split('<<')
namesdb.append(i)
namesdb[i]=info[i][1]
postersdb.append(i)
postersdb[i]=info[i][2]
descdb.append(i)
descdb[i]=info[i][3]
#end for
names_all_lazy=[]
namesforsearch=namesdb
coincidences_old=0
coincidences_old_lazy=0
lazy_c=0
for i in range(0, ovs):
namesforsearch[i]=regexrep(norm_chars_param,' ',namesforsearch[i])
namesforsearch[i]=regexrep(' ','',namesforsearch[i])
namesforsearch[i]=namesforsearch[i].strip()
nm2=namesforsearch[i].split()
npfs=len(nm2) #number of words in the for search name
ifound=regexpi(searchfor,namesforsearch[i])
if ifound and nop==npfs:
resreal=i
if ifound and nop<npfs:
respar=i
elif ifound==False:
coincidences=0
for j in range(0,npfs):
if len(nm2[j])>1 and regexpi(nm2[j],searchfor):
#print(nm2[j],searchfor,i)
coincidences=coincidences+1
#end for
if coincidences>0 and coincidences>coincidences_old:
respart=i
coincidences_old=coincidences
#end if
#end if, elif
if ifound==False:
coincidences=0
for j in range(0,nop):
if regexpi(nm[j],namesforsearch[i]):
coincidences=coincidences+1
#end for
if coincidences>0 and coincidences>coincidences_old_lazy:
respart_lazy=i
names_all_lazy.append(lazy_c)
names_all_lazy[lazy_c]=namesforsearch[i]
lazy_c=lazy_c+1
#if len(namesforsearch[i])<len(namesforsearch[respart_lazy_old]):
# respart_lazy=respart_lazy_old
#end if
coincidences_old_lazy=coincidences
#end if
#end for