Advertisement
Blizzardo1

WeatherApi for mIRC

Sep 22nd, 2024 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 10.21 KB | Source Code | 0 0
  1. ; Weather v2.2 - by entropy 2023
  2.  
  3. ; Help: !weather <set> <location/zipcode> - If you specify <set>, set default location. Otherwise, displays the weather on location.
  4.  
  5. ; Get your own API key: https://www.weatherapi.com/signup.aspx
  6.  
  7. ; Shoutout to entropy for allowing me to copy this code. Give them the best cup of coffee in the world!
  8.  
  9. ; Original Source Code: https://www.mircscripts.info/?page=project&id=9WwwZ
  10.  
  11. menu menubar,status,channel,query {
  12.   -
  13.   Weather v2.2 $chr(9) $replace($group(#weather).status,o,O)
  14.   .Turn it $iif($group(#weather).status == on,Off,On) {
  15.     $iif($group(#weather).status == on,.disable,.enable) #weather
  16.     echo 3 -ag * Weather is now: $qt($replace($group(#weather).status,o,O))
  17.   }
  18.   .-
  19.   .Channel(s) $chr(9) $eval($+(%,weatherchans,.,$network),2) {
  20.     var %net = $eval($+(%,weatherchans,.,$network),2)
  21.     var %text = $input(Channels list (seperated by comma) or "#" for all?,5,Weather,%net)
  22.     %text = $replace(%text,$chr(32),$chr(44))
  23.     var %a = 1, %b
  24.     while ($gettok(%text,%a,44)) {
  25.       %b = $v1
  26.       if ($left(%b,1) != $chr(35)) { %text = $reptok(%text,%b,$+($chr(35),%b),1,44) }
  27.       inc %a
  28.     }
  29.     if (%text) { set $+(%,weatherchans,.,$network) $v1 | echo 3 -ag * Weather Channels are now: $qt($v1) }
  30.     else { unset $+(%,weatherchans,.,$network) | echo 3 -ag * Weather Channels are now reset }
  31.   }
  32.   .$iif(!$istok($eval($+(%,weatherchans,.,$network),2),$chan,44) && $eval($+(%,weatherchans,.,$network),2) != $chr(35) && $menu == channel,Add Channel To list) {
  33.     var %net = $eval($+(%,weatherchans,.,$network),2)
  34.     var %net = $addtok(%net,$chan,44)
  35.     set $+(%,weatherchans,.,$network) %net
  36.     echo 3 -ag * Weather Channels are now: $qt($eval($+(%,weatherchans,.,$network),2))
  37.   }
  38.   .$iif($istok($eval($+(%,weatherchans,.,$network),2),$chan,44) && $menu == channel,Delete Channel From list) {
  39.     var %net = $eval($+(%,weatherchans,.,$network),2)
  40.     var %net = $remtok(%net,$chan,1,44)
  41.     set $+(%,weatherchans,.,$network) %net
  42.     echo 3 -ag * Weather Channels are now $+ $iif(!%net,$chr(32) reset,: $qt(%net))
  43.   }
  44.   .-
  45.   .$iif($eval($+(%,weatherchans,.,$network),2),Delete all Channels) {
  46.     unset $+(%,weatherchans,.,$network)
  47.     echo 3 -ag * Weather Channels are now reset
  48.   }
  49.   .-
  50.   .API Key $chr(9) $iif(%api_key,$v1,NA) {
  51.     set %api_key $input(Weather API Key?,5)
  52.     echo 3 -ag * Weather API is now: $qt(%api_key)
  53.   }
  54.   .-
  55.   .Get an API key { run https://www.weatherapi.com/signup.aspx }
  56.   -
  57. }
  58.  
  59. #weather off
  60. on *:input:$($eval($+(%,weatherchans,.,$network),2)):{ if (/* !iswm $1 && $server) { loadit | doweather # $me $1- } }
  61. on *:text:*:$($eval($+(%,weatherchans,.,$network),2)):{ loadit | doweather # $nick $1- }
  62. #weather end
  63.  
  64. ;==================================================
  65.  
  66. on *:load:{ echo 3 -a * Weather is now loaded! | loadit }
  67. on *:unload:{ echo 3 -a * Weather is now unloaded! | unset %weatherchans.* %api_key | saveit | if ($hget(weather)) { hfree weather } }
  68. on *:exit:{ saveit }
  69.  
  70. ;==================================================
  71.  
  72. alias -l loadit { if (!$hget(weather)) { hmake weather 100 | if ($isfile($qt($mircdirweather.dat))) { hload weather $qt($mircdirweather.dat) } } }
  73. alias -l saveit { if ($hget(weather)) { hsave -o weather $qt($mircdirweather.dat) } }
  74.  
  75. ;==================================================
  76.  
  77. alias -l doweather {
  78.   if (!$3) { return }
  79.   elseif (!weather == $3 || !w == $3) {
  80.     var %loc = $iif($4-,$v1,$hget(weather,$2))
  81.     weather # $2 %loc
  82.   }
  83. }
  84. alias -l weather {
  85.   if (!$2) { return }
  86.   var %text = $3-, %target
  87.   if ($findtok(%text,c,1,32)) { %text = $remtok(%text,c,1,32) }
  88.   if ($findtok(%text,f,1,32)) { %text = $remtok(%text,f,1,32) }
  89.   if ($gettok(%text,-1,44) == c) { %text = $remove(%text,$+($chr(44),c)) }
  90.   if ($gettok(%text,-1,44) == f) { %text = $remove(%text,$+($chr(44),f)) }
  91.   if ($right(%text,1) == $chr(44)) { %text = $mid(%text,1,-1) }
  92.   if (!$3 && !$hget(weather,$2)) {
  93.     msg $1 [Weather] $c No location specified!
  94.     return
  95.   }
  96.   if ($gettok(%text,1,32) == set) {
  97.     if ($gettok(%text,2-,32)) { hadd weather $2 $gettok(%text,2-,32) | %target = $gettok(%text,2-,32) }
  98.     else { msg $1 [Weather] $c No location specified! | return }
  99.   }
  100.   if (!%target && $gettok(%text,1-,32)) { %target = $v1 }
  101.   elseif (!%target) { %target = $hget(weather,$2) }
  102.  
  103.   set %_weatherchan $1
  104.   set %_weathernick $2
  105.   ; old API weatherAPI $+(https://api.weatherapi.com/v1/forecast.json?key=,%api_key,&q=,$urify(%target),&days=1&aqi=no&alerts=no)
  106.   weatherAPI $+(https://api.weatherapi.com/v1/current.json?key=,%api_key,&q=,$urify(%target))
  107. }
  108.  
  109. ;==================================================
  110.  
  111. alias -l weatherAPI { noop $urlget($1-,gbi,&Weather,processweatherAPI) }
  112. alias -l processweatherAPI {
  113.   var %id = $1 , %BV = $urlget(%id).target, %code = $gettok($urlget(%id).reply,2,32)
  114.   if (%code == 403) { msg %_weatherchan [Weather] $c Bad API Key! | unset %_weather* | return }
  115.   elseif (%code != 200) { msg %_weatherchan [Weather] $c Error code: %code | unset %_weather* | return }
  116.   var %total = [Weather] $c
  117.   %total = %total $remove($bvsearch(%BV,"name":,$chr(44)).inbetween,") $+ ,
  118.   if ($remove($bvsearch(%BV,"region":,$chr(44)).inbetween,")) { %total = %total $v1 $+ , }
  119.   var %country = $replace($remove($bvsearch(%BV,"country":,$chr(44)).inbetween,"),United States of America,USA)
  120.   if ($numtok(%country,32) == 2 && $gettok(%country,1,32) == $gettok(%country,2,32)) { %country = $gettok(%country,1,32) }
  121.   %total = %total %country
  122.   %total = %total $c Temp: $bvsearch(%BV,"temp_f":,$chr(44)).inbetween $+ °F ( $+ $bvsearch(%BV,"temp_c":,$chr(44)).inbetween $+ °C)
  123.   if ($bvsearch(%BV,"temp_f":,$chr(44)).inbetween != $bvsearch(%BV,"feelslike_f":,$chr(44)).inbetween) {
  124.     %total = %total $c Feels like: $bvsearch(%BV,"feelslike_f":,$chr(44)).inbetween $+ °F ( $+ $bvsearch(%BV,"feelslike_c":,$chr(44)).inbetween $+ °C)
  125.   }
  126.   %total = %total $c Lat: $bvsearch(%BV,"lat":,$chr(44)).inbetween
  127.   %total = %total $c Lon: $bvsearch(%BV,"lon":,$chr(44)).inbetween
  128.   %total = %total $c Wind: $bvsearch(%BV,"wind_mph":,$chr(44)).inbetween
  129.   %total = %total $c Wind Degree: $bvsearch(%BV,"wind_degree":,$chr(44)).inbetween
  130.   %total = %total $c Wind Direction: $remove($bvsearch(%BV,"wind_dir":,$chr(44)).inbetween,")
  131.   %total = %total $c Condition: $remove($bvsearch(%BV,"condition":,$chr(44)).inbetween,{"text":,")
  132.   %total = %total $c Pressure: $bvsearch(%BV,"pressure_mb":,$chr(44)).inbetween $+ mb
  133.   %total = %total $c Humidity: $bvsearch(%BV,"humidity":,$chr(44)).inbetween $+ %
  134.   %total = %total $c Clouds: $bvsearch(%BV,"cloud":,$chr(44)).inbetween $+ %
  135.   %total = %total $c Visibility: $bvsearch(%BV,"vis_km":,$chr(44)).inbetween miles
  136.  
  137.   msg %_weatherchan $mid(%total,1,400)
  138.  
  139.   if ($len(%total) >= 401) {
  140.     var %out = $mid(%total,401,401) $+ $iif($len(%total) >= 802,$dot))
  141.     msg %_weatherchan %out
  142.   }
  143.   unset %_weather*
  144. }
  145.  
  146. alias -l bvsearch {
  147.   var %S = $bfind($1,1,$2)
  148.   var %E = $bfind($1,$calc(%S + $len($2)),$3)
  149.   if (%S <= 0 || %E <= 0) { return }
  150.   if ($prop == inbetween) { var %S = %S + $len($2) , %E = %E - 1 }
  151.   else { var %E = %E + $iif($regex($3,/(?:\d+|\s)/g),$numtok($3,32),$len($3)) | dec %e }
  152.   return $left( $bvar($1,$+(%S,-,%E)).text , $maxlenl)
  153. }
  154.  
  155. alias -l replacehtmlentities { return $regsubex($1-,/(\x26[^\x3B]+)\x3B/g,$entitieshtml(\1)) }
  156. alias -l entitieshtml {
  157.   if ($mid($1,2,1) == $chr(35)) { return $chr($mid($1,3)) }
  158.   elseif ($findtok(&amp;&lt;&gt;&Agrave;&Aacute;&Acirc;&Atilde;&Auml;&Aring;&AElig;&Ccedil;&Egrave;&Eacute;&Ecirc;&Euml;&Igrave;&Iacute;&Icirc;&Iuml;&ETH;&Ntilde;&Ograve;&Oacute;&Ocirc;&Otilde;&Ouml;&Oslash;&Ugrave;&Uacute;&Ucirc;&Uuml;&Yacute;&THORN;&szlig;&agrave;&aacute;&acirc;&atilde;&auml;&aring;&aelig;&ccedil;&egrave;&eacute;&ecirc;&euml;&igrave;&iacute;&icirc;&iuml;&eth;&ntilde;&ograve;&oacute;&ocirc;&otilde;&ouml;&oslash;&ugrave;&uacute;&ucirc;&uuml;&yacute;&thorn;&yuml;&nbsp;&iexcl;&cent;&pound;&curren;&yen;&brvbar;&sect;&uml;&copy;&ordf;&laquo;&not;&shy;&reg;&macr;&deg;&plusmn;&sup2;&sup3;&acute;&micro;&para;&cedil;&sup1;&ordm;&raquo;&frac14;&frac12;&frac34;&iquest;&times;&divide;&forall;&part;&exist;&empty;&nabla;&isin;&notin;&ni;&prod;&sum;&minus;&lowast;&radic;&prop;&infin;&ang;&and;&or;&cap;&cup;&int;&there4;&sim;&cong;&asymp;&ne;&equiv;&le;&ge;&sub;&sup;&nsub;&sube;&supe;&oplus;&otimes;&perp;&sdot;&Alpha;&Beta;&Gamma;&Delta;&Epsilon;&Zeta;&Eta;&Theta;&Iota;&Kappa;&Lambda;&Mu;&Nu;&Xi;&Omicron;&Pi;&Rho;&Sigma;&Tau;&Upsilon;&Phi;&Chi;&Psi;&Omega;&alpha;&beta;&gamma;&delta;&epsilon;&zeta;&eta;&theta;&iota;&kappa;&lambda;&mu;&nu;&xi;&omicron;&pi;&rho;&sigmaf;&sigma;&tau;&upsilon;&phi;&chi;&psi;&omega;&thetasym;&upsih;&piv;&OElig;&oelig;&Scaron;&scaron;&Yuml;&fnof;&circ;&tilde;&ensp;&emsp;&thinsp;&zwnj;&zwj;&lrm;&rlm;&ndash;&mdash;&lsquo;&rsquo;&sbquo;&ldquo;&rdquo;&bdquo;&dagger;&Dagger;&bull;&hellip;&permil;&prime;&Prime;&lsaquo;&rsaquo;&oline;&euro;&trade;&larr;&uarr;&rarr;&darr;&harr;&crarr;&lceil;&rceil;&lfloor;&rfloor;&loz;&spades;&clubs;&hearts;&diams,$1,59)) {
  159.     return $chr($gettok(38;60;62;192;193;194;195;196;197;198;199;200;201;202;203;204;205;206;207;208;209;210;211;212;213;214;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;248;249;250;251;252;253;254;255;160;161;162;163;164;165;166;167;168;169;170;171;172;173;174;175;176;177;178;179;180;181;182;184;185;186;187;188;189;190;191;215;247;8704;8706;8707;8709;8711;8712;8713;8715;8719;8721;8722;8727;8730;8733;8734;8736;8743;8744;8745;8746;8747;8756;8764;8773;8776;8800;8801;8804;8805;8834;8835;8836;8838;8839;8853;8855;8869;8901;913;914;915;916;917;918;919;920;921;922;923;924;925;926;927;928;929;931;932;933;934;935;936;937;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;977;978;982;338;339;352;353;376;402;710;732;8194;8195;8201;8204;8205;8206;8207;8211;8212;8216;8217;8218;8220;8221;8222;8224;8225;8226;8230;8240;8242;8243;8249;8250;8254;8364;8482;8592;8593;8594;8595;8596;8629;8968;8969;8970;8971;9674;9824;9827;9829;9830,$v1,59))
  160.   }
  161. }
  162.  
  163. alias -l urify { set -l %a !@$*()-_=:',./? | return $regsubex($1-,/(\W)/g,$iif($pos(%a,\1,1),\1,$iif(\1 = $chr(32),+,$+(%,$base($asc($1),10,16,2))))) }
  164. alias -l dot { return $chr(8230) }
  165. alias -l c { return $chr(9679) }
Tags: Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement