-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFromDucks.py
More file actions
1451 lines (1283 loc) · 44.4 KB
/
FromDucks.py
File metadata and controls
1451 lines (1283 loc) · 44.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
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
# -*- coding: utf-8 -*-
#@Name FromDucks
#@Hook Books
#@Image fromducks.ico
#@Key FromDucks
#@Description Search for Inducks informations about the selected eComics
#
# FromDucks 3.0 - Sep 2025
#
# ---> 3.0 Changelog: Use the DucksManager API to get the Inducks data in a structured way, allow to test most of the script logic using pure Python
#
# FromDucks 2.15 - Jun 2022
#
# ---> 2.15 Changelog: Fixed bugs found by /u/MxFlix. Packaged by /u/quinyd
#
# FromDucks 2.14 - Jul 2018
#
# ---> 2.14 Changelog: fixed other bugs
#
# You are free to modify, enhance (possibly) and distribute this file, but only if mentioning the (c) part
#
# (C)2007-2013 cYo Soft & (C)2008 DouglasBubbletrousers & (C)2008 wadegiles & (C)2010 cbanack
# (C)2009-2010 oraclexview aka SoundWave
#
# Data (C) The Inducks Team (http://inducks.org)
# The data presented here is based on information from the freely available Inducks database.
#
# This script is freely available to be modifiedy and redistributed
#
# !!!!!!!! BACKUP YOUR FILES BEFORE USING THIS SCRIPT !!!!!!!!! Yes, at least if you plan a mass scarping...
# Sorry guys, I cannot be held responsible if you screw your database...
#
# Some notes regarding the use of this script:
# Select 1 or more comics, same series; start the script and define the desired behavior.
# Pick the correct Series name for I.N.D.U.C.K.S., select which fields to fill:
# * a marked box means OVERRIDE ALWAYS *
# * a shaded box means OVERRIDE IF EMPTY *
# * a blank box means DO NOT OVERRIDE *
# On the Title label, clicking will change th way the title is written, from original to all initials capitalized
# Choose the genre if wanted, pick a translation language with a double click (characters' names will be set in that language, if existing)
# Click OK and wait...
# RESET will cycle the checkbox status
# CANCEL will abort the script
#
# Bugs, suggestions or comments in the Comicrack Forum !
#
#################################################################################################################
import sys
from _json_decode import JSONDecoder
from datetime import datetime
settings = ""
VERSION = "3.0"
# DEBUG = False
DEBUG = True
fileHandle = 0
SIZE_RENAME_LOG = 100000
SIZE_DEBUG_LOG = 100000
def FromDucks(books):
try:
import clr;
clr.AddReference('System')
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
from System.Windows.Forms import Form
class ProgressBarDialog(Form):
def __init__(self, nMax, cText="Scraping Files"):
from System.Drawing import Point, Size, Color
from System.Windows.Forms import (
Label, FormStartPosition, ProgressBar
)
self.Text = cText #"Scraping Files"
self.Size = Size(350, 150)
self.StartPosition = FormStartPosition.CenterScreen
self.pb = ProgressBar()
self.traitement = Label()
self.traitement.Location = Point(20, 5)
self.traitement.Name = "scraping"
self.traitement.Size = Size(300, 50)
self.traitement.Text = ""
self.pb.Size = Size(300, 20)
self.pb.Location = Point(20, 50)
self.pb.Maximum = 100
self.pb.Minimum = 0
self.pb.Step = 100.00 / nMax
self.pb.Value = 0.00
self.pb.BackColor = Color.LightGreen
self.pb.Text = ""
self.pb.ForeColor = Color.Black
self.Controls.Add(self.pb)
self.Controls.Add(self.traitement)
def Update(self, cText, nInc, cHead="Scraping Files "):
self.traitement.Text = "\n" + cText
if nInc > 0:
self.Text = cHead + self.pb.Value.ToString() + "%"
self.pb.Increment(self.pb.Step)
class BuilderForm(Form):
def __init__(self):
from System.Drawing import Point, Size, Color
from System.Windows.Forms import (
DialogResult, Button, ListBox, TextBox, Label, CheckBox, CheckState,
FormBorderStyle, FormStartPosition, SelectionMode
)
global aUpdate, LStart
aUpdate = [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,""]
# series title team Tags summary Notes Web Chars year month publisher Editor
# Penciller Inker Writer Cover Artist Colorist Letterer Language Genre Format Location genret
self.ok = Button()
self.cancel = Button()
self.reset = Button()
self.help = Button()
self.list = ListBox()
self.genret = TextBox()
self.translateinto = Label()
self.titleT = Label()
self.titleT.Tag = "L"
self.series = CheckBox()
self.year = CheckBox()
self.month = CheckBox()
self.title = CheckBox()
self.inker = CheckBox()
self.tags = CheckBox()
self.notes = CheckBox()
self.cover = CheckBox()
self.summary = CheckBox()
self.publisher = CheckBox()
self.penciller = CheckBox()
self.writer = CheckBox()
self.team = CheckBox()
self.web = CheckBox()
self.colorist = CheckBox()
self.language = CheckBox()
self.translate = Button()
self.translatelist = ListBox()
self.genre = CheckBox()
self.letterer = CheckBox()
self.location = CheckBox()
self.editor = CheckBox()
self.format = CheckBox()
self.age = CheckBox()
self.chars = CheckBox()
self.location = CheckBox()
#
# list
#
self.list.Location = Point(10, 10)
self.list.Name = "list"
self.list.Size = Size(175, 300)
self.list.TabIndex = 1
self.list.Text = "Publications"
self.list.MultiColumn = False
self.list.SelectionMode = SelectionMode.One
self.list.HorizontalScrollbar = True
self.list.DoubleClick += self.DoubleClickM
#self.list.Sorted = True
#
# ok
#
self.ok.Location = Point(405, 250)
self.ok.Name = "ok"
self.ok.Size = Size(75, 23)
self.ok.TabIndex = 2
self.ok.Text = "&Ok"
self.ok.UseVisualStyleBackColor = True
self.ok.Click += self.button_Click
self.ok.BackColor = Color.LightGreen
#
# cancel
#
self.cancel.DialogResult = DialogResult.Cancel
self.cancel.Location = Point(405, 275)
self.cancel.Name = "cancel"
self.cancel.Size = Size(75, 23)
self.cancel.TabIndex = 3
self.cancel.Text = "&Cancel"
self.cancel.UseVisualStyleBackColor = True
self.cancel.Click += self.button_Click
self.cancel.BackColor = Color.Red
#
# reset
#
self.reset.Location = Point(405, 10)
self.reset.Name = "reset"
self.reset.Size = Size(75, 23)
self.reset.TabIndex = 4
self.reset.Tag = "Reset the selections"
self.reset.Text = "&Reset"
self.reset.UseVisualStyleBackColor = True
self.reset.Click += self.button_Click
self.reset.BackColor = Color.LightYellow
#
# Help
#
self.help.Location = Point(405, 40)
self.help.Name = "help"
self.help.Size = Size(75, 23)
self.help.TabIndex = 101
self.help.Tag = "General Help"
self.help.Text = "&Help"
self.help.UseVisualStyleBackColor = True
self.help.Click += self.button_Click
self.help.BackColor = Color.Yellow
#
# Genre Text
#
self.genret.Location = Point(375, 225)
self.genret.Name = "genret"
self.genret.Size = Size(85, 25)
self.genret.TabIndex = 27
self.genret.Text = "Disney"
#self.genret.TextAlign = MiddleCenter
#
# series
#
self.series.Location = Point(195, 25)
self.series.Name = "series"
self.series.Size = Size(103, 23)
self.series.TabIndex = 5
self.series.Tag = "Series"
self.series.Text = "Series"
self.series.UseVisualStyleBackColor = True
self.series.CheckState = CheckState.Indeterminate
self.series.ThreeState = True
#
# title
#
self.title.Location = Point(195, 50)
self.title.Name = "title"
self.title.Size = Size(20, 23)
self.title.TabIndex = 6
self.title.Tag = "Main Title"
self.title.Text = ""
self.title.UseVisualStyleBackColor = True
self.title.CheckState = CheckState.Indeterminate
self.title.ThreeState = True
#
# title label
#
self.titleT.Location = Point(213, 54)
self.titleT.Name = "titleT"
self.titleT.Size = Size(83, 23)
self.titleT.TabIndex = 300
self.titleT.Text = ">title<"
self.titleT.Click += self.ClickT
#
# team
#
self.team.Location = Point(195, 75)
self.team.Name = "team"
self.team.Size = Size(103, 23)
self.team.TabIndex = 7
self.team.Tag = "Team"
self.team.Text = "Team"
self.team.UseVisualStyleBackColor = True
self.team.CheckState = CheckState.Indeterminate
self.team.ThreeState = True
# Team Button
#self.teamlist.Location = Point(405, 75)
#self.teamlist.Name = "teamlist"
#self.teamlist.Size = Size(75, 23)
#self.teamlist.TabIndex = 28
#self.teamlist.Tag = "TeamList"
#self.teamlist.Text = "Team List"
#self.teamlist.UseVisualStyleBackColor = True
#self.teamlist.Click += self.button_Click
#
# Tags
#
self.tags.Location = Point(195, 100)
self.tags.Name = "tags"
self.tags.Size = Size(103, 23)
self.tags.TabIndex = 8
self.tags.Tag = "Tags"
self.tags.Text = "Tags"
self.tags.UseVisualStyleBackColor = True
self.tags.CheckState = CheckState.Indeterminate
self.tags.ThreeState = True
#
# summary
#
self.summary.Location = Point(195, 125)
self.summary.Name = "summary"
self.summary.Size = Size(103, 23)
self.summary.TabIndex = 9
self.summary.Tag = "Summary"
self.summary.Text = "Summary"
self.summary.UseVisualStyleBackColor = True
self.summary.CheckState = CheckState.Indeterminate
self.summary.ThreeState = True
#
# Notes
#
self.notes.Location = Point(195, 150)
self.notes.Name = "notes"
self.notes.Size = Size(103, 23)
self.notes.TabIndex = 10
self.notes.Tag = "Notes"
self.notes.Text = "Notes"
self.notes.UseVisualStyleBackColor = True
self.notes.CheckState = CheckState.Indeterminate
self.notes.ThreeState = True
#
# Web
#
self.web.Location = Point(195, 175)
self.web.Name = "web"
self.web.Size = Size(103, 23)
self.web.TabIndex = 11
self.web.Tag = "Web"
self.web.Text = "Web"
self.web.UseVisualStyleBackColor = True
self.web.CheckState = CheckState.Indeterminate
self.web.ThreeState = True
#
# Chars
#
self.chars.Location = Point(195, 200)
self.chars.Name = "chars"
self.chars.Size = Size(103, 23)
self.chars.TabIndex = 12
self.chars.Tag = "Characters"
self.chars.Text = "Characters"
self.chars.UseVisualStyleBackColor = True
self.chars.CheckState = CheckState.Indeterminate
self.chars.ThreeState = True
#
# year
#
self.year.Location = Point(195, 225)
self.year.Name = "year"
self.year.Size = Size(103, 23)
self.year.TabIndex = 13
self.year.Tag = "Year"
self.year.Text = "Year"
self.year.UseVisualStyleBackColor = True
self.year.CheckState = CheckState.Indeterminate
self.year.ThreeState = True
#
# month
#
self.month.Location = Point(195, 250)
self.month.Name = "month"
self.month.Size = Size(103, 23)
self.month.TabIndex = 14
self.month.Tag = "Month"
self.month.Text = "Month"
self.month.UseVisualStyleBackColor = True
self.month.CheckState = CheckState.Indeterminate
self.month.ThreeState = True
#
# publisher
#
self.publisher.Location = Point(195, 275)
self.publisher.Name = "publisher"
self.publisher.Size = Size(103, 23)
self.publisher.TabIndex = 15
self.publisher.Tag = "Publisher"
self.publisher.Text = "Publisher"
self.publisher.UseVisualStyleBackColor = True
self.publisher.CheckState = CheckState.Indeterminate
self.publisher.ThreeState = True
#
# Editor
#
self.editor.Location = Point(300, 25)
self.editor.Name = "editor"
self.editor.Size = Size(103, 23)
self.editor.TabIndex = 16
self.editor.Tag = "Editor"
self.editor.Text = "Editor"
self.editor.UseVisualStyleBackColor = True
self.editor.CheckState = CheckState.Indeterminate
self.editor.ThreeState = True
#
# Penciller
#
self.penciller.Location = Point(300, 50)
self.penciller.Name = "penciller"
self.penciller.Size = Size(103, 23)
self.penciller.TabIndex = 17
self.penciller.Tag = "Penciller"
self.penciller.Text = "Penciller"
self.penciller.UseVisualStyleBackColor = True
self.penciller.CheckState = CheckState.Indeterminate
self.penciller.ThreeState = True
#
# Inker
#
self.inker.Location = Point(300, 75)
self.inker.Name = "inker"
self.inker.Size = Size(103, 23)
self.inker.TabIndex = 18
self.inker.Tag = "Inker"
self.inker.Text = "Inker"
self.inker.UseVisualStyleBackColor = True
self.inker.CheckState = CheckState.Indeterminate
self.inker.ThreeState = True
#
# Writer
#
self.writer.Location = Point(300, 100)
self.writer.Name = "writer"
self.writer.Size = Size(103, 23)
self.writer.TabIndex = 19
self.writer.Tag = "Writer"
self.writer.Text = "Writer"
self.writer.UseVisualStyleBackColor = True
self.writer.CheckState = CheckState.Indeterminate
self.writer.ThreeState = True
#
# Cover Artist
#
self.cover.Location = Point(300, 125)
self.cover.Name = "cover"
self.cover.Size = Size(103, 23)
self.cover.TabIndex = 20
self.cover.Tag = "Cover Artist"
self.cover.Text = "Cover Artist"
self.cover.UseVisualStyleBackColor = True
self.cover.CheckState = CheckState.Indeterminate
self.cover.ThreeState = True
#
# Colorist
#
self.colorist.Location = Point(300, 150)
self.colorist.Name = "colorist"
self.colorist.Size = Size(103, 23)
self.colorist.TabIndex = 21
self.colorist.Tag = "Colorist"
self.colorist.Text = "Colorist"
self.colorist.UseVisualStyleBackColor = True
self.colorist.CheckState = CheckState.Indeterminate
self.colorist.ThreeState = True
#
# Letterer
#
self.letterer.Location = Point(300, 175)
self.letterer.Name = "letterer"
self.letterer.Size = Size(103, 23)
self.letterer.TabIndex = 22
self.letterer.Tag = "Letterer"
self.letterer.Text = "Letterer"
self.letterer.UseVisualStyleBackColor = True
self.letterer.CheckState = CheckState.Indeterminate
self.letterer.ThreeState = True
#
# Language
#
self.language.Location = Point(300, 200)
self.language.Name = "language"
self.language.Size = Size(103, 23)
self.language.TabIndex = 23
self.language.Tag = "Language"
self.language.Text = "Language"
self.language.UseVisualStyleBackColor = True
self.language.CheckState = CheckState.Indeterminate
self.language.ThreeState = True
#
# Translate Button
self.translate.Location = Point(405, 70)
self.translate.Name = "translate"
self.translate.Size = Size(75, 23)
self.translate.TabIndex = 28
self.translate.Tag = "Translate"
self.translate.Text = "Translate"
self.translate.UseVisualStyleBackColor = True
self.translate.Click += self.button_Click
#
# Translatelist
#
self.translatelist.Location = Point(405, 125)
self.translatelist.Name = "translatelist"
self.translatelist.Size = Size(75, 100)
self.translatelist.TabIndex = 29
self.translatelist.Text = "Translation Language"
self.translatelist.MultiColumn = False
self.translatelist.SelectionMode = SelectionMode.One
self.translatelist.HorizontalScrollbar = True
self.translatelist.DoubleClick += self.DoubleClick
#
# Translateinto label
#
self.translateinto.Location = Point(405, 125)
self.translateinto.Name = "translateinto"
self.translateinto.Size = Size(75, 100)
self.translateinto.TabIndex = 30
self.translateinto.Text = ""
#
# Genre
#
self.genre.Location = Point(300, 225)
self.genre.Name = "genre"
self.genre.Size = Size(103, 23)
self.genre.TabIndex = 24
self.genre.Tag = "Genre"
self.genre.Text = "Genre"
self.genre.UseVisualStyleBackColor = True
self.genre.CheckStateChanged += self.ChangeStatus
self.genre.CheckState = CheckState.Indeterminate
self.genre.ThreeState = True
#
# Format
#
self.format.Location = Point(300, 250)
self.format.Name = "format"
self.format.Size = Size(103, 23)
self.format.TabIndex = 25
self.format.Tag = "Format"
self.format.Text = "Format"
self.format.UseVisualStyleBackColor = True
self.format.CheckState = CheckState.Indeterminate
self.format.ThreeState = True
#
# Location
#
self.location.Location = Point(300, 275)
self.location.Name = "location"
self.location.Size = Size(103, 23)
self.location.TabIndex = 26
self.location.Tag = "Location"
self.location.Text = "Location"
self.location.UseVisualStyleBackColor = True
self.location.CheckState = CheckState.Indeterminate
self.location.ThreeState = True
#
# box W > x L V
self.ClientSize = Size(490, 315)
#
self.Controls.Add(self.cancel)
self.Controls.Add(self.ok)
self.Controls.Add(self.reset)
self.Controls.Add(self.help)
self.Controls.Add(self.genret)
self.Controls.Add(self.series)
self.Controls.Add(self.publisher)
self.Controls.Add(self.title)
self.Controls.Add(self.titleT)
self.Controls.Add(self.month)
self.Controls.Add(self.year)
self.Controls.Add(self.tags)
self.Controls.Add(self.inker)
self.Controls.Add(self.writer)
self.Controls.Add(self.penciller)
self.Controls.Add(self.team)
self.Controls.Add(self.cover)
self.Controls.Add(self.summary)
self.Controls.Add(self.notes)
self.Controls.Add(self.web)
self.Controls.Add(self.colorist)
self.Controls.Add(self.language)
self.Controls.Add(self.translate)
self.Controls.Add(self.genre)
self.Controls.Add(self.letterer)
self.Controls.Add(self.editor)
self.Controls.Add(self.chars)
self.Controls.Add(self.format)
self.Controls.Add(self.location)
self.list.BeginUpdate()
nIndex = 0
for index, publicationcode in enumerate(sorted(publications.keys())):
publicationCountrycode = publicationcode[:publicationcode.find("/")]
publicationtitle = publications[publicationcode]
try:
self.list.Items.Add(publicationcode + " - " + publicationtitle.decode('utf-8'))
except:
self.list.Items.Add(publicationcode + " - " + publicationtitle)
if publicationCountrycode == bookLanguagecode:
try:
if bookPublicationname == publicationtitle.decode('utf-8'):
nIndex = index
except:
if bookPublicationname == publicationtitle:
nIndex = index
self.Controls.Add(self.list)
if nIndex > 0:
self.list.SelectedIndex = nIndex
self.list.TopIndex = self.list.SelectedIndex + 10
self.list.Focus()
self.list.EndUpdate()
self.FormBorderStyle = FormBorderStyle.FixedDialog
self.Name = "FromDucks"
self.StartPosition = FormStartPosition.CenterParent
self.Text = "(c) Inducks team (web: inducks.org)"
self.MinimizeBox = False
self.MaximizeBox = False
def GetSelectedPublicationcodeFromList(self):
return "" if self.list.SelectedIndex == -1 else self.list.Items[self.list.SelectedIndex][:self.list.Items[self.list.SelectedIndex].find(" - ")].strip()
def button_Click(self, sender, e):
from System.Windows.Forms import (
MessageBox, CheckState
)
global aUpdate, publicationcode
if sender.Name.CompareTo(self.ok.Name) == 0:
publicationcode = self.GetSelectedPublicationcodeFromList()
if publicationcode == "":
MessageBox.Show('Please select a publication first!')
return
dDict = {"Checked": 1, "Unchecked": 0, "Indeterminate": 2 }
for x in range(self.Controls.Count):
if 4 < self.Controls.Item[x].TabIndex < 27:
aUpdate[self.Controls.Item[x].TabIndex- 5] = dDict[self.Controls.Item[x].CheckState.ToString()]
aUpdate[22] = self.genret.Text
self.DialogResult = DialogResult.OK
elif sender.Name.CompareTo(self.reset.Name) == 0:
for x in range(self.Controls.Count):
if 4 < self.Controls.Item[x].TabIndex < 27:
aUpdate[self.Controls.Item[x].TabIndex-5] = aUpdate[self.Controls.Item[x].TabIndex-5] + 1
if aUpdate[self.Controls.Item[x].TabIndex-5] == 3:
aUpdate[self.Controls.Item[x].TabIndex-5] = 0
if self.Controls.Item[x].CheckState == CheckState.Checked:
self.Controls.Item[x].CheckState = CheckState.Unchecked
elif self.Controls.Item[x].CheckState == CheckState.Unchecked:
self.Controls.Item[x].CheckState = CheckState.Indeterminate
else:
self.Controls.Item[x].CheckState = CheckState.Checked
self.translateinto.Visible = False
self.translateinto.Text = ""
TranslationID = ""
elif sender.Name.CompareTo(self.cancel.Name) == 0:
pass
elif sender.Name.CompareTo(self.translate.Name) == 0:
self.translatelist.BeginUpdate()
if self.translatelist.Visible == False:
self.translatelist.Visible = True
self.translateinto.Text = ""
self.translateinto.Visible = False
for languagecode, languagename in enumerate(sorted(languages.keys())):
self.translatelist.Items.Add(languagecode.upper() + " - " + languagename )
self.Controls.Add(self.translatelist)
self.translatelist.EndUpdate()
elif sender.Name.CompareTo(self.help.Name) == 0:
MessageBox.Show('Help - FromDucks Script v' + VERSION + "\n---------------------\n" +
"Select 1 or more comics, same series;\nStart the script and define the desired behavior.\n" +
"Pick the correct Series name for COA, select which fields to fill:\n" +
"* A marked box means OVERRIDE ALWAYS *\n" +
"* A shaded box means OVERRIDE IF EMPTY *\n" +
"(only for SUMMARY, it will add to the current value)\n" +
"* A blank box means DO NOT OVERRIDE *\n" +
"On the Title label, clicking will change the way the title is written, from original to all initials capitalized\n" +
"Choose the genre if needed and a translation language with a double click\n"+
"(characters' names will be set in that language, if existing)\n" +
"\nDouble clicking on a series will show the COA Webpage;\n" +
"Click OK and wait...\n" +
"> RESET will cycle the checkbox status\n" +
"> CANCEL will abort the script")
def ChangeStatus(self, sender, e):
if sender.Name.CompareTo(self.genre.Name) == 0:
stDict = {"Checked": True, "Unchecked": False, "Indeterminate": True }
self.genret.Enabled = stDict[sender.CheckState.ToString()]
else:
pass
def DoubleClickM(self, sender, e):
from System.Diagnostics import Process
publicationcode = self.GetSelectedPublicationcodeFromList()
cWeb = "https://inducks.org/publication.php?c=" + publicationcode
if DEBUG:log_BD("Series in Web:", cWeb)
Process.Start(cWeb)
def DoubleClick(self, sender, e):
global TranslationID
if self.translateinto.Visible == False:
self.translateinto.Visible = True
TranslationID = self.translatelist.SelectedItem
self.translatelist.Visible = False
self.Controls.Add(self.translateinto)
self.translateinto.Text = self.translatelist.SelectedItem[self.translatelist.SelectedItem.find(" ")+2:].strip(" ")
def ClickT(self, sender, e):
global TitleT
if self.titleT.Tag == "T":
self.titleT.Text = ">title<"
self.titleT.Tag = "L"
TitleT = "L"
else:
self.titleT.Text = ">TiTlE<"
self.titleT.Tag = "T"
TitleT = "T"
except Exception as e:
debuglog()
raise e
def WorkerThread(books):
from System.Windows.Forms import (
Application
)
global aUpdate, TranslationID, f, TitleT #, progress
try:
# Read Language for Characternames
if TranslationID == "":
TranslationID = 'en'
else:
TranslationID = TranslationID[:2]
#progress = Stats()
#progress.CenterToParent()
#progress.Show()
nBook = 1
lErrors = True
log_BD("\n ** Scraping Started ** " + str(books.Count) + " Album(s)", "\n============ " + str(datetime.now().strftime("%A %d %B %Y %H:%M:%S")) + " ===========", 0)
f = ProgressBarDialog(books.Count)
f.Show(ComicRack.MainWindow)
for book in books:
Application.DoEvents()
#progress.modifyStats(nBook, TotBooks, book.Series, str(book.Number))
f.Update("[" + str(nBook) + "/" + str(len(books)) + "] : " + "[" + book.Series +"] #" + book.Number + " - " + book.Title, 1)
f.Refresh()
nBook += 1
try:
ReadInfoDucks(publicationcode, book)
except Exception:
debuglog()
#
# series = 0 title = 1 team = 2 tags = 3 summary = 4 notes = 5 web = 6 chars = 7 year = 8 month = 9 publisher = 10
# editor = 11 penciller = 12 inker = 13 writer = 14 cover = 15 colorist = 16 letterer = 17 language = 18
# genre = 19 format = 20 location = 21 genret = 22
# if Series == 0:
# progress.Hide()
# return
Application.DoEvents()
except:
f.Close()
debuglog()
return False
#progress.Hide()
f.Update("Completed !", 1)
f.Refresh()
f.Close()
return lErrors
def FillDat():
from System.Windows.Forms import (
MessageBox
)
fd = None
for referenceDataName in ['publications', 'characters', 'languages', 'persons']:
cWeb = "https://api-comicrack.ducksmanager.net/comicrack/" + referenceDataName + ("?languagecode=en" if referenceDataName == "characters" else "")
fileName = getReferenceDataFileName(referenceDataName)
if fileExistsAndCreatedToday(fileName):
log_BD("Reference file " + referenceDataName + " is up to date, reading local copy", "", 1)
page = readFile(fileName)
else:
try:
log_BD("Retrieving reference file " + referenceDataName, "", 1)
page = _read_url(cWeb)
log_BD("Retrieved reference file " + referenceDataName, "", 1)
if (fd is None):
fd = ProgressBarDialog(1, "Reading/Rebuilding Local Database")
log_BD("Reading/Rebuilding [" + cWeb + "]", "Local Database ", 1)
log_BD("Storing in [" + fileName + "]", "", 1)
fd.Show(ComicRack.MainWindow)
fd.Update("Reading/Rebuilding [" + cWeb + "]", 1, "Local Database ")
fd.Refresh()
except IOError:
MessageBox.Show('Cannot open URL ' + cWeb + 'for reading')
sys.exit(0)
writeFile(fileName, page)
log_BD("Filling " + referenceDataName + " data", "", 1)
fillReferenceData(referenceDataName, page)
log_BD("Filled " + referenceDataName + " data", "", 1)
if (not fd is None):
fd.Close()
from System.Diagnostics import Process
from System.Threading import Monitor
from System.IO import FileInfo, File
from System.Windows.Forms import (
MessageBox, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton,
DialogResult
)
global settings, bookPublicationname, bookLanguagecode, publicationcode, TranslationID, LStart, DEBUG, TitleT
TranslationID = ""
LStart = ""
TitleT = "L"
bdlogfile = path_combine(__file__[:-len('FromDucks.py')] , "FromDucks_Rename_Log.txt")
if FileInfo(bdlogfile).Exists and FileInfo(bdlogfile).Length > SIZE_RENAME_LOG:
Result = MessageBox.Show(ComicRack.MainWindow, "The File FromDucks_Rename_Log.txt is growing too much: do you want to clean it ?", "Rename Log File", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
if Result == DialogResult.Yes:
File.Delete(bdlogfile)
debuglogfile = path_combine(__file__[:-len('FromDucks.py')] , "FromDucks_Debug_Log.txt")
if FileInfo(debuglogfile).Exists and FileInfo(debuglogfile).Length > SIZE_DEBUG_LOG:
Result = MessageBox.Show(ComicRack.MainWindow, "The File FromDucks_Debug_Log.txt is growing too much: do you want to clean it ?", "Debug Log File", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
if Result == DialogResult.Yes:
File.Delete(debuglogfile)
Spath = sys.path[:]
del Spath[0]
#Just in case no paths were found
if not Spath:
MessageBox.Show("The script cannot find the locations of the scripts. Please try restarting ComicRack.")
return
FillDat()
bookPublicationname = books[0].Series
bookLanguagecode = books[0].LanguageISO
# Ensure file exists, but do not read here
bf = BuilderForm()
if bf.ShowDialog() == DialogResult.OK:
if (books):
if WorkerThread(books):
Monitor.Enter(ComicRack.MainWindow)
log_BD("\nAlbum(s) scraped !", "", 0)
log_BD("============= " + str(datetime.now().strftime("%A %d %B %Y %H:%M:%S")) + " =============", "\n\n", 0)
rdlg = MessageBox.Show(ComicRack.MainWindow, "Scrape Completed ! \n\nOpen Rename Log ?", "FromDucks", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
if rdlg == DialogResult.Yes:
# open rename log automatically
if FileInfo(path_combine(__file__[:-len('FromDucks.py')] , "FromDucks_Rename_Log.txt")).Exists:
Process.Start (path_combine(__file__[:-len('FromDucks.py')] , "FromDucks_Rename_Log.txt"))
else:
Monitor.Enter(ComicRack.MainWindow)
log_BD("\n!! Errors in scraping !!", "", 0)
log_BD("============= " + str(datetime.now().strftime("%A %d %B %Y %H:%M:%S")) + " =============", "\n\n", 0)
rdlg = MessageBox.Show(ComicRack.MainWindow, "Scrape ended with errors ! \n\nOpen Debug Log ?", "FromDucks", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
if rdlg == DialogResult.Yes:
# open debug log automatically
if FileInfo(path_combine(__file__[:-len('FromDucks.py')] , "FromDucks_Debug_Log.txt")).Exists:
Process.Start (path_combine(__file__[:-len('FromDucks.py')] , "FromDucks_Debug_Log.txt"))
Monitor.Exit(ComicRack.MainWindow)
def getReferenceDataFileName(referenceDataName):
return path_combine(__file__[:-len('FromDucks.py')] , referenceDataName + ".json")
def readFile(fileName):
try:
if 'System' in sys.modules:
from System.IO import StreamReader
from System.Text import Encoding
reader = StreamReader(fileName, Encoding.UTF8)
content = reader.ReadToEnd()
reader.Close()
return content
else:
try:
return open(fileName, 'r', encoding='utf-8').read()
except TypeError:
import codecs
return codecs.open(fileName, 'r', 'utf-8').read()
except Exception as e:
raise e
def writeFile(fileName, content):
try:
log_BD("Writing file:", fileName, 1)
if 'System' in sys.modules:
from System.IO import StreamWriter
from System.Text import Encoding
writer = StreamWriter(fileName, False, Encoding.UTF8)
writer.Write(content)
writer.Close()
else:
try:
open(fileName, 'w', encoding='utf-8').write(content)
except TypeError:
import codecs
codecs.open(fileName, 'w', 'utf-8').write(content)
except Exception as e:
raise e
def fileExistsAndCreatedToday(fileName):
try:
if 'System' in sys.modules:
from System.IO import FileInfo
from System import DateTime
fi = FileInfo(fileName)
if fi.Exists:
if fi.CreationTime.Date == DateTime.Now.Date:
return True
else:
return False
else:
return False
else:
import os
import time
if os.path.exists(fileName):
creation_time = os.path.getmtime(fileName)
creation_date = time.localtime(creation_time)
current_date = time.localtime()
if (creation_date.tm_year == current_date.tm_year and
creation_date.tm_mon == current_date.tm_mon and
creation_date.tm_mday == current_date.tm_mday):
return True
else:
return False
else:
return False
except Exception as e:
raise e
def sstr(object):
''' safely converts the given object into a string (sstr = safestr) '''
if object is None:
return '<None>'
if is_string(object):
# this is needed, because str() breaks on some strings that have unicode
# characters, due to a python bug. (all strings in python are unicode.)
return object
return str(object)
def is_string(object):
''' returns a boolean indicating whether the given object is a string '''
if object is None:
return False
return isinstance(object, str)
def _read_url(url):
if 'System' in sys.modules:
from System.Net import HttpWebRequest, DecompressionMethods, WebException, HttpStatusCode
from System.Text import Encoding
from System.IO import StreamReader
try:
Req = HttpWebRequest.Create(url)
Req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip
Req.Timeout = 5000 # milliseconds
try:
webresponse = Req.GetResponse()
except WebException as ex: