Ford

Google Weather / Toolbar

May 28th, 2011
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 9.73 KB | None | 0 0
  1. ;Google ToolBar Weather by Ford_Lawnmower irc.GeekShed.net #Script-Help
  2. alias GweatherTBInit {
  3.   ;Change %MyLocation to the location you want to monitor.
  4.   ;**Note** This does NOT accept airport codes. City,State-City,Country or ZipCode.
  5.   var %MyLocation Hamilton,Ohio
  6.   ;Change %ForC to F or C for the Measurement Unit you want to use.
  7.   var %ForC F
  8.   if (!$isdir(GoogleWeatherTB)) mkdir GoogleWeatherTB
  9.   writeini GoogleWeatherTB\GoogleWeatherTB.ini Settings MeasurementUnit %ForC
  10.   writeini GoogleWeatherTB\GoogleWeatherTB.ini Settings Location %MyLocation
  11.   window -hp +d @GoogleWeather 535 0 63 22
  12.   drawfill -r @GoogleWeather $rgb(240,240,230) $rgb(240,240,240) 0 0
  13.   GetGoogleWeather Window 0 %MyLocation
  14.   .timerGoogleWeatherTB -o 0 100 GetGoogleWeather Window 0 %MyLocation
  15. }
  16. on *:Start: {
  17.   if ($readini(GoogleWeatherTB\GoogleWeatherTB.ini,Settings,Status) != Off) GweatherTBInit
  18. }
  19. On *:Unload: .timerGoogleWeatherTB off
  20. alias -l GetGoogleWeather {
  21.   .sockclose G.o.o.gleWeatherTB
  22.   sockopen G.o.o.gleWeatherTB www.google.com 80
  23.   sockmark G.o.o.gleWeatherTB $1 $+(/ig/api?weather=,$urlencode($3-)) $2
  24. }
  25. On *:sockopen:G.o.o.gleWeatherTB: {
  26.   if (!$sockerr) {
  27.     sockwrite -nt $sockname GET $gettok($sock($sockname).mark,2,32) HTTP/1.1
  28.     sockwrite -n $sockname User-Agent: Opera 9.6
  29.     sockwrite -n $sockname Host: $sock($sockname).addr
  30.     sockwrite -n $sockname $crlf
  31.   }
  32.   else { sockclose $sockname | return }
  33. }
  34. On *:sockread:G.o.o.gleWeatherTB: {
  35.   if ($sockerr) { sockclose $sockname | return }
  36.   else {
  37.     var %GoogleWeather | sockread %GoogleWeather
  38.     var %OutputMethod $gettok($sock($sockname).mark,1,32)
  39.     if (<problem_cause data=""/> isin %GoogleWeather && %OutputMethod == Dialog) {
  40.       did -ra GoogleWeather 2 $did(GoogleWeather,28) :: No Data found for $did(GoogleWeather,28)
  41.     }
  42.     if ($regex(%GoogleWeather,/<city data="(.*?)"\/>/i)) {
  43.       if (%OutputMethod == Dialog) {
  44.         dialog $iif($dialog(GoogleWeather),-v,-m GoogleWeather) GoogleWeather
  45.         did -ra GoogleWeather 2 $regml(1) on $fulldate
  46.       }
  47.       else sockmark $sockname $addtok($sock($sockname).mark,$regml(1),13)
  48.     }
  49.     if ($regex(%GoogleWeather,/<humidity data="[^:]*:(.*?)"\/>/i)) {
  50.       if (%OutputMethod == Dialog) did -ra GoogleWeather 32 $regml(1)
  51.       else sockmark $sockname $addtok($sock($sockname).mark,$regml(1),13)
  52.     }
  53.     if ($regex(%GoogleWeather,/<wind_condition data="[^:]*:(.*?)"\/>/i)) {
  54.       if (%OutputMethod == Dialog) did -ra GoogleWeather 33 $regml(1)
  55.       else sockmark $sockname $addtok($sock($sockname).mark,$regml(1),13)
  56.     }
  57.     if ($regex(%GoogleWeather,/<day_of_week data="(.*?)"\/>/gi) && %OutputMethod == Dialog) {
  58.       var %count 1
  59.       while (%count <= $regml(0)) {
  60.         did -ra GoogleWeather $calc(%count + 6) $regml(%count)
  61.         inc %count
  62.       }
  63.     }  
  64.     if ($regex(%GoogleWeather,/<low data="(.*?)"\/>/gi) && %OutputMethod == Dialog) {
  65.       var %count 1
  66.       while (%count <= $regml(0)) {
  67.         did -ra GoogleWeather $calc(%count + 14) $+(Low:,$forc($regml(%count)))
  68.         inc %count
  69.       }
  70.     }
  71.     if ($regex(%GoogleWeather,/<high data="(.*?)"\/>/gi) && %OutputMethod == Dialog) {
  72.       var %count 1
  73.       while (%count <= $regml(0)) {
  74.         did -ra GoogleWeather $calc(%count + 18) $+(High:,$forc($regml(%count)))
  75.         inc %count
  76.       }
  77.     }      
  78.     if ($regex(%GoogleWeather,/<condition data="(.*?)"\/>/gi)) {
  79.       if (%OutputMethod == Window) {
  80.         clear @GoogleWeather
  81.         window -r @GoogleWeather 535 0 63 22
  82.         drawfill -r @GoogleWeather $rgb(240,240,230) $rgb(240,240,240) 0 0
  83.         sockmark $sockname $addtok($sock($sockname).mark,$regml(1),13)          
  84.       }
  85.       elseif (%OutputMethod == Dialog) {
  86.         did -ra GoogleWeather 31 $regml(1)
  87.         var %count 2
  88.         while (%count <= $regml(0)) {
  89.           did -ra GoogleWeather $calc(21 + %count) $regml(%count)
  90.           inc %count
  91.         }
  92.       }
  93.     }
  94.     if ($regex(%GoogleWeather,/<temp_f\sdata="(.*?)"\/>/)) {
  95.       if (%OutputMethod == Window) {
  96.         drawtext -np @GoogleWeather 1 arial 14 30 4 $+($chr(2),$forc($regml(1)),$chr(186))
  97.         sockmark $sockname $addtok($sock($sockname).mark,$+($forc($regml(1)),$chr(186)),13)
  98.       }
  99.       elseif (%OutputMethod == Dialog) did -ra GoogleWeather 34 $+($forc($regml(1)),$chr(186))
  100.     }
  101.     if ($regex(%GoogleWeather,/<icon data="http:\/\/(.*?)\/(.*?)\/([^\/]*?)"\/>/gi)) {
  102.       GetGoogleWeatherIcon $regml(1) $+($regml(2),/,$regml(3)) GoogleWeatherTB $regml(3) %OutputMethod 0
  103.       if ($window(@GoogleWeather)) {
  104.         tokenize 13 $sock($sockname).mark
  105.         UpdateToolBar -tp Location: $2 $+(Humidity:,$3) $+(Wind:,$4) Conditon: $5 Temp: $6
  106.       }
  107.       if (%OutputMethod == Dialog) {
  108.         var %c 4, %cc 2
  109.         while (%c <= $regml(0)) {
  110.           GetGoogleWeatherIcon $regml(%c) $+($regml($calc(%c + 1)),/,$regml($calc(%c + 2))) GoogleWeatherTB $regml($calc(%c + 2)) %OutputMethod %cc
  111.           inc %c 3
  112.           inc %cc
  113.         }
  114.       }
  115.     }
  116.   }
  117. }
  118. alias -l UpdateToolBar {
  119.   drawsave @GoogleWeather GoogleWeatherTB\GoogleWeather.jpg
  120.   if ($toolbar(GoogleWeather)) {
  121.     toolbar $1 GoogleWeather $qt($2-) "GoogleWeatherTB\GoogleWeather.jpg" $&
  122.       $qt(/GetGoogleWeather Dialog 0 $readini(GoogleWeatherTB\GoogleWeatherTB.ini,Settings,Location)) @GoogleWeather
  123.   }
  124.   else {
  125.     toolbar -as GoogleWeather|
  126.     toolbar -a GoogleWeather $qt($2-) "GoogleWeatherTB\GoogleWeather.jpg" $&
  127.       $qt(/GetGoogleWeather Dialog 0 $readini(GoogleWeatherTB\GoogleWeatherTB.ini,Settings,Location)) @GoogleWeather
  128.   }
  129. }
  130. alias -l GetGoogleWeatherIcon {
  131.   if ($isfile($qt($+($3,\,$4)))) {
  132.     if ($5 == Window) drawpic -ns @GoogleWeather 0 0 25 22 $+(GoogleWeatherTB/,$4)
  133.     elseif (($5 == Dialog)) did -g GoogleWeather $iif($6,$calc($6 + 9),3) $qt($+(GoogleWeatherTB/,$4))
  134.   }
  135.   else {
  136.     var %sockname $+(GetGoogleWeatherIcon,$ticks,$r(1,$ticks))
  137.     if (!$isdir($qt($3))) { mkdir $qt($3) }
  138.     sockopen %sockname $1 80
  139.     sockmark %sockname $1-
  140.   }
  141. }
  142. On *:sockopen:GetGoogleWeatherIcon*:{
  143.   sockwrite -nt $sockname GET $+(/,$gettok($sock($sockname).mark,2,32)) HTTP/1.0
  144.   sockwrite -n $sockname Host: $gettok($sock($sockname).mark,1,32) $+ $crlf $+ $crlf
  145. }
  146. On *:sockread:GetGoogleWeatherIcon*:{
  147.   if (!$gettok($sock($sockname).mark,7,32)) {
  148.     var %GetGoogleWeatherIcon | sockread %GetGoogleWeatherIcon
  149.     if (!%GetGoogleWeatherIcon) { sockmark $sockname $addtok($sock($sockname).mark,1,32) }
  150.   }
  151.   else {
  152.     sockread &GetGoogleWeatherIcon
  153.     bwrite -s $qt($+($gettok($sock($sockname).mark,3,32),\,$gettok($sock($sockname).mark,4,32))) -1 -1 &GetGoogleWeatherIcon
  154.   }
  155. }
  156. On *:sockclose:GetGoogleWeatherIcon*:{
  157.   tokenize 32 $sock($sockname).mark
  158.   if ($exists($qt($+($3,/,$4)))) {
  159.     if ($5 == Window) {
  160.       drawpic -s @GoogleWeather 0 0 25 22 $qt($+($3,/,$4))
  161.     }
  162.     elseif ($5 == Dialog) {
  163.       if (!$6) did -g GoogleWeather 3 $qt($+($3,/,$4))
  164.       else did -g GoogleWeather $calc(9 + $6) $qt($+($3,/,$4))
  165.     }
  166.   }
  167. }
  168. alias -l ForC {
  169.   if ($readini(GoogleWeatherTB\GoogleWeatherTB.ini,Settings,MeasurementUnit) == C) {
  170.     return $round($calc((5 / 9) * ($1 - 32)),0)
  171.   }
  172.   else return $1
  173. }
  174. alias -l urlencode return $replace($regsubex($1-,/([^a-z0-9\s])/ig,% $+ $base($asc(\t),10,16,2)),$chr(32),+)
  175. menu @GoogleWeather {
  176.   Google Weather
  177.   .$iif($timer(GoogleWeatherTB),$style(3)) On:{
  178.     writeini GoogleWeatherTB\GoogleWeatherTB.ini Settings Status On
  179.     GweatherTBInit
  180.   }
  181.   .$iif(!$timer(GoogleWeatherTB),$style(3)) Off:{
  182.     .timerGoogleWeatherTB off
  183.     window -c @GoogleWeather
  184.     if ($toolbar(GoogleWeather)) toolbar -d GoogleWeather
  185.     if ($toolbar(GoogleWeather|)) toolbar -d GoogleWeather|
  186.     writeini GoogleWeatherTB\GoogleWeatherTB.ini Settings Status Off
  187.     -
  188.   }
  189.   .Dialogs:dialog $iif($dialog(GoogleWeather),-v,-m GoogleWeather) GoogleWeather
  190. }
  191. menu channel,status,menubar {
  192.   -
  193.   Google Weather
  194.   .$iif($timer(GoogleWeatherTB),$style(3)) On:{
  195.     writeini GoogleWeatherTB\GoogleWeatherTB.ini Settings Status On
  196.     GweatherTBInit
  197.   }
  198.   .$iif(!$timer(GoogleWeatherTB),$style(3)) Off:{
  199.     .timerGoogleWeatherTB off
  200.     window -c @GoogleWeather
  201.     if ($toolbar(GoogleWeather)) toolbar -d GoogleWeather
  202.     if ($toolbar(GoogleWeather|)) toolbar -d GoogleWeather|
  203.     writeini GoogleWeatherTB\GoogleWeatherTB.ini Settings Status Off
  204.   }
  205.   .Dialogs:dialog $iif($dialog(GoogleWeather),-v,-m GoogleWeather) GoogleWeather
  206. }
  207. On *:dialog:GoogleWeather:Sclick:29: {
  208.   if ($did(28)) getgoogleweather dialog 0 $v1
  209. }
  210. dialog GoogleWeather {
  211.   title "Google Weather"
  212.   size -1 -1 232 129
  213.   option dbu
  214.   text "Current Weather for", 1, 5 2 52 8
  215.   text "", 2, 57 2 168 8
  216.   icon 3, 6 17 20 20
  217.   text "Condition:", 4, 34 14 27 8
  218.   text "Humidity:", 5, 34 24 27 8
  219.   text "Wind:", 6, 34 34 27 8
  220.   text "", 7, 9 54 54 8, center
  221.   text "", 8, 63 54 54 8, center
  222.   text "", 9, 117 54 54 8, center
  223.   text "", 10, 171 54 54 8, center
  224.   icon 11, 26 63 20 20
  225.   icon 12, 80 63 20 20
  226.   icon 13, 134 63 20 20
  227.   icon 14, 186 63 20 20
  228.   text "", 15, 9 87 25 8
  229.   text "", 16, 63 87 25 8
  230.   text "", 17, 117 87 25 8
  231.   text "", 18, 171 87 25 8
  232.   text "", 19, 34 87 29 8
  233.   text "", 20, 88 87 29 8
  234.   text "", 21, 142 87 29 8
  235.   text "", 22, 196 87 29 8
  236.   text "", 23, 9 96 54 16, center
  237.   text "", 24, 63 96 54 16, center
  238.   text "", 25, 117 96 54 16, center
  239.   text "", 26, 171 96 54 16, center
  240.   text "Location:", 27, 9 116 24 8
  241.   edit "", 28, 33 115 110 10, autohs
  242.   button "Check", 29, 148 114 37 12
  243.   button "Close", 30, 188 114 37 12, cancel
  244.   text "", 31, 61 14 164 8
  245.   text "", 32, 61 24 163 8
  246.   text "", 33, 61 34 163 8
  247.   text "", 34, 5 39 25 8, center
  248.   box "", 35, 170 49 54 64
  249.   box "", 36, 62 49 54 64
  250.   box "", 37, 116 49 54 64
  251.   box "", 38, 8 49 54 64
  252. }
Add Comment
Please, Sign In to add comment