· 6 years ago · Apr 19, 2020, 01:18 PM
1; This is your trigger: !weather city,countrycode
2; for example:
3; !weather New York,us
4; !weather Brisbane,au
5; !weather Paris,fr
6
7on $*:TEXT:/^!weather (.+,\w{2})$/iSgm:#:{ weather $regml(1) }
8
9alias weather {
10 ; whitelist networks:
11 var %whitelist_networks freenode efnet swiftirc
12 if (!$istok(%whitelist_networks,$network,32)) return
13 ; whitelist channels:
14 var %whitelist_channels #abcdef1245 #mychannel1 #mychannel2 #mychannel3
15 if (!$istok(%whitelist_channels,$chan,32)) return
16
17 ; already being looked into?
18 if ($hfind($+(openweathermap,.,$cid,.,$chan),$1-,0).data) return
19
20 ;queue maintenance
21 if ($hget($+(openweathermap,.,$cid,.,$chan),*) == $null) {
22 var %n 1
23 }
24 else {
25 var %n $v1 + 1
26 }
27 ;add to queue (index)
28 hadd -m13 $+(openweathermap,.,$cid,.,$chan) %n $1-
29 hadd -m13 $+(openweathermap,.,$cid,.,$chan) * %n
30
31 ; if timer hasn't been started, start it
32 if (!$timer(.owm_queue)) .timer.owm_queue -mio 0 500 _owm.queue $cid $unsafe($chan)
33}
34alias _owm.queue {
35 var %i 1, %cid $1, %chan $2
36 var %* $hget($+(openweathermap,.,%cid,.,%chan),*)
37 ; ------------------------------------------------
38 ;
39 ; Please insert your API key here:
40 ;
41 ; ------------------------------------------------
42 var %api_key 12345678987654321
43
44 var %owm_url https://api.openweathermap.org/data/2.5/weather
45
46 ; ------------------------------------------------
47 ;
48 ; Specify units as either imperial or metric:
49 ;
50 ; ------------------------------------------------
51 var %units metric
52
53 while (%i <= %* ) {
54
55 if ($hget($+(openweathermap,.,%cid,.,%chan),%i)) {
56 tokenize 44 $v1
57
58 ; convert all spaces to %20 sequence
59 ; New York becomes New%20York
60 var %city $replace($1,$chr(32),$chr(37) $+ 20)
61 ; The on TEXT event makes sure it's two digits, no further validation is done
62 var %countrycode $2
63
64 var %search $+(?q=,%city,$chr(44),%countrycode)
65 var %page $+(%owm_url,%search,&units=,%units,&appid=,%api_key)
66
67 jsonopen -u owm %page
68 .timer -mio 1 1 scid %cid .msg %chan City: $json(owm,name).value - Country Code: $json(owm,sys,country).value - Temp: $json(owm,main,temp).value Celsius - Min temp: $json(owm,main,temp_min).value Celsius - Max temp: $json(owm,main,temp_max).value Celsius
69 jsonclose owm
70 hdel $+(openweathermap,.,%cid,.,%chan) %i
71 if (%i == %*) {
72 timer.owm_queue off
73 hdel $hget($+(openweathermap,.,%cid,.,%chan)) *
74 }
75 }
76 inc %i
77 }
78}
79
80
81level 3
82mircpnp
831 point
84·
858 months ago
86Haven't tested it thoroughly. YMMV
87
88Cheers!
89
90P.S.: I've set the default units to metric, and wrote down Celsius after the JSONOpen. You may wish to change it to imperial and then to F...Have a look at the API docs on the web!
91
92
93
94level 4
95sweedishchef8286
961 point
97·
988 months ago
99Not working..And with the previous script-I did find the metric/imperial trigger...But its giving wrong information. its saying the Temp is 12.63 C or 54 F...its like, 85F/29C
100
101
102
103level 5
104mircpnp
1051 point
106·
1078 months ago
108I revisited this in the last couple of days. There's a WEATHER.PPA addon for Peace and Protection now that should work fine :-)
109
110https://github.com/acvxqs/PnPAddons422