forked from Rzezimioszek/eKW-pobieracz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eKW_pobieracz.py
1384 lines (1021 loc) · 44.4 KB
/
eKW_pobieracz.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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.common.print_page_options import PrintOptions
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from eKW_functions import *
from eKW_save import *
from eKW_dialogs import *
import asyncio
from pathlib import Path
import time
import sys
import os
import json
import extract_html as eh
from tkinter import filedialog
from tkinter import messagebox as msg
import webbrowser
import pypdf as pypdf
import logging
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QStyle
)
from PyQt5.QtCore import QThread, pyqtSignal, Qt
from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtMultimedia import QSound
# from PyQt5.uic import loadUi
# from PyQt5.QtGui import QIcon
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) # enable highdpi scaling
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) # use highdpi icons
from eKW_pobieracz_ui import Ui_MainWindow
eKWp_ver = "1.2"
logging.basicConfig(format="%(message)s", level=logging.INFO)
theme = get_theme()
class GenerateStandard(QThread):
progress = pyqtSignal(int)
stat = pyqtSignal(str)
def __init__(self, download):
super().__init__()
self.is_paused = False
self.is_killed = False
self.save_path = ""
self.download = download
self.pdf_bg = ""
# @pyqtSlot()
def run(self):
self.is_killed = False
self.is_paused = False
sad = win.lineSign.text().strip().upper()
bot = win.lineFloor.text().strip()
top = win.lineRoof.text().strip()
clear_log()
if sad not in win.sady:
err = f"Brak oznaczenia sądu [{sad}], sprawdz plik res/sady.kw"
gen_err(err, True)
return
try:
sad_value = [win.rep_dict[s] for s in sad]
except:
err = f"Oznaczenie sądu {sad} nieprawidłowe"
gen_err(err, True)
return
if not bot.isdecimal() or not top.isdecimal():
err = f"Nieporawny przedział dla wartości dolnej lub górnej"
gen_err(err, True)
return
bot = int(bot)
top = int(top)
if top > 99999999:
err = f"Wartość górna {top} powyżej dozwolonego przedziału zmiana na 99999999"
gen_err(err)
top = 99999999
if bot < 1:
err = f"Wartość dolna {bot} poniżejj dozwolonego przedziału zmiana na 1"
#gen_err(err)
bot = 1
if bot > top:
err = f"Wartość dolna {bot} większa od górnej {top}"
gen_err(err)
return
if not self.download:
gen_err(f"Generowanie listy Kw dla sądu {sad} i przedziału {bot} do {top}")
filetypes = (("pliki txt", "*.txt"), ("Wszystkie pliki", "*.*"))
path = filedialog.asksaveasfilename(title="Zapisz plik txt", filetypes=filetypes)
if path is not None:
if not path.endswith(".txt"):
path = path + ".txt"
with open(path, "w") as file:
file.write(f"")
else:
path = "c:/"
gen_err(f"Pobieranie KW dla: {sad}/{bot}-{top}/n")
if path == "":
err = f"Niepodano scięzki zapisu"
gen_err(err, True)
return
proc = 0
end = top
self.progress.emit(proc)
for i in range(bot, (top + 1)):
try:
nk = win.correct_kw_number(sad, str(i))
if self.download:
# save_kw_to_pdf(nk) #without self
if win.chParams.isChecked():
if win.lineControl.text().isdecimal() and win.lineLast.text().isdecimal():
if nk[-1] == win.lineControl.text() and nk[-3] == win.lineLast.text():
save_kw_to_pdf(nk)
elif win.lineControl.text().isdecimal() and not win.lineLast.text().isdecimal():
if nk[-1] == win.lineControl.text():
save_kw_to_pdf(nk)
elif not win.lineControl.text().isdecimal() and win.lineLast.text().isdecimal():
if nk[-3] == win.lineLast.text():
save_kw_to_pdf(nk)
else:
save_kw_to_pdf(nk)
else:
if win.chParams.isChecked():
if win.lineControl.text().isdecimal() and win.lineLast.text().isdecimal():
if nk[-1] != win.lineControl.text() or nk[-3] != win.lineLast.text():
continue
elif win.lineControl.text().isdecimal() and not win.lineLast.text().isdecimal():
if nk[-1] != win.lineControl.text():
continue
elif not win.lineControl.text().isdecimal() and win.lineLast.text().isdecimal():
if nk[-3] != win.lineLast.text():
continue
with open(path, "a") as file:
file.write(f"{nk}\n")
proc = int(((i - bot)/(end - bot)) * 100)
# logging.info(f"{proc}%\t{i}\t{end}")
proc = 1 if proc <= 0 else proc
proc = 100 if proc >= 100 else proc
# win.progressBar.setValue(proc)
self.progress.emit(proc)
except:
gen_err(f"Bład generownaia w pozycji {i}", log=True, write=True)
return
while self.is_paused:
self.stat.emit("Pauza")
time.sleep(1)
self.stat.emit('')
if self.is_killed:
gen_err(f"Wygenerowano {proc}% z zadanego zakresu", log=True)
self.is_killed = False
self.is_paused = False
break
if self.download:
mess = f"Zakończono pobieranie: {sad} {bot}-{top}"
msg.showinfo("Generator", "Zakończono pobieranie z zadanego zakresu")
self.stat.emit(mess)
else:
mess = f"Zakończono generowanie: {sad} {bot}-{top}"
msg.showinfo("Generator", "Zakończono generowanie z zadanego zakresu")
self.stat.emit(mess)
# self.quit()
# quit()
# return
def kill(self):
self.is_killed = True
self.is_paused = False
self.stat.emit("Kończenie działania przez użytkownika")
def pause(self):
if self.is_paused:
self.is_paused = False
self.stat.emit("Wznowiono")
else:
self.is_paused = True
self.stat.emit("Wstrzymywanie działania")
class GenerateTurbo(QThread):
progress = pyqtSignal(int)
stat = pyqtSignal(str)
def __init__(self, download):
super().__init__()
self.is_paused = False
self.is_killed = False
self.save_path = ""
self.download = download
self.pdf_bg = ""
# @pyqtSlot()
def run(self):
self.is_killed = False
self.is_paused = False
asyncio.run(self.generator())
msg.showinfo("Generator", "Zakończono pobieranie z zadanego zakresu")
async def generator(self):
self.progress.emit(0)
mess = "Start turbogeneratora numerów KW"
self.stat.emit(mess)
sad = win.lineSign.text().strip().upper()
bot = win.lineFloor.text().strip()
top = win.lineRoof.text().strip()
clear_log()
if sad not in win.sady:
err = f"Brak oznaczenia sądu [{sad}], sprawdz plik res/sady.kw"
self.stat.emit(err)
gen_err(err, True)
return
try:
sad_value = [win.rep_dict[s] for s in sad]
except:
err = f"Oznaczenie sądu {sad} nieprawidłowe"
self.stat.emit(err)
gen_err(err, True)
return
if not bot.isdecimal() or not top.isdecimal():
err = f"Nieporawny przedział dla wartości dolnej lub górnej"
self.stat.emit(err)
gen_err(err, True)
return
bot = int(bot)
top = int(top)
if top > 99999999:
err = f"Wartość górna {top} powyżej dozwolonego przedziału zmiana na 99999999"
self.stat.emit(err)
gen_err(err)
top = 99999999
if bot < 1:
err = f"Wartość dolna {bot} poniżej dozwolonego przedziału zmiana na 1"
self.stat.emit(err)
gen_err(err)
bot = 1
if bot > top:
err = f"Wartość dolna {bot} większa od górnej {top}"
self.stat.emit(err)
gen_err(err)
return
if not self.download:
err = f"Generowanie listy KW: {sad} {bot}-{top}"
gen_err(err)
self.stat.emit(err)
filetypes = (("pliki txt", "*.txt"), ("Wszystkie pliki", "*.*"))
path = filedialog.asksaveasfilename(title="Zapisz plik txt", filetypes=filetypes)
if path is not None:
if not path.endswith(".txt"):
path = path + ".txt"
with open(path, "w") as file:
file.write(f"")
else:
path = "c:/"
err = f"Pobieranie KW dla: {sad} {bot}-{top}"
gen_err(err)
self.stat.emit(err)
if path == "":
err = f"Niepodano scięzki zapisu"
self.stat.emit(err)
gen_err(err, True)
return
proc = 0
end = top
j = 0
k = 0
self.progress.emit(proc)
n = win.spN.value()
task = []
for i in range(bot, (top + 1)):
try:
nk = win.correct_kw_number(sad, str(i))
if win.chParams.isChecked():
if win.lineControl.text().isdecimal() and win.lineLast.text().isdecimal():
if nk[-1] == win.lineControl.text() and nk[-3] == win.lineLast.text():
task.append(asyncio.create_task(save_kw_to_pdf_turbo(nk)))
j += 1
elif win.lineControl.text().isdecimal() and not win.lineLast.text().isdecimal():
if nk[-1] == win.lineControl.text():
task.append(asyncio.create_task(save_kw_to_pdf_turbo(nk)))
j += 1
elif not win.lineControl.text().isdecimal() and win.lineLast.text().isdecimal():
if nk[-3] == win.lineLast.text():
task.append(asyncio.create_task(save_kw_to_pdf_turbo(nk)))
j += 1
else:
task.append(asyncio.create_task(save_kw_to_pdf_turbo(nk)))
j += 1
if j == n or i == top:
k += 1
err = f"Pętla: {k} Liczba tasków: {j}"
gen_err(f"Pętla: {k} Liczba tasków: {j}")
self.stat.emit(err)
await asyncio.gather(*task)
task.clear()
proc = int(((i - bot)/(end - bot)) * 100)
proc = 1 if proc <= 0 else proc
proc = 100 if proc >= 100 else proc
self.progress.emit(proc)
while self.is_paused:
self.stat.emit("Pauza")
time.sleep(1)
self.stat.emit('')
if self.is_killed:
self.is_paused = False
break
# await asyncio.sleep(9 * j)
j = 0
except:
err = f"Bład generownaia w pozycji {i}"
gen_err(err, log=True, write=True)
self.stat.emit(err)
return
while self.is_paused:
self.stat.emit("Pauza")
time.sleep(1)
self.stat.emit('')
if self.is_killed:
#gen_err(f"Wygenerowano {proc}% z zadanego zakresu", log=True)
self.is_killed = False
self.is_paused = False
break
def kill(self):
self.is_killed = True
self.is_paused = False
self.stat.emit("Kończenie działania przez użytkownika")
def pause(self):
if self.is_paused:
self.is_paused = False
self.stat.emit("Wznowiono")
else:
self.is_paused = True
self.stat.emit("Wstrzymywanie działania")
class ListStandard(QThread):
progress = pyqtSignal(int)
stat = pyqtSignal(str)
def __init__(self, values):
super().__init__()
self.is_paused = False
self.is_killed = False
self.values = values
self.save_path = ""
self.pdf_bg = ""
# @pyqtSlot()
def run(self):
self.is_killed = False
self.is_paused = False
mess = "Start pobieranie standardowe"
self.stat.emit(mess)
try:
values = self.values
except:
err = "Plik wejściowy z listą kw niepoprawny."
self.stat.emit(err)
msg.showerror("Zła lista", err)
return
clear_log()
i = 0
end = len(values)
proc = 0
self.progress.emit(proc)
for value in values:
if "/" not in value:
continue
value = value.replace("\n", "")
save_kw_to_pdf(value) # without self
i += 1
proc = int((i/end) * 100)
proc = 1 if proc <= 0 else proc
proc = 100 if proc >= 100 else proc
self.progress.emit(proc)
while self.is_paused:
self.stat.emit('Pauza')
time.sleep(1)
self.stat.emit('')
time.sleep(1)
if self.is_killed:
self.is_paused = False
self.stat.emit('Zakończono')
break
if self.is_killed:
err = f"Zakończono pobieranie na: {proc}%"
gen_err(err)
# win.progressBar.setValue(0)
self.stat.emit(err)
self.progress.emit(proc)
msg.showinfo("Zakończono pobieranie", f"Pobrano {proc}% wybranych ksiąg")
else:
err = "Wszystkie księgi wieczyste z zadania zostały pobrane"
gen_err(err)
self.stat.emit(err)
msg.showinfo("Zakończono pobieranie", "Wszystkie księgi wieczyste z zadania zostały pobrane")
msg.showinfo("Generator", "Zakończono pobieranie z listy")
def kill(self):
self.is_killed = True
self.is_paused = False
self.stat.emit("Kończenie działania przez użytkownika")
def pause(self):
if self.is_paused:
self.is_paused = False
self.stat.emit("Wznowiono")
else:
self.is_paused = True
self.stat.emit("Wstrzymywanie działania")
class ListTurbo(QThread):
progress = pyqtSignal(int)
stat = pyqtSignal(str)
def __init__(self, values, generate=False):
super().__init__()
self.is_paused = False
self.is_killed = False
self.generate = generate
self.values = values
self.save_path = ""
self.pdf_bg = ""
# @pyqtSlot()
def run(self):
self.is_killed = False
self.is_paused = False
if self.generate:
asyncio.run(self.generator())
msg.showinfo("Generator", "Zakończono pobieranie z zadanego zakresu")
else:
asyncio.run(self.run_by_list_turbo())
msg.showinfo("Generator", "Zakończono pobieranie z listy")
async def run_by_list_turbo(self, values=[]):
self.progress.emit(0)
mess = "Start turbopobieranie"
self.stat.emit(mess)
try:
if len(values) < 1:
values = win.get_list()
except:
err = "Plik wejściowy z listą kw niepoprawny."
msg.showerror("Zła lista", err)
self.stat.emit(err)
return
clear_log()
task = []
i = 0
j = 0
k = 0
# n = 5
n = win.spN.value()
end = len(values)
for value in values:
if "/" not in value:
continue
value = value.replace("\n", "")
# task.append(asyncio.create_task(self.save_kw_to_pdf_turbo(value)))
task.append(asyncio.create_task(save_kw_to_pdf_turbo(value)))
j += 1
i += 1
if j == n or i == len(values):
k += 1
err = f"Pętla: {k} Liczba tasków: {j}"
gen_err(err)
self.stat.emit(err)
await asyncio.gather(*task)
task.clear()
proc = int((i/end)*100)
proc = 1 if proc <= 0 else proc
proc = 100 if proc >= 100 else proc
self.progress.emit(proc)
if self.is_killed:
break
while self.is_paused:
time.sleep(1)
# await asyncio.sleep(9 * j)
j = 0
err = "Wszystkie księgi wieczyste z zadania zostały pobrane"
gen_err(err)
self.stat.emit(err)
msg.showinfo("Zakończono pobieranie", err)
def kill(self):
self.is_killed = True
self.stat.emit("Zakończono działanie przez użytkownika")
def pause(self):
if self.is_paused:
self.is_paused = False
self.stat.emit("Wznowiono")
else:
self.is_paused = True
self.stat.emit("WWstrzymywanie działania")
class Window(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.connectSignalsSlots()
# self.kw_count = 0
self.config = 'eKW.json'
self.setting = dict()
self.setting['kwlist'] = ""
self.setting['savepath'] = "C:/"
self.setting['sign'] = ""
self.setting['startnum'] = ""
self.setting['endnum'] = ""
self.load_config()
self.pdf_bg = self.chBg.isChecked()
self.sady = []
if os.path.exists('res/sady.kw'):
with open('res/sady.kw', 'r') as file:
lines = file.readlines()
self.sady = [x.replace("\n","") for x in lines]
self.rep_dict = {"X": "10", "A": "11", "B": "12", "C": "13", "D": "14", "E": "15",
"F": "16", "G": "17", "H": "18", "I": "19", "J": "20", "K": "21",
"L": "22", "M": "23", "N": "24", "O": "25", "P": "26", "R": "27",
"S": "28", "T": "29", "U": "30", "W": "31", "Y": "32", "Z": "33",
"0":"0", "1":"1", "2":"2", "3":"3", "4":"4", "5":"5", "6":"6", "7":"7", "8":"8", "9":"9"}
### icons
"""self.btnRun.setIcon(self.style().standardIcon(QStyle.SP_ArrowDown))
self.btnGenSave.setIcon(self.style().standardIcon(QStyle.SP_ArrowDown))"""
self.btnGen.setIcon(self.style().standardIcon(QStyle.SP_DialogSaveButton))
self.btnList.setIcon(self.style().standardIcon(QStyle.SP_DirOpenIcon))
self.btnSave.setIcon(self.style().standardIcon(QStyle.SP_DialogSaveButton))
self.btnLog.setIcon(self.style().standardIcon(QStyle.SP_FileIcon))
self.btnErr.setIcon(self.style().standardIcon(QStyle.SP_FileIcon))
gen_err(err="Uruchomiono program", log=True)
self.runner = ListStandard([])
def connectSignalsSlots(self):
self.btnRun.clicked.connect(lambda: self.start_runer('ds'))
self.btnTurbo.clicked.connect(lambda: self.start_runer('dt'))
self.btnList.clicked.connect(lambda: self.lineList.setText(open_file()))
self.btnOpenDzList.clicked.connect(lambda: self.lineDzList.setText(open_file()))
self.btnSave.clicked.connect(lambda: self.lineSave.setText(open_dir()))
self.btnGen.clicked.connect(lambda: self.start_runer('gs'))
self.btnGenSave.clicked.connect(lambda: self.start_runer('gsd'))
self.btnGenSaveTurbo.clicked.connect(lambda: self.start_runer('gtd'))
self.btnLog.clicked.connect(lambda x: open_local_file('log.txt'))
self.btnErr.clicked.connect(lambda x: open_local_file('errors.txt'))
self.btnPause.clicked.connect(lambda: self.runner.pause())
self.btnStop.clicked.connect(lambda: self.runner.kill())
self.lblBanner.mousePressEvent = baner_click_event
self.chPDF.clicked.connect(lambda: self.update_values())
self.chHTML.clicked.connect(lambda: self.update_values())
self.chTXT.clicked.connect(lambda: self.update_values())
self.chJSON.clicked.connect(lambda: self.update_values())
self.chCSV.clicked.connect(lambda: self.update_values())
self.action_github.triggered.connect(
lambda: webbrowser.open_new('https://github.com/Rzezimioszek/eKW-pobieracz'))
self.action_Wsparcie.triggered.connect(
lambda: webbrowser.open_new('https://www.paypal.com/donate/?hosted_button_id=2AFDC9PRMGN3Q'))
self.action_Instrukcja.triggered.connect(
lambda x: open_local_file('eKW pobieraczek - instrukcja.pdf'))
self.btn_Github.clicked.connect(lambda: webbrowser.open_new('https://github.com/Rzezimioszek/eKW-pobieracz'))
self.btn_Coffe.clicked.connect(lambda: webbrowser.open_new('https://www.paypal.com/donate/?hosted_button_id=2AFDC9PRMGN3Q'))
self.btn_Instrukcja.clicked.connect(lambda x: open_local_file('eKW pobieraczek - instrukcja.pdf'))
self.action_muzyka.triggered.connect(lambda x: self.music_switch())
def load_config(self):
if os.path.exists(self.config):
with open(self.config, "r", encoding="utf-8") as file:
line = file.readline()
try:
self.setting = json.loads(line)
except:
self.setting['kwlist'] = ""
self.setting['savepath'] = "C:/"
self.setting['startnum'] = ""
self.setting['endnum'] = ""
self.kw_list = self.exist_setting('kwlist')
self.save_path = self.exist_setting('savepath')
if 'Save' not in self.setting.keys():
self.setting['Save'] = {'save_pdf': True,
'save_html': True,
'save_txt': True,
'save_raport': True,
'save_csv': True,
'save_json1o': True
}
self.setting['Music'] = self.exist_setting('Music', True)
if not self.setting['Music']:
sound.stop()
self.save_pdf = self.exist_setting('Save')['save_pdf']
self.save_html = self.exist_setting('Save')['save_html']
self.save_txt = self.exist_setting('Save')['save_txt']
self.save_raport = self.exist_setting('Save')['save_raport']
self.save_csv = self.exist_setting('Save')['save_csv']
self.save_json1o = self.exist_setting('Save')['save_json1o']
self.ch1o.setChecked(self.exist_setting('dzial_1o', True))
self.ch1s.setChecked(self.exist_setting('dzial_1s', True))
self.ch2.setChecked(self.exist_setting('dzial_2', True))
self.ch3.setChecked(self.exist_setting('dzial_3', True))
self.ch4.setChecked(self.exist_setting('dzial_4', True))
self.chSkip.setChecked(self.exist_setting('Skip', True))
self.chProxy.setChecked(self.exist_setting('Proxy', True))
self.lineProxy.setText(self.exist_setting('ProxyIP'))
self.load_format_checks()
self.lineSign.setText(self.exist_setting('sign'))
self.lineFloor.setText(self.exist_setting('startnum'))
self.lineRoof.setText(self.exist_setting('endnum'))
self.lineLast.setText(self.exist_setting('parms_last'))
self.lineControl.setText(self.exist_setting('parms_control'))
self.lineList.setText(self.kw_list)
self.lineSave.setText(self.save_path)
def music_switch(self):
self.setting['Music'] = not self.setting['Music']
if self.setting['Music']:
sound.play()
else:
sound.stop()
def start_runer(self, action):
match action:
case "ds":
self.runner = ListStandard(self.get_list())
case "dt":
self.runner = ListTurbo(self.get_list())
case 'gs':
self.runner = GenerateStandard(False)
case 'gsd':
self.runner = GenerateStandard(True)
case 'gtd':
self.runner = GenerateTurbo(True)
case _:
return
self.runner.progress.connect(self.update_progress)
self.runner.stat.connect(self.update_status)
self.runner.start()
def update_progress(self, value):
self.progressBar.setValue(value)
def update_status(self, value):
self.lblStatus.setText(value)
def load_format_checks(self):
self.chPDF.setChecked(self.save_pdf)
self.chHTML.setChecked(self.save_html)
self.chTXT.setChecked(self.save_txt)
self.chJSON.setChecked(self.save_raport)
self.chCSV.setChecked(self.save_csv)
self.chJSON1o.setChecked(self.save_json1o)
self.chTheme.setChecked(get_theme())
def update_values(self):
self.save_pdf = self.chPDF.isChecked()
self.save_html = self.chHTML.isChecked()
self.save_txt = self.chTXT.isChecked()
self.save_raport = self.chJSON.isChecked()
self.save_csv = self.chCSV.isChecked()
def correct_kw_number(self, sad, number):
sad_value = [self.rep_dict[s] for s in sad]
wei = [1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7]
while len(number) < 8:
number = f"0{number}"
j_value = [x for x in number]
temp_kw = sad_value + j_value
ctlr_dig = 0
for k in range(len(wei)):
ctlr_dig = ctlr_dig + (wei[k] * int(temp_kw[k]))
ctlr_dig = ctlr_dig % 10
skw = sad + "/" + number + f"/{ctlr_dig}"
return skw
def get_list(self):
self.kw_list = self.lineList.text()
with open(self.kw_list, 'r') as file:
values = file.readlines()
# value = 'OP1U/00004102/3'
distinct = set(values)
return_value = sorted(distinct)
return return_value
def exist_setting(self, key, bool=False):
if key in self.setting.keys():
return self.setting[key]
else:
if bool:
return False
else:
return ""
def get_driver(img: bool = True):
main_browser = str(win.cbBrowser.currentText())[0]
# print(main_browser)
match main_browser:
case "c": # Chrome
try:
options = webdriver.ChromeOptions()
if not img:
prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", prefs)
if win.chProxy.isChecked():
proxy = win.lineProxy.text()
options.add_argument(f"--proxy-server={proxy}")
""" WINDOW_SIZE = "1920,1080"
options.add_argument("--headless=new")
options.add_argument("--window-size=%s" % WINDOW_SIZE)
options.add_argument("disable-gpu")"""
# options.add_argument("--start-minimized")
options.add_argument("--disable-search-engine-choice-screen")
service = Service()
browser = webdriver.Chrome(service=service, options=options)
return browser
except:
return get_driver(main_browser="edge")
case "e": # Edge
try:
options = webdriver.EdgeOptions()
if not img:
prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", prefs)
if win.chProxy.isChecked():
proxy = win.lineProxy.text()
options.add_argument(f"--proxy-server={proxy}")
service = Service()
browser = webdriver.Edge(service=service, options=options)
return browser
except:
return get_driver(main_browser="firefox")
case "f": # Firefox
try:
options = webdriver.FirefoxOptions()
if not img:
prefs = {"profile.managed_default_content_settings.images": 2}
options.set_preference("permissions.default.image", 2)
if win.chProxy.isChecked():
proxy = win.lineProxy.text()
options.add_argument(f"--proxy-server={proxy}")
service = Service()
browser = webdriver.Firefox(service=service, options=options)
return browser
except:
print("Error")
return get_driver(main_browser="error")
case "s": # Safari
...
case _:
return ''
def save_settings():
win.setting['kwlist'] = win.lineList.text()
win.setting['savepath'] = win.lineSave.text()
win.setting['sign'] = win.lineSign.text()
win.setting['startnum'] = win.lineFloor.text()
win.setting['endnum'] = win.lineRoof.text()
win.setting['Save'] = {'save_pdf': win.chPDF.isChecked(),
'save_html': win.chHTML.isChecked(),
'save_txt': win.chTXT.isChecked(),
'save_raport': win.chJSON.isChecked(),
'save_csv': win.chCSV.isChecked(),
'save_json1o': win.chJSON1o.isChecked()}
win.setting['Skip'] = win.chSkip.isChecked()
win.setting['Proxy'] = win.chProxy.isChecked()
win.setting['ProxyIP'] = win.lineProxy.text()
# save chapters preferences
win.setting['dzial_1o'] = win.ch1o.isChecked()
win.setting['dzial_1s'] = win.ch1s.isChecked()
win.setting['dzial_2'] = win.ch2.isChecked()
win.setting['dzial_3'] = win.ch3.isChecked()
win.setting['dzial_4'] = win.ch4.isChecked()
win.setting['parms_last'] = win.lineLast.text()
win.setting['parms_control'] = win.lineControl.text()
with open(win.config, "w", encoding="utf-8") as file:
json.dump(win.setting, file, ensure_ascii=False)
set_theme(win.chTheme.isChecked())
sys.exit(app.exec())
def save_kw_to_pdf(value: str): #
save_path = win.lineSave.text()
pdf_bg = win.chBg.isChecked()
zupelna = False
to_merge = []
merge = win.chMerge.isChecked()
gen_err(f"{value}\t- Wprowadzona wartość")
try:
kw = value.split('/')
if 2 <= len(kw) < 3:
value = win.correct_kw_number(kw[0], kw[1])
kw = value.split('/')
gen_err(f"{value}\t- Poprawiono cyfrę kontrolną")