Ford

Google weather toolbar / working

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