-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcovid.tcl
976 lines (917 loc) · 39 KB
/
covid.tcl
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
#######################################################################################################
## Covid19.tcl 1.3.4 (15/05/2020) Copyright 2008 - 2020 @ WwW.TCLScripts.NET ##
## _ _ _ _ _ _ _ _ _ _ _ _ _ _ ##
## / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ ##
## ( T | C | L | S | C | R | I | P | T | S | . | N | E | T ) ##
## \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ ##
## ##
## ® BLaCkShaDoW Production ® ##
## ##
## PRESENTS ##
## ®##
############################################ Covid-19 TCL ##########################################
## ##
## DESCRIPTION: ##
## Shows realtime stats about the COVID-19 CORONAVIRUS OUTBREAK. These are taken from the site ##
## ##
## https://www.worldometers.info/coronavirus/ by command and also auto if something changes from ##
## ##
## the last information given. (RSS type) ##
## ##
## Tested on Eggdrop v1.8.3 (Debian Linux 3.16.0-4-amd64) Tcl version: 8.6.10 ##
## ##
#######################################################################################################
## ##
## /===============================\ ##
## | This Space For Rent | ##
## \===============================/ ##
## ##
#######################################################################################################
## ##
## INSTALLATION: ##
## ++ http package is REQUIRED for this script to work. ##
## ++ tls package is REQUIRED for this script to work. (1.7.18-2 or later) ##
## latest tls https://ubuntu.pkgs.org/19.10/ubuntu-universe-amd64/tcl-tls_1.7.18-2_amd64.deb.html ##
## ++ Edit the Covid19.tcl script and place it into your /scripts directory, ##
## ++ add "source scripts/Covid19.tcl" to your eggdrop config and rehash the bot. ##
## ##
#######################################################################################################
#######################################################################################################
## ##
## OFFICIAL LINKS: ##
## E-mail : BLaCkShaDoW[at]tclscripts.net ##
## Bugs report : http://www.tclscripts.net ##
## GitHub page : https://github.com/tclscripts/ ##
## Online help : irc://irc.undernet.org/tcl-help ##
## #TCL-HELP / UnderNet ##
## You can ask in english or romanian ##
## ##
## paypal.me/DanielVoipan = Please consider a donation. Thanks! ##
## ##
#######################################################################################################
## ##
## You want a customised TCL Script for your eggdrop? ##
## Easy-peasy, just tell me what you need! ##
## I can create almost anything in TCL based on your ideas and donations. ##
## Email blackshadow@tclscripts.net or info@tclscripts.net with your ##
## request informations and I'll contact you as soon as possible. ##
## ##
#######################################################################################################
## ##
## Version 1.1 -- If country isnt specificed it will show the total statistics ##
## ##
## Commmands: !Covid [country] - if not specified it will show the total statistics ##
## ##
## ##
## Settings: .chanset/.set #chan +covid - enable the !covid <city> command ##
## ##
## ##
## .chanset/.set #chan +autocovid - enable the auto message on timer if the ##
## information changes (like RSS feed) ##
## ##
## .chanset/.set #chan covid-country [your country] - setup the default country ##
## for the Covid19 RSS (auto show information) ##
## ##
## .chanset/.set #chan covid-lang Ro/En/Es - setup the default language for the scrip ##
## ##
## Version 1.2.1 -- Added some new countries and places ##
## Version 1.2.2 -- Solved an issue related to https connection ##
## ##
## Version 1.3 -- Solved some issues related to page layout ##
## -- Added some more details from the page ##
## ##
## Version 1.3.1 -- added difference between today and yesterday for active cases, recovered, ##
## serious cases, tests for countries ##
## -- solved some bugs related to settng your default country ##
## -- added spanish language support ##
## ##
## Version 1.3.2 -- added last updated entry to channel output ##
## ##
## Version 1.3.3 -- added total stats for continents Europe, North America, Asia, South America, ##
## Africa, Oceania ##
## -- soved issue with GLOBAL stats output ##
## ##
## Version 1.3.4 -- solved some issues due to page info modification ##
## -- solved some little bugs ##
## ##
#######################################################################################################
#######################################################################################################
## ##
## LICENSE: ##
## This code comes with ABSOLUTELY NO WARRANTY. ##
## ##
## This program is free software; you can redistribute it and/or modify it under the terms of ##
## the GNU General Public License version 3 as published by the Free Software Foundation. ##
## ##
## This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ##
## USE AT YOUR OWN RISK. ##
## ##
## See the GNU General Public License for more details. ##
## (http://www.gnu.org/copyleft/library.txt) ##
## ##
## Copyright 2008 - 2018 @ WwW.TCLScripts.NET ##
## ##
#######################################################################################################
#######################################################################################################
## CONFIGURATION FOR Covid19.TCL ##
#######################################################################################################
###
#Default country for corona virus checking uppon command or timer
#put "GLOBAL" for total stats
#
set corona(country) "GLOBAL"
###
#Set script language (Ro/En/Es)
#
set corona(language) "en"
###
#Flags required to use !covid [country] command
#
set corona(flags) "-|-"
###
# FLOOD PROTECTION
#Set the number of minute(s) to ignore flooders
###
set corona(ignore_prot) "1"
###
# FLOOD PROTECTION
#Set the number of requests within specifide number of seconds to trigger flood protection.
# By default, 4:10, which allows for upto 3 queries in 10 seconds. 4 or more quries in 10 seconds would cuase
# the forth and later queries to be ignored for the amount of time specifide above.
###
set corona(flood_prot) "3:10"
###
#COVID RSS (minutes)
#Set here the time for the script to check if the info changed
#If the info changed it will be shown on chan
#only when the option is enabled with +autocovid
###
set corona(time_check) "15"
########################################################################################################
#Continents list
set corona(continent_list) {
"Europe"
"North America"
"Asia"
"South America"
"Africa"
"Oceania"
}
#Country list
set corona(country_list) {
"USA"
"Spain"
"Italy"
"France"
"Germany"
"UK"
"Turkey"
"China"
"Iran"
"Russia"
"Brazil"
"Belgium"
"Canada"
"Netherlands"
"Switzerland"
"Portugal"
"India"
"Peru"
"Ireland"
"Austria"
"Sweden"
"Israel"
"Japan"
"S. Korea"
"Chile"
"Ecuador"
"Saudi Arabia"
"Poland"
"Romania"
"Pakistan"
"Mexico"
"Denmark"
"Norway"
"UAE"
"Czechia"
"Australia"
"Singapore"
"Indonesia"
"Serbia"
"Philippines"
"Ukraine"
"Qatar"
"Malaysia"
"Belarus"
"Dominican Republic"
"Panama"
"Finland"
"Colombia"
"Luxembourg"
"South Africa"
"Egypt"
"Morocco"
"Argentina"
"Thailand"
"Algeria"
"Moldova"
"Bangladesh"
"Greece"
"Hungary"
"Kuwait"
"Bahrain"
"Croatia"
"Iceland"
"Kazakhstan"
"Uzbekistan"
"Iraq"
"Estonia"
"New Zealand"
"Azerbaijan"
"Slovenia"
"Lithuania"
"Armenia"
"Bosnia and Herzegovina"
"Oman"
"North Macedonia"
"Slovakia"
"Cuba"
"Hong Kong"
"Cameroon"
"Afghanistan"
"Bulgaria"
"Tunisia"
"Ivory Coast"
"Djibouti"
"Ghana"
"Cyprus"
"Latvia"
"Andorra"
"Diamond Princess"
"Lebanon"
"Costa Rica"
"Niger"
"Guinea"
"Burkina Faso"
"Albania"
"Kyrgyzstan"
"Nigeria"
"Bolivia"
"Uruguay"
"Channel Islands"
"Honduras"
"San Marino"
"Palestine"
"Malta"
"Taiwan"
"Jordan"
"Réunion"
"Georgia"
"Senegal"
"Mauritius"
"DRC"
"Montenegro"
"Isle of Man"
"Sri Lanka"
"Mayotte"
"Kenya"
"Vietnam"
"Guatemala"
"Venezuela"
"Mali"
"Paraguay"
"El Salvador"
"Faeroe Islands"
"Jamaica"
"Tanzania"
"Somalia"
"Martinique"
"Guadeloupe"
"Rwanda"
"Congo"
"Brunei"
"Gibraltar"
"Cambodia"
"Madagascar"
"Trinidad and Tobago"
"Myanmar"
"Gabon"
"Ethiopia"
"Aruba"
"French Guiana"
"Monaco"
"Liberia"
"Bermuda"
"Togo"
"Liechtenstein"
"Equatorial Guinea"
"Barbados"
"Sint Maarten"
"Sudan"
"Guyana"
"Zambia"
"Cabo Verde"
"Cayman Islands"
"Bahamas"
"French Polynesia"
"Uganda"
"Maldives"
"Guinea-Bissau"
"Libya"
"Haiti"
"Macao"
"Syria"
"Eritrea"
"Mozambique"
"Saint Martin"
"Benin"
"Sierra Leone"
"Chad"
"Mongolia"
"Nepal"
"Zimbabwe"
"Angola"
"Antigua and Barbuda"
"Eswatini"
"Botswana"
"Laos"
"Timor-Leste"
"Belize"
"New Caledonia"
"Malawi"
"Fiji"
"Dominica"
"Namibia"
"Saint Lucia"
"Curaçao"
"Grenada"
"Saint Kitts and Nevis"
"CAR"
"St. Vincent Grenadines"
"Turks and Caicos"
"Falkland Islands"
"Greenland"
"Montserrat"
"Seychelles"
"Nicaragua"
"Gambia"
"Suriname"
"MS Zaandam"
"Vatican City"
"Mauritania"
"Papua New Guinea"
"St. Barth"
"Western Sahara"
"Burundi"
"Bhutan"
"Caribbean Netherlands"
"British Virgin Islands"
"Sao Tome and Principe"
"South Sudan"
"Anguilla"
"Saint Pierre Miquelon"
"Yemen"
"Lesotho"
"Comoros"
"Europe"
"North America"
"Asia"
"South America"
"Africa"
"Oceania"
}
###############################################################################################################
#
# Try to edit only the language :-)
#
###############################################################################################################
package require tls
package require http
bind pub $corona(flags) !covid corona:pub
setudef flag covid
setudef flag autocovid
setudef str covid-country
setudef str covid-lang
###
if {![info exists corona(timer_start)]} {
timer $corona(time_check) corona:auto_timer
set corona(timer_start) 1
}
###
proc corona:auto_timer {} {
global corona
set channels ""
foreach chan [channels] {
if {[channel get $chan autocovid] && [validchan $chan]} {
lappend channels $chan
}
}
if {$channels != ""} {
set data [corona:getdata]
corona:auto_check $data $channels 0
} else {
timer $corona(time_check) corona:auto_timer
}
}
###
proc corona:auto_check {data channels num} {
global corona
set total 0
set chan [lindex $channels $num]
set country [string toupper [channel get $chan covid-country]]
#if {$country == ""} { set country $corona(country) }
if {$country == ""} { set country [lindex $corona(country_list) [rand [llength $corona(country_list)]]] }
if {[string tolower $country] != "global"} {
set find_continent [lsearch -nocase $corona(continent_list) $country]
set find_country [lsearch -nocase $corona(country_list) $country]
if {$find_country < 0 && $find_continent < 0} {
set country "GLOBAL"
} elseif {$find_continent > -1} {
set country [lindex $corona(continent_list) $find_continent]
set total 2
} else {
set country [lindex $corona(country_list) $find_country]
}
}
if {[string tolower $country] == "global"} {
set total 1
}
set extract [corona:extract $data $country $total]
set total_cases [lindex $extract 0]
set new_cases [lindex $extract 1]
set total_deaths [lindex $extract 2]
set new_deaths [lindex $extract 3]
set total_recovered [lindex $extract 4]
set active_cases [lindex $extract 5]
set serious_critical [lindex $extract 6]
set totalcases_per_milion [lindex $extract 7]
set deaths_per_milion [lindex $extract 8]
set total_tests [lindex $extract 9]
set totaltests_per_milion [lindex $extract 10]
set type [lindex $extract 11]
set last_updated [lindex $extract 12]
set extract [string map [list $last_updated ""] $extract]
if {$new_cases == ""} { set new_cases - }
if {$total_deaths == ""} { set total_deaths - }
if {$new_deaths == ""} { set new_deaths - }
if {$total_recovered == ""} { set total_recovered - }
if {$active_cases == ""} { set active_cases - }
if {$totalcases_per_milion == ""} { set totalcases_per_milion - }
if {$deaths_per_milion == ""} { set deaths_per_milion - }
if {$total_tests == ""} { set total_tests - }
if {$totaltests_per_milion == ""} { set totaltests_per_milion - }
if {[info exists corona($chan:autocovid:entry)]} {
if {$corona($chan:autocovid:entry) != $extract} {
set corona($chan:autocovid:entry) $extract
if {$type == "1"} {
corona:say "" $chan [list $country $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_critical $totalcases_per_milion $deaths_per_milion $total_tests $totaltests_per_milion $last_updated] 4
} else {
corona:say "" $chan [list $country $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_critical $totalcases_per_milion $deaths_per_milion $last_updated] 6
}
}
} else {
set corona($chan:autocovid:entry) $extract
if {$type == "1"} {
corona:say "" $chan [list $country $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_critical $totalcases_per_milion $deaths_per_milion $total_tests $totaltests_per_milion $last_updated] 4
} else {
corona:say "" $chan [list $country $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_critical $totalcases_per_milion $deaths_per_milion $last_updated] 6
}
}
set next_num [expr $num + 1]
if {[lindex $channels $next_num] != ""} {
utimer 5 [list corona:auto_check $data $channels $next_num]
} else {
timer $corona(time_check) corona:auto_timer
}
}
###
proc corona:getdata {} {
set link "https://www.worldometers.info/coronavirus/"
# http::register https 443 [list ::tls::socket -autoservername true]
::http::register https 443 tls:socket
set ipq [http::config -useragent "lynx"]
set ipq [::http::geturl "$link" -timeout 5000]
set status [::http::status $ipq]
if {$status != "ok"} {
::http::cleanup $ipq
return
}
set data [http::data $ipq]
::http::cleanup $ipq
return $data
}
proc tls:socket args {
set opts [lrange $args 0 end-2]
set host [lindex $args end-1]
set port [lindex $args end]
::tls::socket -servername $host {*}$opts $host $port
}
###
proc corona:pub {nick host hand chan arg} {
global corona
if {![channel get $chan covid]} {
return
}
set total 0
set flood_protect [corona:flood:prot $chan $host]
if {$flood_protect == "1"} {
set get_seconds [corona:get:flood_time $host $chan]
corona:say $nick "NOTC" [list $get_seconds] 2
return
}
set country [join [lrange [split $arg] 0 end]]
if {$country == ""} {
set total 1
set country "GLOBAL"
} else {
set find_continent [lsearch -nocase $corona(continent_list) $country]
set find_country [lsearch -nocase $corona(country_list) $country]
if {$find_country < 0 && $find_continent < 0} {
corona:say $nick $chan "" 1
return
} elseif {$find_continent > -1} {
set country [lindex $corona(continent_list) $find_continent]
set total 2
} else {
set country [lindex $corona(country_list) $find_country]
}
}
set data [corona:getdata]
set extract [corona:extract $data $country $total]
set total_cases [lindex $extract 0]
set new_cases [lindex $extract 1]
set total_deaths [lindex $extract 2]
set new_deaths [lindex $extract 3]
set total_recovered [lindex $extract 4]
set active_cases [lindex $extract 5]
set serious_critical [lindex $extract 6]
set totalcases_per_milion [lindex $extract 7]
set deaths_per_milion [lindex $extract 8]
set total_tests [lindex $extract 9]
set totaltests_per_milion [lindex $extract 10]
set type [lindex $extract 11]
set last_updated [lindex $extract 12]
if {$new_cases == ""} { set new_cases - }
if {$total_deaths == ""} { set total_deaths - }
if {$new_deaths == ""} { set new_deaths - }
if {$total_recovered == ""} { set total_recovered - }
if {$active_cases == ""} { set active_cases - }
if {$totalcases_per_milion == ""} { set totalcases_per_milion - }
if {$serious_critical == ""} { set serious_critical - }
if {$deaths_per_milion == ""} { set deaths_per_milion - }
if {$total_tests == ""} { set total_tests - }
if {$totaltests_per_milion == ""} { set totaltests_per_milion - }
if {$type > "0"} {
corona:say $nick $chan [list $country $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_critical $totalcases_per_milion $deaths_per_milion $total_tests $totaltests_per_milion $last_updated] 3
} else {
corona:say $nick $chan [list $country $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_critical $totalcases_per_milion $deaths_per_milion $last_updated] 5
}
}
###
proc corona:extract {data country total} {
global corona
set last_updated "N/A"
set var_lastupdated "<div style=\"font-size:13px; color:#999; margin-top:5px; text-align:center\">Last updated:(.*)</div>(.*)"
regexp {<div style=\"font-size:13px; color:#999; margin-top:5px; text-align:center\">(.*)</div>(.*)} $data -> last_updated
regsub {</div>(.*)} $last_updated "" last_updated
set last_updated [concat [string map {"Last updated:" ""} $last_updated]]
if {$total > "0"} {
set split_data [split $data "\n"]
set information ""
set c 0
set first_line 0
set last_line 0
switch $total {
1 {
set var "<td style=\"text-align:left;\">World</td>"
}
2 {
set var "<nobr>$country</nobr>"
}
}
foreach line $split_data {
set line [concat $line]
if {[regexp -nocase $var $line]} {
set first_line $c
continue
}
if {[string match -nocase "*</tr>" $line] && $first_line > 0} {
set last_line $c
break
}
set c [expr $c + 1]
}
set new_data [lrange $split_data $first_line $last_line]
foreach line $new_data {
set test [regexp {<td style="(.*)">\d*(.*)\d*</td>|<td>(.*)</td>|text-align:right;(.*)\">\d*(.*)\d*</td>|<td>\d*(.*)\d*</td>} $line match]
if {$test > 0} {
regsub {</td>(.*)} $match "" m
lappend information $m
}
}
if {$total == "2"} {
set total_cases [corona:filter [lindex $information 0] 0]
set new_cases [corona:filter [lindex $information 1] 0]
set total_deaths [corona:filter [lindex $information 2] 0]
set new_deaths [corona:filter [lindex $information 3] 0]
set total_recovered [corona:filter [lindex $information 4] 0]
set active_cases [corona:filter [lindex $information 5] 0]
set serious_cases [corona:filter [lindex $information 6] 0]
set totalcases_per_milion [corona:filter [lindex $information 7] 0]
set deaths_per_milion [corona:filter [lindex $information 8] 0]
set total_tests [corona:filter [lindex $information 9] 0]
set totaltests_per_milion [corona:filter [lindex $information 10] 0]
} else {
set total_cases [corona:filter [lindex $information 1] 0]
set new_cases [corona:filter [lindex $information 2] 0]
set total_deaths [corona:filter [lindex $information 3] 0]
set new_deaths [corona:filter [lindex $information 4] 0]
set total_recovered [corona:filter [lindex $information 5] 0]
set active_cases [corona:filter [lindex $information 6] 0]
set serious_cases [corona:filter [lindex $information 7] 0]
set totalcases_per_milion [corona:filter [lindex $information 8] 0]
set deaths_per_milion [corona:filter [lindex $information 9] 0]
set total_tests [corona:filter [lindex $information 10] 0]
set totaltests_per_milion [corona:filter [lindex $information 11] 0]
}
return [list $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_cases $totalcases_per_milion $deaths_per_milion $total_tests $totaltests_per_milion 0 $last_updated]
} else {
set split_data [split $data "\n"]
set information ""
set information_yesterday ""
set c 0
set first_line 0
set last_line 0
set found_yesterday 0
set var "(.*)<td style=\"font-weight: bold; font-size:15px; text-align:left;\">$country</td>|<td style=\"font-weight: bold; font-size:15px; text-align:left;\"><a class=\"mt_a\" href=\"(.*)\">$country</a></td>"
foreach line $split_data {
set line [concat $line]
if {[regexp $var $line]} {
incr found_yesterday
set first_line $c
continue
}
if {[string match -nocase "*</tr>" $line] && $first_line > 0 && $found_yesterday == 2} {
set last_line [expr $c + 1]
break
}
set c [expr $c + 1]
}
set new_data [lrange $split_data $first_line $last_line]
foreach line $new_data {
set test [regexp {<td style="(.*)">\d*(.*)\d*</td>|text-align:right;(.*)\">\d*(.*)\d*</td>} $line match]
if {$test > 0} {
regsub {</td>(.*)} $match "" m
lappend information_yesterday $m
}
}
set c 0
set first_line 0
set last_line 0
foreach line $split_data {
set line [concat $line]
if {[regexp $var $line]} {
set first_line $c
continue
}
if {[string match -nocase "*</tr>" $line] && $first_line > 0} {
set last_line $c
break
}
set c [expr $c + 1]
}
set new_data [lrange $split_data $first_line $last_line]
foreach line $new_data {
set test [regexp {<td style="(.*)">\d*(.*)\d*</td>|text-align:right;(.*)\">\d*(.*)\d*</td>} $line match]
if {$test > 0} {
regsub {</td>(.*)} $match "" m
lappend information $m
}
}
set country [corona:filter [lindex $information 0] 0]
set total_cases [corona:filter [lindex $information 1] 0]
set new_cases [corona:filter [lindex $information 2] 0]
set total_deaths [corona:filter [lindex $information 3] 0]
set new_deaths [corona:filter [lindex $information 4] 0]
set total_recovered [corona:filter [lindex $information 5] 0]
set active_cases [corona:filter [lindex $information 6] 0]
set serious_cases [corona:filter [lindex $information 7] 0]
set totalcases_per_milion [corona:filter [lindex $information 8] 0]
set deaths_per_milion [corona:filter [lindex $information 9] 0]
set total_tests [corona:filter [lindex $information 10] 0]
set totaltests_per_milion [corona:filter [lindex $information 11] 0]
set yesterday_total_recovered [corona:comma [corona:filter [lindex $information_yesterday 6] 0]]
set yesterday_active_cases [corona:comma [corona:filter [lindex $information_yesterday 7] 0]]
set yesterday_serious_cases [corona:comma [corona:filter [lindex $information_yesterday 8] 0]]
set yesterday_total_tests [corona:comma [corona:filter [lindex $information_yesterday 11] 0]]
set dif_total_recovered 0
set dif_active_cases 0
set dif_serious_cases 0
set dif_total_tests 0
if {$total_recovered != "" && $yesterday_total_recovered != "" && $total_recovered != $yesterday_total_recovered} {
if {[corona:comma $total_recovered] > $yesterday_total_recovered} {
set dif_total_recovered +[expr [corona:comma $total_recovered] - $yesterday_total_recovered]
} else {
set dif_total_recovered -[expr $yesterday_total_recovered - [corona:comma $total_recovered]]
}
}
if {$active_cases != "" && $yesterday_active_cases != "" && $active_cases != $yesterday_active_cases} {
if {[corona:comma $active_cases] > $yesterday_active_cases} {
set dif_active_cases +[expr [corona:comma $active_cases] - $yesterday_active_cases]
} else {
set dif_active_cases -[expr $yesterday_active_cases - [corona:comma $active_cases]]
}
}
if {$serious_cases != "" && $yesterday_serious_cases != "" && $serious_cases != $yesterday_serious_cases} {
if {[corona:comma $serious_cases] > $yesterday_serious_cases} {
set dif_serious_cases +[expr [corona:comma $serious_cases] - $yesterday_serious_cases]
} else {
set dif_serious_cases -[expr $yesterday_serious_cases - [corona:comma $serious_cases]]
}
}
if {$total_tests != "" && $yesterday_total_tests != "" && $total_tests != $yesterday_total_tests} {
if {[corona:comma $total_tests] > $yesterday_total_tests} {
set dif_total_tests +[expr [corona:comma $total_tests] - $yesterday_total_tests]
} else {
set dif_total_tests -[expr $yesterday_total_tests - [corona:comma $total_tests]]
}
}
if {$dif_total_recovered != "0"} {
set total_recovered $total_recovered\[[corona:commify $dif_total_recovered]\]
}
if {$dif_active_cases != "0"} {
set active_cases $active_cases\[[corona:commify $dif_active_cases]\]
}
if {$dif_serious_cases != "0"} {
set serious_cases $serious_cases\[[corona:commify $dif_serious_cases]\]
}
if {$dif_total_tests != "0"} {
set total_tests $total_tests\[[corona:commify $dif_total_tests]\]
}
return [list $total_cases $new_cases $total_deaths $new_deaths $total_recovered $active_cases $serious_cases $totalcases_per_milion $deaths_per_milion $total_tests $totaltests_per_milion 1 $last_updated]
}
}
###
proc corona:filter {text type} {
if {$type == "0"} {
set split_text [split $text ">"]
return [concat [lindex $split_text 1]]
} else {
set text [string map {"<td>" ""
"<nobr>" ""
"</nobr>" ""
} $text]
return [concat $text]
}
}
proc corona:comma {num} {
global corona
set text [string map {"," ""} $num]
return $text
}
###
proc corona:flood:prot {chan host} {
global corona
set number [scan $corona(flood_prot) %\[^:\]]
set timer [scan $corona(flood_prot) %*\[^:\]:%s]
if {[info exists corona(flood:$host:$chan:act)]} {
return 1
}
foreach tmr [utimers] {
if {[string match "*corona:remove:flood $host $chan*" [join [lindex $tmr 1]]]} {
killutimer [lindex $tmr 2]
}
}
if {![info exists corona(flood:$host:$chan)]} {
set corona(flood:$host:$chan) 0
}
incr corona(flood:$host:$chan)
utimer $timer [list corona:remove:flood $host $chan]
if {$corona(flood:$host:$chan) > $number} {
set corona(flood:$host:$chan:act) 1
utimer 60 [list corona:expire:flood $host $chan]
return 1
} else {
return 0
}
}
###
proc corona:expire:flood {host chan} {
global corona
if {[info exists corona(flood:$host:$chan:act)]} {
unset corona(flood:$host:$chan:act)
}
}
###
proc corona:remove:flood {host chan} {
global corona
if {[info exists corona(flood:$host:$chan)]} {
unset corona(flood:$host:$chan)
}
}
###
proc corona:get:flood_time {host chan} {
global corona
foreach tmr [utimers] {
if {[string match "*corona:expire:flood $host $chan*" [join [lindex $tmr 1]]]} {
return [lindex $tmr 0]
}
}
}
###
proc corona:wrap {str {len 100} {splitChr { }}} {
set out [set cur {}]; set i 0
foreach word [split [set str][unset str] $splitChr] {
if {[incr i [string len $word]]>$len} {
lappend out [join $cur $splitChr]
set cur [list [encoding convertfrom utf-8 $word]]
set i [string len $word]
} {
lappend cur $word
}
incr i
}
lappend out [join $cur $splitChr]
}
###
proc corona:say {nick chan arg num} {
global corona
set inc 0
if {$chan == "NOTC"} {
set lang [string tolower $corona(language)]
} else {
set lang [string tolower [channel get $chan covid-lang]]
if {$lang == ""} {
set lang [string tolower $corona(language)]
} else {
if {[info exists corona($lang.lang.1)]} {
set lang $lang
} else {
set lang [string tolower $corona(language)]
}
}
}
foreach s $arg {
set inc [expr $inc + 1]
set replace(%msg.$inc%) $s
}
set reply [string map [array get replace] $corona($lang.lang.$num)]
if {$chan == "NOTC"} {
foreach w [corona:wrap $reply 450] {
putserv "NOTICE $nick :$w"
}
} else {
foreach w [corona:wrap $reply 450] {
putserv "PRIVMSG $chan :$w"
}
}
}
###
proc corona:commify {num {sep ,}} {
fixpoint num {
regsub {^([-+]?\d+)(\d\d\d)} $num "\\1$sep\\2"
}
}
###
#http://wiki.tcl.tk/5000
proc fixpoint {varName script} {
upvar 1 $varName arg
while {[set res [uplevel 1 $script]] ne $arg} {
set arg $res
}
return $arg
}
set corona(name) "Covid-19"
set corona(owner) "BLaCkShaDoW"
set corona(site) "WwW.TclScripts.Net"
set corona(version) "1.3.4"
####
#Language
#
###
set corona(en.lang.1) "Invalid country specified or NO CASES"
set corona(en.lang.2) "You exceded the number of commands. Please wait \002%msg.1%\002 seconds."
#set corona(en.lang.3) "\002COVID-19\002 stats -- \002%msg.1%\002 -- Total Cases: \002%msg.2%\002 ; New Cases: \037%msg.3%\037 ; Total Deaths: \002%msg.4%\002 ; New Deaths: \037%msg.5%\037 ; Recovered: \002%msg.6%\002 ; Active Cases: \037%msg.7%\037 ; Critical: \002%msg.8%\002 ; Total Cases/1M pop: \002%msg.9%\002 ; Deaths/1M pop: \002%msg.10%\002 ; Total tests: \002%msg.11%\002 ; Tests/1M pop: \002%msg.12%\002 ; Last Updated: \002%msg.13%\002"
set corona(en.lang.3) "\00303COVID-19 \00301Stats For \00313(\00310%msg.1%\00313)\00306. \00301Total Cases: \00307%msg.2%\00306. \00301New Cases: \00304%msg.3%\0036. \00301Total Deaths: \00307%msg.4%\00306. \00301New Deaths: \00304%msg.5%\00306. \00301Total Recovered: \00303%msg.6%\00306. \00301Active Cases: \00307%msg.7%\00306. \00301Serious Critical: \00313%msg.8%\00306. \00301Total Cases/1M pop: \00307%msg.9%\00306. \00301Deaths/1M pop: \00304%msg.10%\00306. \00301Total tests: \00307%msg.11%\00306. \00301Tests/1M pop: \00307%msg.12%\00306. \00301Last Updated: \00312%msg.13%\00306.\003"
#set corona(en.lang.4) "(AUTO) \002COVID-19\002 stats -- \002%msg.1%\002 -- Total Cases: \002%msg.2%\002 ; New Cases: \037%msg.3%\037 ; Total Deaths: \002%msg.4%\002 ; New Deaths: \037%msg.5%\037 ; Recovered: \002%msg.6%\002 ; Active Cases: \037%msg.7%\037 ; Critical: \002%msg.8%\002 ; Total Cases/1M pop: \002%msg.9%\002 ; Deaths/1M pop: \002%msg.10%\002 ; Total tests: \002%msg.11%\002 ; Tests/1M pop: \002%msg.12%\002 ; Last Updated: \002%msg.13%\002"
set corona(en.lang.4) "\00303COVID-19 \00301Stats For \00313(\00310%msg.1%\00313)\00306. \00301Total Cases: \00307%msg.2%\00306. \00301New Cases: \00304%msg.3%\0036. \00301Total Deaths: \00307%msg.4%\00306. \00301New Deaths: \00304%msg.5%\00306. \00301Total Recovered: \00303%msg.6%\00306. \00301Active Cases: \00307%msg.7%\00306. \00301Serious Critical: \00313%msg.8%\00306. \00301Total Cases/1M pop: \00307%msg.9%\00306. \00301Deaths/1M pop: \00304%msg.10%\00306. \00301Total tests: \00307%msg.11%\00306. \00301Tests/1M pop: \00307%msg.12%\00306. \00301Last Updated: \00312%msg.13%\00306.\003"
#set corona(en.lang.5) "\002COVID-19\002 stats -- \002%msg.1%\002 -- Total Cases: \002%msg.2%\002 ; New Cases: \037%msg.3%\037 ; Total Deaths: \002%msg.4%\002 ; New Deaths: \037%msg.5%\037 ; Recovered: \002%msg.6%\002 ; Active Cases: \037%msg.7%\037 ; Critical: \002%msg.8%\002 ; Total Cases/1M pop: \002%msg.9%\002 ; Deaths/1M pop: \002%msg.10%\002 ; Last Updated: \002%msg.11%\002"
set corona(en.lang.5) "\00303COVID-19 \00301Stats For \00313(\00310%msg.1%\00313)\00306. \00301Total Cases: \00307%msg.2%\00306. \00301New Cases: \00304%msg.3%\0036. \00301Total Deaths: \00307%msg.4%\00306. \00301New Deaths: \00304%msg.5%\00306. \00301Total Recovered: \00303%msg.6%\00306. \00301Active Cases: \00307%msg.7%\00306. \00301Serious Critical: \00313%msg.8%\00306. \00301Total Cases/1M pop: \00307%msg.9%\00306. \00301Deaths/1M pop: \00304%msg.10%\00306. \00301Last Updated: \00312%msg.11%\00306.\003"
#set corona(en.lang.6) "(AUTO) \002COVID-19\002 stats -- \002%msg.1%\002 -- Total Cases: \002%msg.2%\002 ; New Cases: \037%msg.3%\037 ; Total Deaths: \002%msg.4%\002 ; New Deaths: \037%msg.5%\037 ; Recovered: \002%msg.6%\002 ; Active Cases: \037%msg.7%\037 ; Critical: \002%msg.8%\002 ; Total Cases/1M pop: \002%msg.9%\002 ; Deaths/1M pop: \002%msg.10%\002 ; Last Updated: \002%msg.11%\002"
set corona(en.lang.6) "\00303COVID-19 \00301Stats For \00313(\00310%msg.1%\00313)\00306. \00301Total Cases: \00307%msg.2%\00306. \00301New Cases: \00304%msg.3%\0036. \00301Total Deaths: \00307%msg.4%\00306. \00301New Deaths: \00304%msg.5%\00306. \00301Total Recovered: \00303%msg.6%\00306. \00301Active Cases: \00307%msg.7%\00306. \00301Serious Critical: \00313%msg.8%\00306. \00301Total Cases/1M pop: \00307%msg.9%\00306. \00301Deaths/1M pop: \00304%msg.10%\00306. \00301Last Updated: \00312%msg.11%\00306.\003"
set corona(ro.lang.1) "Tara invalida sau nu sunt cazuri."
set corona(ro.lang.2) "Ai depasit number de comenzi. Te rog asteapta \002%msg.1%\002 secunde."
set corona(ro.lang.3) "Statistici \002COVID-19\002 -- \002%msg.1%\002 -- Cazuri totale: \002%msg.2%\002 ; Cazuri noi: \037%msg.3%\037 ; Total decedati: \002%msg.4%\002 ; Noi decedati: \037%msg.5%\037 ; Recuperati: \002%msg.6%\002 ; Cazuri active: \037%msg.7%\037 ; Cazuri critice: \002%msg.8%\002 ; Total cazuri/1M pop: \002%msg.9%\002 ; Decedati/1M pop: \002%msg.10%\002 ; Total teste: \002%msg.11%\002 ; Teste/1M pop: \002%msg.12%\002 ; Ultimul update: \002%msg.13%\002"
set corona(ro.lang.4) "(AUTO) Statistici \002COVID-19\002 pentru -- %msg.1% -- Cazuri totale: \002%msg.2%\002 ; Cazuri noi: \037%msg.3%\037 ; Total decedati: \002%msg.4%\002 ; Noi decedati: \037%msg.5%\037 ; Recuperati: \002%msg.6%\002 ; Cazuri active: \037%msg.7%\037 ; Cazuri critice: \002%msg.8%\002 ; Total cazuri/1M pop: \002%msg.9%\002 ; Decedati/1M pop: \002%msg.10%\002 ; Total teste: \002%msg.11%\002 ; Teste/1M pop: \002%msg.12%\002 ; Ultimul update: \002%msg.13%\002"
set corona(ro.lang.5) "Statistici \002COVID-19\002 -- \002%msg.1%\002 -- Cazuri totale: \002%msg.2%\002 ; Cazuri noi: \037%msg.3%\037 ; Total decedati: \002%msg.4%\002 ; Noi decedati: \037%msg.5%\037 ; Recuperati: \002%msg.6%\002 ; Cazuri active: \037%msg.7%\037 ; Cazuri critice: \002%msg.8%\002 ; Total cazuri/1M pop: \002%msg.9%\002 ; Decedati/1M pop: \002%msg.10%\002 ; Ultimul update: \002%msg.11%\002"
set corona(ro.lang.6) "(AUTO) Statistici \002COVID-19\002 pentru -- %msg.1% -- Cazuri totale: \002%msg.2%\002 ; Cazuri noi: \037%msg.3%\037 ; Total decedati: \002%msg.4%\002 ; Noi decedati: \037%msg.5%\037 ; Recuperati: \002%msg.6%\002 ; Cazuri active: \037%msg.7%\037 ; Cazuri critice: \002%msg.8%\002 ; Total cazuri/1M pop: \002%msg.9%\002 ; Decedati/1M pop: \002%msg.10%\002 ; Ultimul update: \002%msg.11%\002"
#Translated in spanish by charls_a
#Ayuda @ Undernet.org
set corona(es.lang.1) "Nombre de pais invalido, o no presenta casos."
set corona(es.lang.2) "Has excedido el numero de intentos. Por favor espera \002%msg.1%\002 segundos."
set corona(es.lang.3) "\002COVID-19\002 Estadisticas -- \002%msg.1%\002 -- Total de Casos: \002%msg.2%\002 ; Nuevos Casos: \037%msg.3%\037 ; Total de personas fallecidas: \002%msg.4%\002 ; Nuevos casos de personas fallecidas: \037%msg.5%\037 ; Recuperados: \002%msg.6%\002 ; Casos activos: \037%msg.7%\037 ; En estado critico: \002%msg.8%\002 ; Total de Casos/1M pob: \002%msg.9%\002 ; Fallecimientos/1M pob: \002%msg.10%\002 ; Total de pruebas: \002%msg.11%\002 ; Pruebas/1M pob: \002%msg.12%\002 ; Ultima actualizacion: \002%msg.13%\002"
set corona(es.lang.4) "(AUTO) \002COVID-19\002 Estadisticas -- \002%msg.1%\002 -- Total de Casos: \002%msg.2%\002 ; Nuevos Casos: \037%msg.3%\037 ; Total de personas fallecidas: \002%msg.4%\002 ; Nuevoss casos de personas fallecidas: \037%msg.5%\037 ; Recuperados: \002%msg.6%\002 ; Casos activos: \037%msg.7%\037 ; En estado critico: \002%msg.8%\002 ; Total de Casos/1M pob: \002%msg.9%\002 ; Fallecimientos/1M pob: \002%msg.10%\002 ; Total de pruebas: \002%msg.11%\002 ; Pruebas/1M pob: \002%msg.12%\002 ; Ultima actualizacion: \002%msg.13%\002"
set corona(es.lang.5) "\002COVID-19\002 Estadisticas -- \002%msg.1%\002 -- Total de Casos: \002%msg.2%\002 ; Nuevos Casos: \037%msg.3%\037 ; Total de personas fallecidas: \002%msg.4%\002 ; Nuevos casos de personas fallecidas: \037%msg.5%\037 ; Recuperados: \002%msg.6%\002 ; Casos activos: \037%msg.7%\037 ; En estado critico: \002%msg.8%\002 ; Total de Casos/1M pob: \002%msg.9%\002 ; Fallecimientos/1M pob: \002%msg.10%\002 ; Ultima actualizacion: \002%msg.11%\002"
set corona(es.lang.6) "(AUTO) \002COVID-19\002 Estadisticas -- \002%msg.1%\002 -- Total de Casos: \002%msg.2%\002 ; Nuevos Casos: \037%msg.3%\037 ; Total de personas fallecidas: \002%msg.4%\002 ; Nuevos casos de personas fallecidas: \037%msg.5%\037 ; Recuperados: \002%msg.6%\002 ; Casos activos: \037%msg.7%\037 ; En estado critico: \002%msg.8%\002 ; Total de Casos/1M pob: \002%msg.9%\002 ; Fallecimientos/1M pob: \002%msg.10%\002 ; Ultima actualizacion: \002%msg.11%\002"
putlog "$corona(name) $corona(version) TCL by $corona(owner) loaded. For more tcls visit -- $corona(site) --"