-
Notifications
You must be signed in to change notification settings - Fork 1
/
ms-CEESpring2018.py
1413 lines (1229 loc) · 85.1 KB
/
ms-CEESpring2018.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Call:
python pwb.py masti/ms-CEESpring2018.py -page:"Szablon:CEE Spring 2018" -outpage:"meta:Wikimedia CEE Spring 2018/Statistics" -summary:"Bot updates statistics"
python pwb.py masti/ms-CEESpring2018.py -page:"Szablon:CEE Spring 2018" -outpage:"Wikipedysta:Masti/CEE Spring 2017" -summary:"Bot updates statistics"
Use global -simulate option for test purposes. No changes to live wiki
will be done.
The following parameters are supported:
¶ms;
-always If used, the bot won't ask if it should file the message
onto user talk page.
-outpage Results page; otherwise "Wikipedysta:mastiBot/test" is used
-maxlines Max number of entries before new subpage is created; default 1000
-text: Use this text to be added; otherwise 'Test' is used
-replace: Dont add text but replace it
-top Place additional text on top of the page
-summary: Set the action summary message for the edit.
-negative: mark if text not in page
-v: make verbose output
-vv: make even more verbose output
"""
#
# (C) Pywikibot team, 2006-2016
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals
__version__ = '$Id: c1795dd2fb2de670c0b4bddb289ea9d13b1e9b3f $'
#
import pywikibot
from pywikibot import pagegenerators
import re
from pywikibot import textlib
from datetime import datetime
import pickle
from pywikibot import (
config, config2,
)
from pywikibot.bot import (
MultipleSitesBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot)
#SingleSiteBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot)
from pywikibot.tools import issue_deprecation_warning
# This is required for the text that is shown when you run this script
# with the parameter -help.
docuReplacements = {
'¶ms;': pagegenerators.parameterHelp
}
CEEtemplates = {'pl' : 'Szablon:CEE Spring 2018', 'az' : 'Şablon:Vikibahar 2018', 'ba' : 'Ҡалып:Вики-яҙ 2018', 'be' : 'Шаблон:CEE Spring 2018', 'be-tarask' : 'Шаблён:Артыкул ВікіВясны-2018', 'bg' : 'Шаблон:CEE Spring 2018', 'de' : 'Vorlage:CEE Spring 2018', 'el' : 'Πρότυπο:CEE Spring 2018', 'et' : 'Mall:CEE Spring 2018', 'hr' : 'Predložak:CEE proljeće 2018.', 'hy' : 'Կաղապար:CEE Spring 2018', 'ka' : 'თარგი:ვიკიგაზაფხული 2018', 'lv' : 'Veidne:CEE Spring 2018', 'lt' : 'Šablonas:VRE 2018', 'mk' : 'Шаблон:СИЕ Пролет 2018', 'ro' : 'Format:Wikimedia CEE Spring 2018', 'ru' : 'Шаблон:Вики-весна 2018', 'sr' : 'Шаблон:ЦЕЕ пролеће 2018', 'tr' : 'Şablon:Vikibahar 2018', 'uk' : 'Шаблон:CEE Spring 2018' }
countryList =[ u'Albania', u'Armenia', u'Austria', u'Azerbaijan', u'Bashkortostan', u'Belarus', u'Bosnia and Herzegovina', u'Bulgaria', u'Crimean Tatars', u'Croatia', u'Czechia', u'Erzia', u'Esperanto', u'Estonia', u'Georgia', u'Greece', u'Hungary', u'Kazakhstan', u'Kosovo', u'Latvia', u'Lithuania', u'Macedonia', u'Moldova', u'Poland', u'Romania', u'Republic of Srpska', u'Russia', u'Serbia', u'Slovakia', u'Tatarstan', u'Turkey', u'Ukraine', u'Other', u'Empty' ]
countryNames = {
'pl':{ 'Albania':'Albania', 'Austria':'Austria', 'Azerbejdżan':'Azerbaijan', 'Baszkortostan':'Bashkortostan', 'Białoruś':'Belarus', 'Bułgaria':'Bulgaria', 'Armenia':'Armenia', 'Bośnia i Hercegowina':'Bosnia and Herzegovina', 'Erzja':'Erzia', 'Esperanto':'Esperanto', 'Estonia':'Estonia', 'Gruzja':'Georgia', 'Czechy':'Czechia', 'Chorwacja':'Croatia', 'Kosowo':'Kosovo', 'Tatarzy krymscy':'Crimean Tatars', 'Litwa':'Lithuania', 'Łotwa':'Latvia', 'Węgry':'Hungary', 'Macedonia':'Macedonia', 'Mołdawia':'Moldova', 'Polska':'Poland', 'Rosja':'Russia', 'Rumunia':'Romania', 'Republika Serbska':'Republic of Srpska', 'Serbia':'Serbia', 'Słowacja':'Slovakia', 'Turcja':'Turkey', 'Ukraina':'Ukraine', 'Grecja':'Greece', 'Kazachstan':'Kazakhstan', 'Tatarstan':'Tatarstan'},
'az':{ 'Albaniya':'Albania', 'Avstriya':'Austria', 'Azərbaycan':'Azerbaijan', 'Başqırdıstan':'Bashkortostan', 'Belarus':'Belarus', 'Bolqarıstan':'Bulgaria', 'Ermənistan':'Armenia', 'Bosniya və Herseqovina':'Bosnia and Herzegovina', 'Erzya':'Erzia', 'Esperantida':'Esperanto', 'Estoniya':'Estonia', 'Gürcüstan':'Georgia', 'Çexiya':'Czechia', 'Xorvatiya':'Croatia', 'Kosovo':'Kosovo', 'Krımtatar':'Crimean Tatars', 'Krım tatarları':'Crimean Tatars', 'Krım-Tatar':'Crimean Tatars', 'Litva':'Lithuania', 'Latviya':'Latvia', 'Macarıstan':'Hungary', 'Makedoniya':'Macedonia', 'Moldova':'Moldova', 'Polşa':'Poland', 'Rusiya':'Russia', 'Rumıniya':'Romania', 'Serb Respublikası':'Republic of Srpska', 'Serbiya':'Serbia', 'Slovakiya':'Slovakia', 'Türkiyə':'Turkey', 'Ukrayna':'Ukraine', 'Yunanıstan':'Greece', 'Qazaxıstan':'Kazakhstan', },
'ba':{ 'Албания':'Albania', 'Австрия':'Austria', 'Әзербайжан':'Azerbaijan', 'Башҡортостан':'Bashkortostan', 'Белоруссия':'Belarus', 'Беларусь':'Belarus', 'Болгария':'Bulgaria', 'Әрмәнстан':'Armenia', 'Босния һәм Герцеговина':'Bosnia and Herzegovina', 'Эрзя':'Erzia', 'Эсперантида':'Esperanto', 'Эстония':'Estonia', 'Грузия':'Georgia', 'Чехия':'Czechia', 'Хорватия':'Croatia', 'Косово':'Kosovo', 'Ҡырым Республикаһы':'Crimean Tatars', 'Ҡырым татарҙары':'Crimean Tatars', 'Литва':'Lithuania', 'Латвия':'Latvia', 'Венгрия':'Hungary', 'Македония':'Macedonia', 'Молдавия':'Moldova', 'Польша':'Poland', 'Рәсәй':'Russia', 'Румыния':'Romania', 'Серб Республикаһы':'Republic of Srpska', 'Сербия':'Serbia', 'Словакия':'Slovakia', 'Төркиә':'Turkey', 'Украина':'Ukraine', 'Греция':'Greece', 'Ҡаҙағстан':'Kazakhstan', },
'be':{ 'Албанія':'Albania', 'Аўстрыя':'Austria', 'Азербайджан':'Azerbaijan', 'Башкартастан':'Bashkortostan', 'Беларусь':'Belarus', 'Балгарыя':'Bulgaria', 'Арменія':'Armenia', 'Боснія і Герцагавіна':'Bosnia and Herzegovina', 'Эрзя':'Erzia', 'Эсперанта':'Esperanto', 'Эстонія':'Estonia', 'Грузія':'Georgia', 'Чэхія':'Czechia', 'Харватыя':'Croatia', 'Рэспубліка Косава':'Kosovo', 'Крымскія татары':'Crimean Tatars', 'Літва':'Lithuania', 'Латвія':'Latvia', 'Венгрыя':'Hungary', 'Македонія':'Macedonia', 'Малдова':'Moldova', 'Польшча':'Poland', 'Расія':'Russia', 'Румынія':'Romania', 'Рэспубліка Сербская':'Republic of Srpska', 'Сербія':'Serbia', 'Славакія':'Slovakia', 'Турцыя':'Turkey', 'Украіна':'Ukraine', 'Грэцыя':'Greece', 'Казахстан':'Kazakhstan', },
'be-tarask':{ 'Альбанія':'Albania', 'Аўстрыя':'Austria', 'Азэрбайджан':'Azerbaijan', 'Башкартастан':'Bashkortostan', 'Беларусь':'Belarus', 'Баўгарыя':'Bulgaria', 'Армэнія':'Armenia', 'Босьнія і Герцагавіна':'Bosnia and Herzegovina', 'Эрзя':'Erzia', 'Эспэранта':'Esperanto', 'Эстонія':'Estonia', 'Грузія':'Georgia', 'Чэхія':'Czechia', 'Харватыя':'Croatia', 'Косава':'Kosovo', 'крымскія татары':'Crimean Tatars', 'Крымскія татары':'Crimean Tatars', 'Летува':'Lithuania', 'Латвія':'Latvia', 'Вугоршчына':'Hungary', 'Македонія':'Macedonia', 'Малдова':'Moldova', 'Польшча':'Poland', 'Расея':'Russia', 'Румынія':'Romania', 'Рэспубліка Сэрбская':'Republic of Srpska', 'Сэрбія':'Serbia', 'Славаччына':'Slovakia', 'Турэччына':'Turkey', 'Украіна':'Ukraine', 'Грэцыя':'Greece', 'Казахстан':'Kazakhstan', },
'bg':{ 'Албания':'Albania', 'Австрия':'Austria', 'Азербайджан':'Azerbaijan', 'Башкортостан':'Bashkortostan', 'Беларус':'Belarus', 'България':'Bulgaria', 'Армения':'Armenia', 'Босна и Херцеговина':'Bosnia and Herzegovina', 'Ерзяни':'Erzia','ерзяни':'Erzia','Эрзя':'Erzia', 'Есперанто':'Esperanto', 'Естония':'Estonia', 'Грузия':'Georgia', 'Чехия':'Czechia', 'Хърватия':'Croatia', 'Косово':'Kosovo', 'кримски татари':'Crimean Tatars', 'Кримски татари':'Crimean Tatars', 'Литва':'Lithuania', 'Латвия':'Latvia', 'Унгария':'Hungary', 'Република Македония':'Macedonia', 'Македония':'Macedonia', 'Молдова':'Moldova', 'Полша':'Poland', 'Русия':'Russia', 'Румъния':'Romania', 'Република Сръбска':'Republic of Srpska', 'Сърбия':'Serbia', 'Словакия':'Slovakia', 'Турция':'Turkey', 'Украйна':'Ukraine', 'Гърция':'Greece', 'Казахстан':'Kazakhstan', 'Татарстан':'Tatarstan'},
'de':{ 'Albanien':'Albania', 'Österreich':'Austria', 'Aserbaidschan':'Azerbaijan', 'Baschkortostan':'Bashkortostan', 'Weißrussland':'Belarus', 'Bulgarien':'Bulgaria', 'Armenien':'Armenia', 'Bosnien und Herzegowina':'Bosnia and Herzegovina', 'Ersja':'Erzia', 'Esperanto':'Esperanto', 'Estland':'Estonia', 'Georgien':'Georgia', 'Tschechien':'Czechia', 'Kroatien':'Croatia', 'Kosovo':'Kosovo', 'Krimtataren':'Crimean Tatars', 'Litauen':'Lithuania', 'Lettland':'Latvia', 'Ungarn':'Hungary', 'Mazedonien':'Macedonia', 'Moldau':'Moldova', 'Moldawien':'Moldova', 'Polen':'Poland', 'Russland':'Russia', 'Rumänien':'Romania', 'Republika Srpska':'Republic of Srpska', 'Serbien':'Serbia', 'Slowakei':'Slovakia', 'Türkei':'Turkey', 'Ukraine':'Ukraine', 'Griechenland':'Greece', 'Kasachstan':'Kazakhstan', },
'crh':{ 'Arnavutlıq':'Albania', 'Avstriya':'Austria', 'Azerbaycan':'Azerbaijan', 'Başqırtistan':'Bashkortostan', 'Belarus':'Belarus', 'Bulğaristan':'Bulgaria', 'Ermenistan':'Armenia', 'Bosna ve Hersek':'Bosnia and Herzegovina', 'Esperanto':'Esperanto', 'Estoniya':'Estonia', 'Gürcistan':'Georgia', 'Çehiya':'Czechia', 'Hırvatistan':'Croatia', 'Kosovo':'Kosovo', 'Qırımtatarlar':'Crimean Tatars', 'Litvaniya':'Lithuania', 'Latviya':'Latvia', 'Macaristan':'Hungary', 'Makedoniya':'Macedonia', 'Moldova':'Moldova', 'Lehistan':'Poland', 'Rusiye':'Russia', 'Romaniya':'Romania', 'Sırb Cumhuriyeti':'Republic of Srpska', 'Sırbistan':'Serbia', 'Slovakiya':'Slovakia', 'Türkiye':'Turkey', 'Ukraina':'Ukraine', 'Yunanistan':'Greece', 'Qazahistan':'Kazakhstan', },
'el':{ 'Αλβανία':'Albania', 'Αυστρία':'Austria', 'Αζερμπαϊτζάν':'Azerbaijan', 'Μπασκορτοστάν':'Bashkortostan', 'Λευκορωσία':'Belarus', 'Βουλγαρία':'Bulgaria', 'Αρμενία':'Armenia', 'Βοσνία και Ερζεγοβίνη':'Bosnia and Herzegovina', 'Έρζυα':'Erzia', 'Εσπεράντο':'Esperanto', 'Εσθονία':'Estonia', 'Γεωργία':'Georgia', 'Τσεχία':'Czechia', 'Κροατία':'Croatia', 'Κόσοβο':'Kosovo', 'Τατάροι Κριμαίας':'Crimean Tatars', 'Λιθουανία':'Lithuania', 'Λετονία':'Latvia', 'Ουγγαρία':'Hungary', 'πΓΔΜ':'Macedonia', 'Μολδαβία':'Moldova', 'Πολωνία':'Poland', 'Ρωσία':'Russia', 'Ρουμανία':'Romania', 'Δημοκρατία της Σερβίας':'Republic of Srpska', 'Σερβική Δημοκρατία':'Republic of Srpska', 'Σερβία':'Serbia', 'Σλοβακία':'Slovakia', 'Τουρκία':'Turkey', 'Ουκρανία':'Ukraine', 'Ελλάδα':'Greece', 'Καζακστάν':'Kazakhstan', },
'myv':{ 'Албания':'Albania', 'Австрия':'Austria', 'Азербайджан':'Azerbaijan', 'Башкирия':'Bashkortostan', 'Белорузия':'Belarus', 'Болгария':'Bulgaria', 'Армения':'Armenia', 'Босния ды Герцеговина':'Bosnia and Herzegovina', 'Эрзя':'Erzia', 'Эсперанто':'Esperanto', 'Эстэнь':'Estonia', 'Грузия':'Georgia', 'Чехия':'Czechia', 'Хорватия':'Croatia', 'Литва':'Lithuania', 'Латвия':'Latvia', 'Мадьяронь':'Hungary', 'Македония':'Macedonia', 'Молдавия':'Moldova', 'Польша':'Poland', 'Россия':'Russia', 'Румыния':'Romania', 'Сербань Республикась':'Republic of Srpska', 'Сербия':'Serbia', 'Словакия':'Slovakia', 'Турция':'Turkey', 'Украина':'Ukraine', 'Греция':'Greece', 'Казахстан':'Kazakhstan', },
'eo':{ 'Albanio':'Albania', 'Aŭstrio':'Austria', 'Azerbajĝano':'Azerbaijan', 'Baŝkirio':'Bashkortostan', 'Belorusio':'Belarus', 'Bulgario':'Bulgaria', 'Armenio':'Armenia', 'Bosnio kaj Hercegovino':'Bosnia and Herzegovina', 'Erzja':'Erzia', 'Esperantujo':'Esperanto', 'Esperanto':'Esperanto', 'Estonio':'Estonia', 'Kartvelio':'Georgia', 'Ĉeĥio':'Czechia', 'Kroatio':'Croatia', 'Kosovo':'Kosovo', 'Krimeo':'Crimean Tatars', 'Krime-tataroj':'Crimean Tatars', 'Litovio':'Lithuania', 'Latvio':'Latvia', 'Hungario':'Hungary', 'Makedonio':'Macedonia', 'Moldava':'Moldova', 'Pollando':'Poland', 'Rusio':'Russia', 'Rumanio':'Romania', 'Serba Respubliko':'Republic of Srpska', 'Serbio':'Serbia', 'Slovakio':'Slovakia', 'Turkio':'Turkey', 'Ukrainio':'Ukraine', 'Grekio':'Greece', 'Kazaĥio':'Kazakhstan', },
'hy':{ 'Ալբանիա':'Albania', 'Ավստրիա':'Austria', 'Ադրբեջան':'Azerbaijan', 'Ադրբեջանական Հանրապետություն':'Azerbaijan', 'Բաշկորտոստան':'Bashkortostan', 'Բելառուս':'Belarus', 'Բուլղարիա':'Bulgaria', 'Հայաստան':'Armenia', 'Բոսնիա և Հերցեգովինա':'Bosnia and Herzegovina', 'Էսպերանտո':'Esperanto', 'Էստոնիա':'Estonia', 'Էրզիա':'Erzia', 'Վրաստան':'Georgia', 'Չեխիա':'Czechia', 'Խորվաթիա':'Croatia', 'Կոսովո':'Kosovo', 'Ղրիմի թաթարներ':'Crimean Tatars', 'Լիտվա':'Lithuania', 'Լատվիա':'Latvia', 'Հունգարիա':'Hungary', 'Մակեդոնիա':'Macedonia', 'Մակեդոնիայի Հանրապետություն':'Macedonia', 'Մոլդովա':'Moldova', 'Լեհաստան':'Poland', 'Ռուսաստան':'Russia', 'Ռումինիա':'Romania', 'Սերբիայի Հանրապետություն':'Serbia', 'Սերբիա':'Serbia', 'Սլովակիա':'Slovakia', 'Թուրքիա':'Turkey', 'Ուկրաինա':'Ukraine', 'Հունաստան':'Greece', 'Ղազախստան':'Kazakhstan', },
'ka':{ 'ალბანეთი':'Albania', 'ავსტრია':'Austria', 'აზერბაიჯანი':'Azerbaijan', 'ბაშკირეთი':'Bashkortostan', 'ბელარუსი':'Belarus', 'ბულგარეთი':'Bulgaria', 'სომხეთი':'Armenia', 'ბოსნია და ჰერცეგოვინა':'Bosnia and Herzegovina', 'ესპერანტო':'Esperanto', 'ესტონეთი':'Estonia', 'საქართველო':'Georgia', 'ჩეხეთი':'Czechia', 'ხორვატია':'Croatia', 'კოსოვო':'Kosovo', 'ყირიმელი თათრები':'Crimean Tatars', 'ლიტვა':'Lithuania', 'ლატვია':'Latvia', 'უნგრეთი':'Hungary', 'მაკედონია':'Macedonia', 'მოლდოვა':'Moldova', 'პოლონეთი':'Poland', 'რუსეთი':'Russia', 'რუმინეთი':'Romania', 'სერბთა რესპუბლიკა':'Republic of Srpska', 'სერბეთი':'Serbia', 'სლოვაკეთი':'Slovakia', 'თურქეთი':'Turkey', 'უკრაინა':'Ukraine', 'საბერძნეთი':'Greece', 'ყაზახეთი':'Kazakhstan', },
'lv':{ 'Albānija':'Albania', 'Austrija':'Austria', 'Azerbaidžāna':'Azerbaijan', 'Baškortostāna':'Bashkortostan', 'Baltkrievija':'Belarus', 'Bulgārija':'Bulgaria', 'Armēnija':'Armenia', 'Bosnija un Hercegovina':'Bosnia and Herzegovina', 'erzji':'Erzia', 'Erzju':'Erzia', 'Esperanto':'Esperanto', 'Igaunija':'Estonia', 'Gruzija':'Georgia', 'Čehija':'Czechia', 'Horvātija':'Croatia', 'Kosova':'Kosovo', 'Krimas tatāri':'Crimean Tatars', 'Lietuva':'Lithuania', 'Latvija':'Latvia', 'Ungārija':'Hungary', 'Maķedonija':'Macedonia', 'Moldova':'Moldova', 'Polija':'Poland', 'Krievija':'Russia', 'Rumānija':'Romania', 'Serbu Republika':'Republic of Srpska', 'Serbija':'Serbia', 'Slovākija':'Slovakia', 'Turcija':'Turkey', 'Ukraina':'Ukraine', 'Grieķija':'Greece', 'Kazahstāna':'Kazakhstan', },
'lt':{ 'Albanija':'Albania', 'Austrija':'Austria', 'Azerbaidžanas':'Azerbaijan', 'Baškirija':'Bashkortostan', 'Baltarusija':'Belarus', 'Bulgarija':'Bulgaria', 'Armėnija':'Armenia', 'Bosnija ir Hercegovina':'Bosnia and Herzegovina', 'Erzių':'Erzia', 'Esperanto':'Esperanto', 'Estija':'Estonia', 'Gruzija':'Georgia', 'Čekija':'Czechia', 'Kroatija':'Croatia', 'Kosovas':'Kosovo', 'Krymas':'Crimean Tatars', 'Krymo totoriai':'Crimean Tatars', 'Lietuva':'Lithuania', 'Latvija':'Latvia', 'Vengrija':'Hungary', 'Makedonija':'Macedonia', 'Moldavija':'Moldova', 'Lenkija':'Poland', 'Rusija':'Russia', 'Rumunija':'Romania', 'Serbų Respublika':'Republic of Srpska', 'Serbų respublika':'Republic of Srpska', 'Serbija':'Serbia', 'Serbijos respublika':'Serbia', 'Slovakija':'Slovakia', 'Turkija':'Turkey', 'Ukraina':'Ukraine', 'Graikija':'Greece', 'Kazachstanas':'Kazakhstan', 'Tatarstanas':'Tatarstan' },
'mk':{ 'Албанија':'Albania', 'Австрија':'Austria', 'Азербејџан':'Azerbaijan', 'Башкортостан':'Bashkortostan', 'Bashkortostani':'Bashkortostan', 'Белорусија':'Belarus', 'Бугарија':'Bulgaria', 'Ерменија':'Armenia', 'Босна и Херцеговина':'Bosnia and Herzegovina', 'Ерзја':'Erzia', 'Есперанто':'Esperanto', 'Естонија':'Estonia', 'Грузија':'Georgia', 'Чешка':'Czechia', 'Хрватска':'Croatia', 'Косово':'Kosovo', 'Република Косово':'Kosovo', 'Крим':'Crimean Tatars', 'Кримски Татари':'Crimean Tatars', 'Литванија':'Lithuania', 'Латвија':'Latvia', 'Унгарија':'Hungary', 'Македонија':'Macedonia', 'Молдавија':'Moldova', 'Полска':'Poland', 'Русија':'Russia', 'Романија':'Romania', 'Република Српска':'Republic of Srpska', 'Србија':'Serbia', 'Словачка':'Slovakia', 'Турција':'Turkey', 'Украина':'Ukraine', 'Грција':'Greece', 'Казахстан':'Kazakhstan', 'Татарстан':'Tatarstan' },
'ro':{ 'Albania':'Albania', 'Austria':'Austria', 'Azerbaidjan':'Azerbaijan', 'Bașkortostan':'Bashkortostan', 'Bașchiria':'Bashkortostan', 'Belarus':'Belarus', 'Bulgaria':'Bulgaria', 'Armenia':'Armenia', 'Bosnia și Herțegovina':'Bosnia and Herzegovina', 'Esperanto':'Esperanto', 'Estonia':'Estonia', 'Georgia':'Georgia', 'Cehia':'Czechia', 'Croația':'Croatia', 'Kosovo':'Kosovo', 'Crimeea':'Crimean Tatars', 'Lituania':'Lithuania', 'Letonia':'Latvia', 'Ungaria':'Hungary', 'Macedonia':'Macedonia', 'Republica Moldova':'Moldova', 'Polonia':'Poland', 'Rusia':'Russia', 'România':'Romania', 'Republika Srpska':'Republic of Srpska', 'Serbia':'Serbia', 'Slovacia':'Slovakia', 'Turcia':'Turkey', 'Ucraina':'Ukraine', 'Grecia':'Greece', 'Kazahstan':'Kazakhstan', 'Erzia':'Erzia'},
'ru':{ 'Албания':'Albania', 'Австрия':'Austria', 'Азербайджан':'Azerbaijan', 'Башкортостан':'Bashkortostan', 'Беларусь':'Belarus', 'Белоруссия':'Belarus', 'Болгария':'Bulgaria', 'Армения':'Armenia', 'Босния и Герцеговина':'Bosnia and Herzegovina', 'Эрзя':'Erzia', 'Эсперантида':'Esperanto', 'Эсперанто':'Esperanto', 'Эстония':'Estonia', 'Грузия':'Georgia', 'Чехия':'Czechia', 'Хорватия':'Croatia', 'Косово':'Kosovo', 'Крымские татары':'Crimean Tatars', 'Литва':'Lithuania', 'Латвия':'Latvia', 'Венгрия':'Hungary', 'Республика Македония':'Macedonia', 'Македония':'Macedonia', 'Молдавия':'Moldova', 'Польша':'Poland', 'Россия':'Russia', 'Румыния':'Romania', 'Сербская Республика':'Republic of Srpska', 'Республика Сербская':'Republic of Srpska', 'Сербия':'Serbia', 'Словакия':'Slovakia', 'Турция':'Turkey', 'Украина':'Ukraine', 'Греция':'Greece', 'Казахстан':'Kazakhstan', },
'sq':{ 'Shqipërisë':'Albania', 'Shqipëria':'Albania', 'Austria':'Austria', 'Azerbajxhanit':'Azerbaijan', 'Azerbajxhani':'Azerbaijan', 'Bashkortostani':'Bashkortostan', 'Bjellorusia':'Belarus', 'Bullgaria':'Bulgaria', 'Armenisë':'Armenia', 'Armenia':'Armenia', 'Bosnja dhe Hercegovina':'Bosnia and Herzegovina', 'Gjuha esperanto':'Esperanto', 'Estonia':'Estonia', 'Gjeorgjisë':'Georgia', 'Gjeorgjia':'Georgia', 'Republika Çeke':'Czechia', 'Kroacisë':'Croatia', 'Kroacia':'Croatia', 'Kosovës':'Kosovo', 'Kosova':'Kosovo', 'Lituania':'Lithuania', 'Letonia':'Latvia', 'Hungaria':'Hungary', 'Maqedonisë':'Macedonia', 'Moldavinë':'Moldova', 'Moldavia':'Moldova', 'Polonisë':'Poland', 'Polonia':'Poland', 'Rusisë':'Russia', 'Rusia':'Russia', 'Rumania':'Romania', 'Serbia':'Serbia', 'Sllovakia':'Slovakia', 'Turqisë':'Turkey', 'Turqia':'Turkey', 'Ukraina':'Ukraine', 'Greqisë':'Greece', 'Greqia':'Greece', 'Kazakistanin':'Kazakhstan', 'Kazakistani':'Kazakhstan', },
'sr':{ 'Албанија':'Albania', 'Аустрија':'Austria', 'Атербејџан':'Azerbaijan', 'Азербејџан':'Azerbaijan', 'Башкортостан':'Bashkortostan', 'Белорусија':'Belarus', 'Бугарска':'Bulgaria', 'Јерменија':'Armenia', 'Босна и Херцеговина':'Bosnia and Herzegovina', 'Ерзја':'Erzia', 'Есперанто':'Esperanto', 'Естонија':'Estonia', 'Грузија':'Georgia', 'Чешка':'Czechia', 'Hrvatska':'Croatia', 'Хрватска':'Croatia', 'Република Косово':'Kosovo', 'Кримски Татари':'Crimean Tatars', 'Литванија':'Lithuania', 'Летонија':'Latvia', 'Мађарска':'Hungary', 'Македонија':'Macedonia', 'Република Македонија':'Macedonia', 'Молдавија':'Moldova', 'Пољска':'Poland', 'Руска Империја':'Russia', 'Rusija':'Russia', 'Русија':'Russia', 'Румунија':'Romania', 'Република Српска':'Republic of Srpska', 'Србија':'Serbia', 'Словачка':'Slovakia', 'Турска':'Turkey', 'Украјина':'Ukraine', 'грчка':'Greece', 'Грчка':'Greece', 'Казахстан':'Kazakhstan', },
'tt':{ 'Албания':'Albania', 'Австрия':'Austria', 'Азәрбайҗан':'Azerbaijan', 'Башкортстан':'Bashkortostan', 'Беларусия':'Belarus', 'Болгария':'Bulgaria', 'Әрмәнстан':'Armenia', 'Босния һәм Герцеговина':'Bosnia and Herzegovina', 'Эрзя':'Erzia', 'Ирзә':'Erzia', 'Эсперанто':'Esperanto', 'Эстония':'Estonia', 'Гөрҗистан':'Georgia', 'Чехия':'Czechia', 'Хорватия':'Croatia', 'Косово Җөмһүрияте':'Kosovo', 'Кырым татарлары':'Crimean Tatars', 'Литва':'Lithuania', 'Latviä':'Latvia', 'Маҗарстан':'Hungary', 'Македония Җөмһүрияте':'Macedonia', 'Македония':'Macedonia', 'Молдова':'Moldova', 'Польша':'Poland', 'РФ':'Russia', 'Русия':'Russia', 'Румыния':'Romania', 'Сербия':'Serbia', 'Словакия':'Slovakia', 'Төркия':'Turkey', 'Украина':'Ukraine', 'Греция':'Greece', 'Казакъстан':'Kazakhstan', },
'tr':{ 'Arnavutluk':'Albania', 'Avusturya':'Austria', 'Azerbaycan':'Azerbaijan', 'Başkurdistan':'Bashkortostan', 'Beyaz Rusya':'Belarus', 'Bulgaristan':'Bulgaria', 'Ermenistan':'Armenia', 'Bosna-Hersek':'Bosnia and Herzegovina', 'Erzya':'Erzia', 'Esperanto':'Esperanto', 'Estonya':'Estonia', 'Gürcistan':'Georgia', 'Çek Cumhuriyeti':'Czechia', 'Hırvatistan':'Croatia', 'Kosova':'Kosovo', 'Kırım':'Crimean Tatars', 'Kırım Tatar':'Crimean Tatars', 'Kırım Tatarları':'Crimean Tatars', 'Litvanya':'Lithuania', 'Letonya':'Latvia', 'Macaristan':'Hungary', 'Makedonya Cumhuriyeti':'Macedonia', 'Makedonya':'Macedonia', 'Moldova':'Moldova', 'Polonya':'Poland', 'Rusya':'Russia', 'Romanya':'Romania', 'Sırp Cumhuriyeti':'Republic of Srpska', 'Sırbistan':'Serbia', 'Slovakya':'Slovakia', 'Türkiye':'Turkey', 'Ukrayna':'Ukraine', 'Yunanistan':'Greece', 'Kazakistan':'Kazakhstan', 'Tataristan':'Tatarstan' },
'uk':{ 'Албанія':'Albania', 'Австрія':'Austria', 'Азербайджан':'Azerbaijan', 'Башкортостан':'Bashkortostan', 'Білорусь':'Belarus', 'Болгарія':'Bulgaria', 'Вірменія':'Armenia', 'Боснія':'Bosnia and Herzegovina', 'Боснія і Герцеговина':'Bosnia and Herzegovina', 'Ерзя':'Erzia', 'Есперантида':'Esperanto', 'Есперанто':'Esperanto', 'Естонія':'Estonia', 'Грузія':'Georgia', 'Чехія':'Czechia', 'Хорватія':'Croatia', 'Косово':'Kosovo', 'Кримські Татари':'Crimean Tatars', 'Кримські татари':'Crimean Tatars', 'Литва':'Lithuania', 'Латвія':'Latvia', 'Угорщина':'Hungary', 'Македонія':'Macedonia', 'Молдова':'Moldova', 'Польща':'Poland', 'Російська Федерація':'Russia', 'Росія':'Russia', 'Румунія':'Romania', 'Республіка Сербська':'Republic of Srpska', 'Сербія':'Serbia', 'Словаччина':'Slovakia', 'Туреччина':'Turkey', 'Туречинна':'Turkey', 'Україна':'Ukraine', 'Греція':'Greece', 'Казахстан':'Kazakhstan', },
'hu':{ 'Albánia':'Albania', 'Ausztria':'Austria', 'Azerbajdzsán':'Azerbaijan', 'Baskirföld':'Bashkortostan', 'Belorusz':'Belarus', 'Bulgária':'Bulgaria', 'Örményország':'Armenia', 'Bosznia és Hercegovina':'Bosnia and Herzegovina', 'Eszperantó':'Esperanto', 'Észtország':'Estonia', 'Grúzia':'Georgia', 'Csehország':'Czechia', 'Horvátország':'Croatia', 'Koszovo':'Kosovo', 'Krími tatárok':'Crimean Tatars', 'Litvánia':'Lithuania', 'Lettország':'Latvia', 'Magyarország':'Hungary', 'Macedónia':'Macedonia', 'Moldávia':'Moldova', 'Lengyelország':'Poland', 'Oroszország':'Russia', 'Románia':'Romania', 'Boszniai Szerb Köztársaság':'Republic of Srpska', 'Szerbia':'Serbia', 'Szlovákia':'Slovakia', 'Törökország':'Turkey', 'Ukrajna':'Ukraine', 'Görögország':'Greece', 'Kazahsztán':'Kazakhstan', },
'kk':{ 'Албания':'Albania', 'Аустрия':'Austria', 'Әзірбайжан':'Azerbaijan', 'Башқұртстан':'Bashkortostan', 'Беларусь':'Belarus', 'Болгария':'Bulgaria', 'Армения':'Armenia', 'Босния және Герцеговина':'Bosnia and Herzegovina', 'Эсперанто':'Esperanto', 'Эстония':'Estonia', 'Грузия':'Georgia', 'Чехия':'Czechia', 'Хорватия':'Croatia', 'Косово':'Kosovo', 'Қырым татарлары':'Crimean Tatars', 'Литва':'Lithuania', 'Латвия':'Latvia', 'Мажарстан':'Hungary', 'Македония':'Macedonia', 'Молдова':'Moldova', 'Польша':'Poland', 'Ресей':'Russia', 'Румыния':'Romania', 'Сербия':'Serbia', 'Словакия':'Slovakia', 'Түркия':'Turkey', 'Украина':'Ukraine', 'Грекия':'Greece', 'Қазақстан':'Kazakhstan', },
'et':{ 'Albaania':'Albania', 'Austria':'Austria', 'Aserbaidžaan':'Azerbaijan', 'Baškortostanu':'Bashkortostan', 'Baškortostan':'Bashkortostan', 'Valgevene':'Belarus', 'Bulgaaria':'Bulgaria', 'Armeenia':'Armenia', 'Bosnia ja Hertsegoviina':'Bosnia and Herzegovina', 'Esperanto':'Esperanto', 'Eesti':'Estonia', 'Gruusia':'Georgia', 'Tšehhi':'Czechia', 'Horvaatia':'Croatia', 'Kosovo':'Kosovo', 'Krimski Tatari':'Crimean Tatars', 'Leedu':'Lithuania', 'Läti':'Latvia', 'Ungari':'Hungary', 'Makedoonia':'Macedonia', 'Moldova':'Moldova', 'Poola':'Poland', 'Venemaa':'Russia', 'Rumeenia':'Romania', 'Serblaste Vabariik':'Republic of Srpska', 'Republika Srpska':'Republic of Srpska', 'Serbia':'Serbia', 'Slovakkia':'Slovakia', 'Türgi':'Turkey', 'Ukraina':'Ukraine', 'Kreeka':'Greece', 'Kasahstan':'Kazakhstan', 'Ersa':'Erzia'},
'hr':{ 'Albaniji':'Albania', 'Albanija':'Albania', 'Austriji':'Austria', 'Austrija':'Austria', 'Azerbajdžanu':'Azerbaijan', 'Azerbajdžan':'Azerbaijan', 'Baškortostanu (Bashkortostan)':'Bashkortostan', 'Baškirska':'Bashkortostan', 'Bjelorusiji':'Belarus', 'Bjelorusija':'Belarus', 'Bugarskoj':'Bulgaria', 'Bugarska':'Bulgaria', 'Armeniji':'Armenia', 'Armenija':'Armenia', 'Bosni i Hercegovini':'Bosnia and Herzegovina', 'Bosne i Hercegovine':'Bosnia and Herzegovina', 'Bosna i Hercegovina':'Bosnia and Herzegovina', 'esperantu':'Esperanto', 'Esperanto':'Esperanto', 'Estoniji':'Estonia', 'Estonija':'Estonia', 'Gruziji':'Georgia', 'Gruziji (Georgia)':'Georgia', 'Gruzija':'Georgia', 'Češkoj (Czech)':'Czechia', 'Češka':'Czechia', 'Hrvatskoj':'Croatia', 'Hrvatska':'Croatia', 'Kosovo':'Kosovo', 'Kosovu':'Kosovo', 'Krimskih Tatara':'Crimean Tatars', 'Krimski Tatari':'Crimean Tatars', 'Litvi':'Lithuania', 'Litva':'Lithuania', 'Latviji':'Latvia', 'Latvija':'Latvia', 'Mađarskoj':'Hungary', 'Mađarska':'Hungary', 'Makedoniji':'Macedonia', 'Makedonija':'Macedonia', 'Moldaviji':'Moldova', 'Moldavija':'Moldova', 'Poljskoj':'Poland', 'Poljska':'Poland', 'Rusiji':'Russia', 'Rusija':'Russia', 'Rumunjskoj (Romania)':'Romania', 'Rumunjskoj':'Romania', 'Rumunjska':'Romania', 'Republici Srpskoj':'Republic of Srpska', 'Republika Srpska':'Republic of Srpska', 'Srbiji':'Serbia', 'Srbija':'Serbia', 'Slovačkoj':'Slovakia', 'Slovačkoj (Slovakia)':'Slovakia', 'Slovačka':'Slovakia', 'Turskoj':'Turkey', 'Turska':'Turkey', 'Ukrajini':'Ukraine', 'Ukrajina':'Ukraine', 'Grčkoj':'Greece', 'Grčka':'Greece', 'Kazahstanu':'Kazakhstan', 'Kazahstan':'Kazakhstan', 'Erziji (Erzya)':'Erzia', 'Erziji':'Erzia', 'Erzya':'Erzia'},
}
class BasicBot(
# Refer pywikobot.bot for generic bot classes
#SingleSiteBot, # A bot only working on one site
MultipleSitesBot, # A bot only working on one site
# CurrentPageBot, # Sets 'current_page'. Process it in treat_page method.
# # Not needed here because we have subclasses
ExistingPageBot, # CurrentPageBot which only treats existing pages
NoRedirectPageBot, # CurrentPageBot which only treats non-redirects
AutomaticTWSummaryBot, # Automatically defines summary; needs summary_key
):
"""
An incomplete sample bot.
@ivar summary_key: Edit summary message key. The message that should be used
is placed on /i18n subdirectory. The file containing these messages
should have the same name as the caller script (i.e. basic.py in this
case). Use summary_key to set a default edit summary message.
@type summary_key: str
"""
summary_key = 'basic-changing'
springList = {}
templatesList = {}
authors = {}
authorsData = {}
authorsArticles = {}
missingCount = {}
pagesCount = {}
countryTable = {}
lengthTable = {}
womenAuthors = {} # authors of articles about women k:author v; (count,[list])
otherCountriesList = {'pl':[], 'az':[], 'ba':[], 'be':[], 'be-tarask':[], 'bg':[], 'de':[], 'crh':[], 'el':[], 'et':[], 'myv':[], 'eo':[], 'hr':[], 'hy':[], 'ka':[], 'lv':[], 'lt':[], \
'mk':[], 'ro':[], 'ru':[], 'sq':[], 'sr':[], 'tt':[], 'tr':[], 'uk':[], 'hu':[]}
women = {'pl':0, 'az':0, 'ba':0, 'be':0, 'be-tarask':0, 'bg':0, 'de':0, 'crh':0, 'el':0, 'et':0, 'myv':0, 'eo':0, 'hr':0, 'hy':0, 'ka':0, 'lv':0, 'lt':0, \
'mk':0, 'ro':0, 'ru':0, 'sq':0, 'sr':0, 'tt':0, 'tr':0, 'uk':0, 'hu':0}
countryp = { 'pl':'kraj', 'az':'ölkə', 'ba':'ил', 'be':'краіна', 'be-tarask':'краіна', 'bg':'държава', 'de':'land', 'crh':'memleket', 'el':'country', 'et':'maa', \
'myv':'мастор', 'eo':'country', 'ka':'ქვეყანა', 'lv':'valsts', 'lt':'šalis', 'mk':'земја', 'ro':'țară', 'ru':'страна', 'sq':'country', \
'sr':'држава', 'tt':'ил', 'tr':'ülke', 'uk':'країна', 'hr':'zemlja', 'hy':'երկիր' }
topicp = {'pl':'parametr', 'az':'qadınlar', 'ba':'тема', 'be':'тэма', 'be-tarask':'тэма', 'bg':'тема', 'de':'thema', 'crh':'mevzu', 'el':'topic', 'et':'teema', \
'myv':'тема', 'eo':'topic', 'ka':'თემა', 'lv':'tēma', 'lt':'tema', 'mk':'тема', 'ro':'secțiune', 'ru':'тема', 'sq':'topic', 'sr':'тема', \
'tt':'тема', 'tr':'konu', 'uk':'тема', 'hr':'tema', 'hy':'Թուրքիա|թեմա'}
womenp = {'pl':'kobiety', 'az':'qadınlar', 'ba':'Ҡатын-ҡыҙҙар', 'be':'Жанчыны', 'be-tarask':'жанчыны', 'bg':'жени', 'de':'Frauen','el':'γυναίκες', 'et':'naised', \
'ka':'ქალები', 'lv':'Sievietes','mk':'Жени', 'ro':'Femei', 'ru':'женщины', 'sq':'Gratë', 'sr':'Жене', 'tt':'Хатын-кызлар', 'tr':'Kadın',\
'uk':'жінки', 'hu':'nők', 'hr':'Žene', 'hy':'Կանայք'}
userp = {'pl':'autor', 'az':'istifadəçi', 'ba':'ҡатнашыусы', 'be':'удзельнік', 'be-tarask':'удзельнік', 'bg':'потребител', 'hu':'szerkesztő',\
'de':'benutzer','crh':'qullanıcı','el':'user', 'et':'kasutaja', 'myv':'сёрмадыця', 'eo':'user', 'ka':'მომხმარებელი', 'lv':'dalībnieks', 'lt':'naudotojas',\
'mk':'корисник', 'ro':'utilizator', 'ru':'участник', 'sq':'user', 'sr':'корисник', 'tt':'кулланучы', 'tr':'kullanıcı', 'uk':'користувач', 'hr':'suradnik', 'hy':'մասնակից' }
def __init__(self, generator, **kwargs):
"""
Constructor.
@param generator: the page generator that determines on which pages
to work
@type generator: generator
"""
# Add your own options to the bot and set their defaults
# -always option is predefined by BaseBot class
self.availableOptions.update({
'replace': False, # delete old text and write the new text
'summary': None, # your own bot summary
'text': 'Test', # add this text from option. 'Test' is default
'top': False, # append text on top of the page
'outpage': u'User:mastiBot/test', #default output page
'maxlines': 1000, #default number of entries per page
'testprint': False, # print testoutput
'negative': False, #if True negate behavior i.e. mark pages that DO NOT contain search string
'test': False, # make verbose output
'test2': False, # make verbose output
'test3': False, # make verbose output
'test4': False, # make verbose output
'testartinfo': False, # make verbose output
'testwomen': False, # make verbose output for women table
'testwomenauthors': False, # make verbose output for women authors table
'testnewbie': False, # make verbose output for newbies
'testlength': False, # make verbose output for article length
'testpickle': False, # make verbose output for article list load/save
'testauthorwiki': False, # make verbose output for author/wiki
'short': False, # make short run
'append': False,
'reset': False, # rebuild database from scratch
'progress': False, #report progress
})
# call constructor of the super class
#super(BasicBot, self).__init__(site=True, **kwargs)
super(BasicBot, self).__init__(**kwargs)
# assign the generator to the bot
self.generator = generator
def articleExists(self,art):
#check if article already in springList
result = False
lang = art.site.code
title = art.title()
if self.getOption('testpickle'):
pywikibot.output('testing existence: [%s:%s]' % (lang,title))
if lang in self.springList.keys():
for a in self.springList[lang]:
if self.getOption('testpickle'):
pywikibot.output('checking existence: [%s:%s]==%s' % (lang,title,a['title']))
if a['title'] == title:
result = True
return(result)
return(result)
def run(self):
header = u'{{TNT|Wikimedia CEE Spring 2018 navbar}}\n\n'
header += u'{{Wikimedia CEE Spring 2018/Statistics/Header}}\n\n'
#header += u"Last update: '''<onlyinclude>{{#time: Y-m-d H:i|{{REVISIONTIMESTAMP}}}} UTC</onlyinclude>'''.\n\n"
header += u"Last update: '''~~~~~'''.\n\n"
footer = u''
#load springList from previous run
self.springList = self.loadArticleList()
#generate dictionary of articles
# article[pl:title] = pageobject
ceeArticles = self.getArticleList()
self.printArtList(ceeArticles)
pywikibot.output(u'ART INFO')
count = 1
for a in ceeArticles:
if self.articleExists(a):
if self.getOption('testpickle'):
pywikibot.output('SKIPPING: [%s:%s]' % (a.site.code,a.title()))
else:
aInfo = self.getArtInfo(a)
if self.getOption('test'):
pywikibot.output(aInfo)
count += 1
if self.getOption('progress') and not count % 10:
pywikibot.output('[%i] Lang:%s Article:%s' % (count,aInfo['lang'],aInfo['title']))
#populate article list per language
if aInfo['lang'] not in self.springList.keys():
self.springList[aInfo['lang']] = []
self.springList[aInfo['lang']].append(aInfo)
#populate authors list
if aInfo['newarticle']:
user = aInfo['creator']
if self.getOption('testnewbie'):
pywikibot.output('NEWBIE CREATOR:%s' % user)
if aInfo['creator'] not in self.authors.keys():
self.authors[aInfo['creator']] = 1
else:
self.authors[aInfo['creator']] += 1
else:
user = aInfo['template']['user']
if self.getOption('testnewbie'):
pywikibot.output('NEWBIE FROM TEMPLATE:%s' % user)
if aInfo['template']['user'] not in self.authors.keys():
self.authors[aInfo['template']['user']] = 1
else:
self.authors[aInfo['template']['user']] += 1
self.newbie(aInfo['lang'],user)
self.printArtInfo(self.springList)
#print self.springList
# save list for the future
self.saveArticleList(self.springList)
self.createCountryTable(self.springList) #generate results for pages about countries
self.createWomenTable(self.springList) #generate results for pages about women
self.createWomenAuthorsTable(self.springList) #generate results for pages about women
self.createLengthTable(self.springList) #generate results for pages length
self.createAuthorsArticles(self.springList) #generate list of articles per author/wiki
self.generateOtherCountriesTable(self.otherCountriesList,self.getOption('outpage')+u'/Other countries',header,footer)
self.generateResultCountryTable(self.countryTable,self.getOption('outpage'),header,footer)
self.generateResultArticleList(self.springList,self.getOption('outpage')+u'/Article list',header,footer)
self.generateResultAuthorsPage(self.authors,self.getOption('outpage')+u'/Authors list',header,footer)
self.generateAuthorsCountryTable(self.authorsArticles,self.getOption('outpage')+u'/Authors list/per wiki',header,footer)
self.generateResultWomenPage(self.women,self.getOption('outpage')+u'/Articles about women',header,footer)
self.generateResultWomenAuthorsTable(self.womenAuthors,self.getOption('outpage')+u'/Articles about women/Authors',header,footer) #generate results for pages about women
#self.generateResultLengthPage(self.lengthTable,self.getOption('outpage')+u'/Article length',header,footer)
return
def newbie(self,lang,user):
#check if user is a newbie
newbieLimit = datetime.strptime("2017-12-20T12:00:00Z", "%Y-%m-%dT%H:%M:%SZ")
if self.getOption('testnewbie'):
pywikibot.output('NEWBIE:%s' % self.authorsData)
if user in self.authorsData.keys():
if lang not in self.authorsData[user]['wikis']:
self.authorsData[user]['wikis'].append(lang)
if self.authorsData[user]['anon']:
return(False)
if not self.authorsData[user]['newbie']:
return(False)
else:
self.authorsData[user] = {'newbie':True, 'wikis':[lang], 'anon':False, 'gender':'unknown'}
userpage = u'user:' + user
site = pywikibot.Site(lang,fam='wikipedia')
#page = pywikibot.Page(site,userpage)
if self.getOption('testnewbie'):
pywikibot.output('GETTING USER DATA:[[:%s:%s]]' % (lang,userpage))
try:
userdata = pywikibot.User(site,userpage)
except:
pywikibot.output('NEWBIE Exception: [[%s:user:%s]]' % (lang,user))
return(False)
self.authorsData[user]['anon'] = userdata.isAnonymous()
if self.authorsData[user]['anon']:
return(False)
usergender = userdata.gender()
if not self.authorsData[user]['gender'] == 'female':
self.authorsData[user]['gender'] = usergender
if self.authorsData[user]['newbie']:
reg = userdata.registration()
if reg:
register = datetime.strptime(str(reg), "%Y-%m-%dT%H:%M:%SZ")
if register < newbieLimit:
self.authorsData[user]['newbie'] = False
else:
self.authorsData[user]['newbie'] = False
if self.getOption('testnewbie'):
pywikibot.output('NEWBIE [%s]:%s' % (user,self.authorsData[user]))
pywikibot.output('registration:%s' % reg)
return(self.authorsData[user]['newbie'])
def createCountryTable(self,aList):
#creat dictionary with la:country article counts
if self.getOption('test2'):
pywikibot.output(u'createCountryTable')
artCount = 0
countryCount = 0
for l in aList.keys():
for a in aList[l]:
#print a
artCount += 1
lang = a['lang'] #source language
tmpl = a['template'] #template data {country:[clist], women:T/F, nocountry:T/F}
if self.getOption('test2'):
pywikibot.output('tmpl:%s' % tmpl)
if u'country' in tmpl.keys():
cList = tmpl['country']
else:
continue
if lang not in self.countryTable.keys():
self.countryTable[lang] = {}
if tmpl['nocountry']:
if 'Empty' in self.countryTable[lang].keys():
self.countryTable[lang]['Empty'] += 1
else:
self.countryTable[lang]['Empty'] = 1
else:
for c in cList:
if c not in self.countryTable[lang].keys():
self.countryTable[lang][c] = 0
self.countryTable[lang][c] += 1
countryCount += 1
if self.getOption('test2'):
pywikibot.output(u'art:%i coutry:%i, [[%s:%s]]' % (artCount, countryCount, lang, a['title']))
return
def createWomenTable(self,aList):
#creat dictionary with la:country article counts
if self.getOption('test') or self.getOption('testwomen'):
pywikibot.output(u'createWomenTable')
pywikibot.output(self.women)
artCount = 0
countryCount = 0
for l in aList.keys():
for a in aList[l]:
#print a
artCount += 1
lang = a['lang'] #source language
tmpl = a['template'] #template data {country:[clist], women:T/F}
if u'woman' in tmpl.keys():
if not tmpl['woman']:
continue
else:
continue
if self.getOption('testwomen'):
pywikibot.output('tmpl:%s' % tmpl)
if lang not in self.women.keys():
self.women[lang] = 1
else:
self.women[lang] += 1
if self.getOption('testwomen'):
pywikibot.output('self.women[%s]:%i' % (lang,self.women[lang]))
countryCount += 1
if self.getOption('test') or self.getOption('testwomen'):
pywikibot.output(u'art:%i Women:True [[%s:%s]]' % (artCount, lang, a['title']))
if self.getOption('testwomen'):
pywikibot.output('**********')
pywikibot.output('self.women')
pywikibot.output('**********')
pywikibot.output(self.women)
return
def createWomenAuthorsTable(self,aList):
#creat dictionary with la:country article counts
if self.getOption('test') or self.getOption('testwomenauthors'):
pywikibot.output(u'createWomenAuthorsTable')
pywikibot.output(self.womenAuthors)
artCount = 0
countryCount = 0
for l in aList.keys():
for a in aList[l]:
#print a
artCount += 1
if self.getOption('testwomenauthors'):
pywikibot.output('article:%s' % a)
lang = a['lang'] #source language
tmpl = a['template'] #template data {country:[clist], women:T/F}
newart = a['newarticle']
womanart = tmpl['woman']
if not newart:
if self.getOption('test') or self.getOption('testwomenauthors'):
pywikibot.output(u'Skipping updated [%i]: [[%s:%s]]' % (artCount,lang,a['title']))
continue
if not womanart:
if self.getOption('test') or self.getOption('testwomenauthors'):
pywikibot.output(u'Skipping NOT WOMAN [%i]: [[%s:%s]]' % (artCount,lang,a['title']))
continue
user = a['creator']
if user in self.womenAuthors.keys():
self.womenAuthors[user]['count'] += 1
self.womenAuthors[user]['list'].append(lang+':'+a['title'])
else:
self.womenAuthors[user] = {'count':1, 'list':[lang+':'+a['title']]}
if self.getOption('testwomenauthors'):
pywikibot.output('**********')
pywikibot.output('self.women.authors')
pywikibot.output('**********')
pywikibot.output(self.womenAuthors)
return
def createLengthTable(self,aList):
#creat dictionary with la:country article counts
if self.getOption('test') or self.getOption('testwomen'):
pywikibot.output(u'createLengthTable')
pywikibot.output(self.lengthTable)
artCount = 0
countryCount = 0
for l in aList.keys():
for a in aList[l]:
if a['newarticle']:
artCount += 1
lang = a['lang'] #source language
title = lang + ':' + a['title'] #art title
if self.getOption('testlength'):
pywikibot.output('Title:%s' % title)
self.lengthTable[title] = (a['charcount'],a['wordcount'])
if self.getOption('testlength'):
pywikibot.output('self.lengthtable[%s]:%s' % (title,self.lengthTable[title]))
if self.getOption('testlength'):
pywikibot.output('**********')
pywikibot.output('self.lengthTable')
pywikibot.output('**********')
pywikibot.output(self.lengthTable)
return
def createAuthorsArticles(self,aList):
#creat dictionary with author:wiki:{count,[artlist]} in self.authorsArticles
if self.getOption('test') or self.getOption('testauthorwiki'):
pywikibot.output(u'createAuthorsArticles')
wikilist = list(aList.keys())
artCount = 0
countryCount = 0
for l in aList.keys():
for a in aList[l]:
author = a['creator']
if author not in self.authorsArticles.keys():
self.authorsArticles[author] = {}
for lang in wikilist:
self.authorsArticles[author][lang] = {'count':0, 'list':[]}
self.authorsArticles[author][l]['count'] += 1
self.authorsArticles[author][l]['list'].append(a['title'])
if self.getOption('testauthorwiki'):
pywikibot.output('**********')
pywikibot.output('createAuthorsArticles')
pywikibot.output('**********')
pywikibot.output(self.authorsArticles)
return
def loadArticleList(self):
#load article list form pickled dictionary
result = {}
if self.getOption('reset'):
if self.getOption('testpickle'):
pywikibot.output('PICKLING SKIPPED at %s' % datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
else:
if self.getOption('testpickle'):
pywikibot.output('PICKLING LOAD at %s' % datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
try:
with open('masti/CEESpring2018.dat', 'rb') as datfile:
result = pickle.load(datfile)
except (IOError, EOFError):
# no saved history exists yet, or history dump broken
if self.getOption('testpickle'):
pywikibot.output('PICKLING FILE NOT FOUND')
result = {}
if self.getOption('testpickle'):
pywikibot.output('PICKLING RESULT:%s' % result)
return(result)
def saveArticleList(self,artList):
#save list as pickle file
if self.getOption('testpickle'):
pywikibot.output('PICKLING SAVE at %s' % datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
with open('masti/CEESpring2018.dat', 'wb') as f:
pickle.dump(artList, f, protocol=config.pickle_protocol)
def getArticleList(self):
#generate article list
artList = []
#use pagegenerator to get articles linking to CEE templates
for p in self.generator:
#p = t.toggleTalkPage()
pywikibot.output(u'Treating: %s' % p.title())
d = p.data_item()
pywikibot.output(u'WD: %s' % d.title() )
dataItem = d.get()
count = 0
for i in self.genInterwiki(p):
lang = self.lang(i.title(asLink=True,forceInterwiki=True))
#test switch
if self.getOption('short'):
if lang not in ('hu','et'):
continue
self.templatesList[lang] = i.title()
pywikibot.output(u'Getting references to %s Lang:%s' % (i.title(asLink=True,forceInterwiki=True), lang) )
countlang = 0
for p in i.getReferences(namespaces=1):
artParams = {}
art = p.toggleTalkPage()
if art.exists():
countlang += 1
artList.append(art)
if self.getOption('test'):
pywikibot.output(u'#%i/%i:%s:%s' % (count,countlang,lang,art.title()))
count += 1
'''
#get et.wiki article list
if self.getOption('test'):
pywikibot.output(u'GET ET WIKI')
etwiki = pywikibot.Site('et',fam='wikipedia')
lang = u'et'
for etart in etArticles.keys():
etpage = pywikibot.Page( etwiki, etart )
if etpage.exists():
artList.append(etpage)
if self.getOption('test'):
pywikibot.output(u'#%i:%s:%s' % (count,lang,etpage.title()))
count += 1
#get hr.wiki article list
if self.getOption('test'):
pywikibot.output(u'GET HR WIKI')
hrwiki = pywikibot.Site('hr',fam='wikipedia')
lang = u'hr'
for hrart in hrArticles.keys():
hrpage = pywikibot.Page( hrwiki, hrart )
if hrpage.exists():
artList.append(hrpage)
if self.getOption('test'):
pywikibot.output(u'#%i:%s:%s' % (count,lang,hrpage.title()))
count += 1
'''
return(artList)
def printArtList(self,artList):
for p in artList:
s = p.site
l = s.code
if self.getOption('test'):
pywikibot.output(u'Page lang:%s : %s' % (l, p.title(asLink=True,forceInterwiki=True)))
return
def printArtInfo(self,artInfo):
#test print of article list result
if self.getOption('testartinfo'):
pywikibot.output(u'***************************************')
pywikibot.output(u'** artInfo **')
pywikibot.output(u'***************************************')
for l in artInfo.keys():
for a in artInfo[l]:
if self.getOption('testartinfo'):
pywikibot.output(a)
return
def getWordCount(self,text):
# get a word count for text
return(len(text.split()))
def getArtLength(self,text):
# get article length
return(len(text))
def cleanUsername(self,user):
# remove lang> from username
if '>' in user:
user = re.sub(r'.*\>','',user)
return(user)
def getArtInfo(self,art):
#get article language, creator, creation date
artParams = {}
talk = art.toggleTalkPage()
if art.exists():
creator, creationDate = self.getUpdater(art)
creator = self.cleanUsername(creator)
lang = art.site.code
woman = self.checkWomen(art)
artParams['title'] = art.title()
artParams['lang'] = lang
artParams['creator'] = creator
artParams['creationDate'] = creationDate
artParams['newarticle'] = self.newArticle(art)
cleantext = textlib.removeDisabledParts(art.text)
artParams['charcount'] = self.getArtLength(cleantext)
artParams['wordcount'] = self.getWordCount(cleantext)
artParams['template'] = {u'country':[], 'user':creator, 'woman':woman, 'nocountry':False}
if lang in CEEtemplates.keys() and talk.exists():
TmplInfo = self.getTemplateInfo(talk, CEEtemplates[lang], lang)
artParams['template'] = TmplInfo
if not artParams['template']['woman']:
artParams['template']['woman'] = woman
if not len(artParams['template']['country']):
artParams['template']['nocountry'] = True
if u'template' not in artParams.keys():
artParams['template'] = {u'country':[], 'user':creator, 'woman':woman, 'nocountry':True}
#if not artParams['newarticle'] :
#if artParams['newarticle'] :
# artParams['template']['user'] = creator
if not artParams['template']['user'] == 'dummy' :
artParams['creator'] = artParams['template']['user']
#print artParams
if self.getOption('test2'):
pywikibot.output('artParams:%s' % artParams)
return(artParams)
def checkWomen(self,art):
#check if the article is about woman
#using WikiData
try:
d = art.data_item()
if self.getOption('test4'):
pywikibot.output(u'WD: %s' % d.title() )
dataItem = d.get()
#pywikibot.output(u'DataItem:%s' % dataItem.keys() )
claims = dataItem['claims']
except:
return(False)
try:
gender = claims["P21"]
except:
return(False)
for c in gender:
cjson = c.toJSON()
genderclaim = cjson[u'mainsnak'][u'datavalue'][u'value'][u'numeric-id']
if u'6581072' == str(genderclaim):
if self.getOption('test4'):
pywikibot.output(u'%s:Woman' % art.title())
return(True)
else:
if self.getOption('test4'):
pywikibot.output(u'%s:Man' % art.title())
return(False)
return(False)
def getUpdater(self, art):
#find author and update datetime of the biggest update within CEESpring
creator, creationDate = art.getCreator()
SpringStart = datetime.strptime("2018-03-20T12:00:00Z", "%Y-%m-%dT%H:%M:%SZ")
if self.newArticle(art):
if self.getOption('test3'):
pywikibot.output(u'New art creator %s:%s (T:%s)' % (art.title(asLink=True,forceInterwiki=True),creator,creationDate))
return(creator, creationDate)
else:
#for rv in art.revisions(reverse=True,starttime="2017-03-20T12:00:00Z",endtime="2017-06-01T00:00:00Z"):
for rv in art.revisions(reverse=True, starttime=SpringStart):
if self.getOption('test3'):
pywikibot.output(u'updated art editor %s:%s (T:%s)' % (art.title(asLink=True,forceInterwiki=True),rv.user,rv.timestamp))
if datetime.strptime(str(rv.timestamp), "%Y-%m-%dT%H:%M:%SZ") > SpringStart:
if self.getOption('test3'):
pywikibot.output(u'returning art editor %s:%s (T:%s)' % (art.title(asLink=True,forceInterwiki=True),rv.user,rv.timestamp))
return(rv.user,rv.timestamp)
else:
if self.getOption('test3'):
pywikibot.output(u'Skipped returning art editor %s:%s (T:%s)' % (art.title(asLink=True,forceInterwiki=True),rv.user,rv.timestamp))
#if self.getOption('test3'):
# pywikibot.output(u'updated art editor %s:%s (T:%s)' % (art.title(asLink=True,forceInterwiki=True),rv['user'],rv['timestamp']))
# return(rv['user'],rv['timestamp'])
return("'''UNKNOWN USER'''", creationDate)
def newArticle(self,art):
#check if the article was created within CEE Spring
creator, creationDate = art.getCreator()
SpringStart = datetime.strptime("2018-03-20T12:00:00Z", "%Y-%m-%dT%H:%M:%SZ")
SpringEnd = datetime.strptime("2018-06-01T00:00:00Z", "%Y-%m-%dT%H:%M:%SZ")
return ( datetime.strptime(creationDate, "%Y-%m-%dT%H:%M:%SZ") > SpringStart )
def getTemplateInfo(self,page,template,lang):
param = {}
#author, creationDate = self.getUpdater(page)
parlist = {'country':[],'user':'dummy','woman':False, 'nocountry':False}
#return dictionary with template params
for t in page.templatesWithParams():
title, params = t
#print(title)
#print(params)
tt = re.sub(ur'\[\[.*?:(.*?)\]\]', r'\1', title.title())
if self.getOption('test2'):
pywikibot.output(u'tml:%s * %s * %s' % (title,tt,template) )
if tt == template:
paramcount = 1
countryDef = False # check if country defintion exists
parlist['woman'] = False
parlist['country'] = []
parlist['user'] = 'dummy'
for p in params:
named, name, value = self.templateArg(p)
# strip square brackets from value
value = re.sub(ur"\'*\[*([^\]\|\']*).*", r'\1', value)
if not named:
name = str(paramcount)
param[name] = value
paramcount += 1
if self.getOption('test2'):
pywikibot.output(u'p:%s' % p )
#check username in template
if lang in self.userp.keys() and name.lower().startswith(self.userp[lang].lower()):
if self.getOption('test'):
pywikibot.output(u'user:%s:%s' % (name,value))
#if lang in self.userp.keys() and value.lower().startswith(self.userp[lang].lower()):
# parlist['user'] = value
parlist['user'] = value
#check article about women
if lang in self.topicp.keys() and name.lower().startswith(self.topicp[lang].lower()):
if self.getOption('test2'):
pywikibot.output(u'topic:%s:%s' % (name,value))
if lang in self.womenp.keys() and value.lower().startswith(self.womenp[lang].lower()):
#self.women[lang] += 1
parlist['woman'] = True
#check article about country
if lang in self.countryp.keys() and name.lower().startswith(self.countryp[lang].lower()):
if self.getOption('test2'):
pywikibot.output(u'country:%s:%s' % (name,value))
if len(value)>0:
countryDef = True
if lang in countryNames.keys() and value in (countryNames[lang].keys()):
countryEN = countryNames[lang][value]
parlist['country'].append(countryEN)
if lang not in self.pagesCount.keys():
self.pagesCount[lang] = {}
if countryEN in self.pagesCount[lang].keys():
self.pagesCount[lang][countryEN] += 1
else:
self.pagesCount[lang][countryEN] = 1
else:
parlist['country'].append(value)
self.otherCountriesList[lang].append(value)
if self.getOption('test'):
pywikibot.output(self.pagesCount)
if self.getOption('test3'):
#pywikibot.output(u'PARAM:%s' % param)
pywikibot.output(u'PARLIST:%s' % parlist)
return parlist
return parlist
def lang(self,template):
return(re.sub(ur'\[\[(.*?):.*?\]\]',ur'\1',template))
def genInterwiki(self,page):
# yield interwiki sites generator
iw = []
try:
d = page.data_item()
pywikibot.output(u'WD: %s' % d.title() )
dataItem = d.get()
#pywikibot.output(u'DataItem:%s' % dataItem.keys() )
sitelinks = dataItem['sitelinks']
for s in sitelinks:
#if self.getOption('test'):
# pywikibot.output(u'SL iw: %s' % d)
site = re.sub(ur'(.*)wiki$', ur'\1',s)
if site == u'be_x_old':
site = u'be-tarask'
ssite = pywikibot.Site(site,fam='wikipedia')
spage = pywikibot.Page( ssite, title=sitelinks[s] )
#pywikibot.output(u'gI Page: %s' % spage.title(asLink=True,forceInterwiki=True) )
iw.append( spage )
#print( iw)
except:
pass
#print(iw)
return(iw)
def generateOtherCountriesTable(self, res, pagename, header, footer):
"""
Generates results page from res
Starting with header, ending with footer
Output page is pagename
"""
locpagename = re.sub(ur'.*:','',pagename)
finalpage = header
if self.getOption('test'):
pywikibot.output(u'**************************')
pywikibot.output(u'generateOtherCountriesTable')
pywikibot.output(u'**************************')
pywikibot.output(u'OtherCountries:%s' % self.otherCountriesList)
for c in self.otherCountriesList.keys():
finalpage += u'\n== ' + c + u' =='
pywikibot.output('== ' + c + u' ==')
for i in self.otherCountriesList[c]:
pywikibot.output('c:%s, i:%s' % (c,i))
finalpage += u'\n# <nowiki>' + i + u'</nowiki>'
finalpage += footer
outpage = pywikibot.Page(pywikibot.Site(), pagename)
if self.getOption('test') or self.getOption('progress'):
pywikibot.output(u'OtherCountries:%s' % outpage.title())
outpage.text = finalpage
outpage.save(summary=self.getOption('summary'))
if self.getOption('test') or self.getOption('progress'):
pywikibot.output(u'OtherCountries SAVED')
return
def generateResultCountryTable(self, res, pagename, header, footer):
"""
Generates results page from res
Starting with header, ending with footer
Output page is pagename
"""
locpagename = re.sub(ur'.*:','',pagename)
finalpage = header
if self.getOption('test'):
pywikibot.output(u'**************************')
pywikibot.output(u'generateResultCountryTable')
pywikibot.output(u'**************************')
#total counters
countryTotals = {}
for c in countryList:
countryTotals[c] = 0
# generate table header
finalpage += u'\n{| class="wikitable sortable" style="text-align: center;"'
finalpage += u'\n|-'
finalpage += u'\n! wiki/country'
finalpage += u' !! Total'
for c in countryList:
finalpage += u' !! ' + c
finalpage += u' !! Total'
# generate table rows
for wiki in res.keys():
finalpage += u'\n|-'
finalpage += u'\n| [[' + locpagename + u'/Article list#'+ wiki + u'.wikipedia|' + wiki + u']]'
wikiTotal = 0 # get the row total
newline = '' # keep info for the table row
for c in countryList:
newline += u' || '
if u'Other' in c:
if self.getOption('test3'):
pywikibot.output(u'other:%s' % c)
pywikibot.output(u'res[wiki]:%s' % res[wiki])
otherCountry = 0 # count other countries
for country in res[wiki]:
if country not in countryList and not country==u'':
if self.getOption('test3'):
pywikibot.output(u'country:%s ** otherCountry=%i+%i=%i' % (country,otherCountry,res[wiki][country],otherCountry+res[wiki][country]))
otherCountry += res[wiki][country]
newline += str(otherCountry)
wikiTotal += otherCountry # add to wiki total
countryTotals[c] += otherCountry
else:
if c in res[wiki].keys():
if res[wiki][c]:
newline += str(res[wiki][c])
wikiTotal += res[wiki][c] # add to wiki total
countryTotals[c] += res[wiki][c]
# add row (wiki) total to table
finalpage += u" || '''" + str(wikiTotal) + "'''" + newline + u" || '''" + str(wikiTotal) + "'''"
finalpage += u'\n|-'
# generate totals
totalTotal = 0
finalpage += u"\n! Total: !! '''" + str(totalTotal) + "'''"
for c in countryList:
finalpage += u' !! ' + str(countryTotals[c])
totalTotal += countryTotals[c]
finalpage += u" || '''" + str(totalTotal) + "'''"
# generate table footer
finalpage += u'\n|}'
finalpage += u"\n\n'''NOTE:''' the table counts references to respective countries. Article can reference more than 1 country"
finalpage += footer
if self.getOption('test2'):
pywikibot.output(finalpage)
outpage = pywikibot.Page(pywikibot.Site(), pagename)
if self.getOption('test'):
pywikibot.output(u'WomenPage:%s' % outpage.title())
outpage.text = finalpage
outpage.save(summary=self.getOption('summary'))
return
def generateAuthorsCountryTable(self, res, pagename, header, footer):
"""
Generates results page from res
Starting with header, ending with footer
Output page is pagename
"""
locpagename = re.sub(ur'.*:','',pagename)
finalpage = header
pywikibot.output(u'***************************')
pywikibot.output(u'generateAuthorsCountryTable')
pywikibot.output(u'***************************')
#total counters
wikiTotals = {}
wikiList = list(self.otherCountriesList.keys())
for a in wikiList:
wikiTotals[a] = 0
# generate table header
finalpage += u'\n{| class="wikitable sortable" style="text-align: center;"'
finalpage += u'\n|-'
finalpage += u'\n! author/wiki'
finalpage += u' !! Total'
for w in wikiList:
finalpage += u' !! ' + w
finalpage += u' !! Total'
# generate table rows
for author in res.keys():
finalpage += u'\n|-'
finalpage += u'\n| [[user:%s|%s]]' % (author,author)
authorTotal = 0 # get the row total
newline = '' # keep info for the table row
for w in wikiList:
newline += u' || '
if w in res[author].keys():
if res[author][w]:
newline += str(res[author][w]['count'])
authorTotal += res[author][w]['count'] # add to author total (horizontal)
wikiTotals[w] += res[author][w]['count'] # add to wiki total {verical)
# add row (wiki) total to table
finalpage += u" || '''" + str(authorTotal) + "'''" + newline + u" || '''" + str(authorTotal) + "'''"
finalpage += u'\n|-'
# generate totals
totalTotal = 0
finalpage += u"\n! Total: !! '''" + str(totalTotal) + "'''"
for w in wikiList:
finalpage += u' !! ' + str(wikiTotals[w])
totalTotal += wikiTotals[w]
finalpage += u" || '''" + str(totalTotal) + "'''"
# generate table footer
finalpage += u'\n|}'