usmiv4o

Weather from weather.com

1 post in this topic

#1 ·  Posted

 

Yet another weather scrypt, but this one is working. All other that I search for aren not functioning.

To get you City code go to weather.com and inside URL is code.

this script parses XML from weather.com and shows to MSgBox and console.

#cs

Description:    Weather XML from Weather.com.
author:         usmiv4o (just repaired old script)
date:           29.7.2017

to get City code go to weather.com and copy City code from URL
;http://wxdata.weather.com/wxdata/weather/local/BUXX0005?cc=*&unit=m&dayf=1                 <- URL for Sofia, Bulgaria, metric units

#ce


Global $location,$loc_time,$sunrise,$sunset,$datetime,$loc,$temp,$feels,$current,$wicon,$bp
Global $bpd,$ws,$wg,$wd,$wt,$hmid,$vis,$uv,$uvt,$dewp,$micon,$mt
Global $code = "BUXX0005"   ;Sofia Bulgaria
$input = "sofia"

_GetWeather()

    $array = StringSplit($temp, " ")
    ;$temp = K2C($array[1])

    $array = StringSplit($feels, " ")
    ;$feels = K2C($array[1])

    $array = StringSplit($sunrise, " ")
    $sunrise = $array[1]
    $array = StringSplit($sunrise, ":")
    $sunrise = $array[1]
    $sunrise1 = $array[2]

    ;MsgBox(0,"sunset", $sunset)
    $array = StringSplit($sunset, " ")
    $sunset = $array[1]
    $array = StringSplit($sunset, ":")
    $sunset = $array[1]
    $sunset1 = $array[2]

    ; wind speed
    $ws = $ws * 1.6
    $array = StringSplit($ws, ".")
    $ws = $array[1]
    ;$ws1 = $array[2]



;ConsoleWrite("Temperature now "&$temp& " C " & @CRLF _
;& " Weather now "& $current &  @CRLF &"  wind speed " & K2C($ws) _
;& "km/h." & @CRLF & "    Humidity " &$hmid &  " %" & @CRLF & "     bar. pressure " & $bp & " hP" & @CRLF)

; convert Kelvins to Celsius
Func K2C(ByRef $temp)
    $temp = ($temp - 32) * (5/9) ;converting to Celsius
    $temp = Round($temp, 2) ;round float point up to 2 -nd sign
    ;MsgBox(0, "K2C", $temp)
    Return $temp
EndFunc

;Message Box with data
Func Showy()
    MsgBox(0,"location ", $location)
    ConsoleWrite("location "& $location & @CRLF)
    MsgBox(0,"loc_time ", $loc_time)
    ConsoleWrite("loc_time "& $loc_time & @CRLF)
    MsgBox(0,"sunrise ", $sunrise &"."&  $sunrise1)
    ConsoleWrite("sunrise "& $sunrise &"."&  $sunrise1  & @CRLF)
    MsgBox(0,"sunset ", $sunset &"."&  $sunset1)
    ConsoleWrite("sunset "& $sunset &"."&  $sunset1 & @CRLF)
    MsgBox(0,"datetime ", $datetime)
    ConsoleWrite("datetime "& $datetime & @CRLF)
    MsgBox(0,"temp ", $temp & " C")
    ConsoleWrite("temp "& $temp & " C"  & @CRLF)
    MsgBox(0,"feels ", $feels & "C")
    ConsoleWrite("feels "& $feels & "C" & @CRLF)
    MsgBox(0,"current ", $current)
    ConsoleWrite("current " & $current  & @CRLF)
    MsgBox(0,"barometric pressure ", $bp & "hP")
    ConsoleWrite("barometric pressure "&  $bp   & "hP" & @CRLF)
    MsgBox(0,"bpd ", $bpd)
    ConsoleWrite("bpd " & $bpd  & @CRLF)
    MsgBox(0,"wind speed ", $ws)
    ConsoleWrite("wind speed " & $ws    & @CRLF)
    MsgBox(0,"wd wt ", $wd & " " & $wt& " km/h")
    ConsoleWrite("wd wt " & $wd & " " & $wt & " km/h"   & @CRLF)
    MsgBox(0,"humidity ", $hmid & "%")
    ConsoleWrite("humidity "    & $hmid & "%" & @CRLF)
    MsgBox(0,"visibility ", $vis & " km")
    ConsoleWrite("visibility " & $vis & " km " & @CRLF)
    MsgBox(0,"UV index", $uv & " (" & $uvt & ")")
    ConsoleWrite("UV index "  & $uv & " (" & $uvt & ")" & @CRLF)
    MsgBox(0,"dewp", $dewp)
    ConsoleWrite("dewp " & $dewp  & @CRLF)
    MsgBox(0,"mt", $mt)
    ConsoleWrite("mt " & $mt  & @CRLF)
EndFunc


Func _GetWeather()
$oXml = ObjCreate("Msxml2.DOMDocument.3.0")
$oXml.async=0
$oXml.Load("http://wxdata.weather.com/wxdata/weather/local/BUXX0005?cc=*&unit=m&dayf=1")
$oXmlroot = $oXml.documentElement
For $oXmlnode In $oXmlroot.childnodes
    For $oXmlnode2 In $oXmlnode.attributes
        If $oXmlnode2.name = "id" Then $code = $oXmlnode2.value
    Next
Next
If $code = "NoCode" Then
    Msgbox(0, "Error", "Location Not Found" & "Click OK To Continue")
Else



$oXml.Load("http://wxdata.weather.com/wxdata/weather/local/" & $code & "?cc=*&unit=m&dayf=1")
$oXmlroot = $oXml.documentElement
For $oXmlNode In $oXmlroot.childNodes
    Select
    Case $oXmlnode.nodename = "loc"
        For $oXmlnode2  in $oXmlnode.Childnodes
            Select
            Case $oXmlnode2.nodename = "dnam"
                $location = $oXmlnode2.text
            Case $oXmlnode2.nodename = "tm"
                $loc_time = $oXmlnode2.text
            Case $oXmlnode2.nodename = "sunr"
                $sunrise = $oxmlnode2.text  ; sunrise
                ;ConsoleWrite($sunrise & @CRLF)
            Case $oXmlnode2.nodename = "suns"
                $sunset = $oxmlnode2.text   ; sunset
                ;ConsoleWrite($sunset & @CRLF)
            EndSelect
        Next
    Case $oXmlnode.nodename = "dayf"
        For $oXmlnode2  in $oXmlnode.Childnodes
            Select
            Case $oXmlnode2.nodename = "hi"
                $hi = $oXmlnode2.text
            Case $oXmlnode2.nodename = "low"
                $low = $oXmlnode2.text

            EndSelect
        Next
    Case $oxmlnode.nodename = "cc"
        For $oxmlnode2 In $oxmlnode.childnodes
            Select
            Case $oxmlnode2.nodename = "lsup"   ;<lsup>7/28/17 7:00 AM EEST</lsup>
                $datetime = $oxmlnode2.text
            Case $oxmlnode2.nodename = "obst"
                $loc = $oxmlnode2.text
            Case $oxmlnode2.nodename = "tmp"
                $temp = $oxmlnode2.text
            Case $oxmlnode2.nodename = "flik"
                $feels = $oxmlnode2.text
            Case $oxmlnode2.nodename = "t"
                $current = $oxmlnode2.text
            Case $oxmlnode2.nodename = "icon"
                $wicon = $oxmlnode2.text
            Case $oxmlnode2.nodename = "bar"
                For $oxmlnode3 in $oxmlnode2.childnodes
                Select
                Case $oxmlnode3.nodename = "r"
                    $bp = $oxmlnode3.text
                Case $oxmlnode3.nodename = "d"
                    $bpd = $oxmlnode3.text
                EndSelect
                Next
            Case $oxmlnode2.nodename = "wind"
                For $oxmlnode3 in $oxmlnode2.childnodes
                    Select
                    Case $oxmlnode3.nodename = "s"
                        $ws = $oxmlnode3.text  ;windspeed miles
                    Case $oxmlnode3.nodename = "gust"
                        $wg = $oxmlnode3.text
                    Case $oxmlnode3.nodename = "d"
                        $wd = $oxmlnode3.text
                    Case $oxmlnode3.nodename = "t"
                        $wt = $oxmlnode3.text
                    EndSelect
                Next
            Case $oxmlnode2.nodename = "hmid"
                $hmid = $oxmlnode2.text ;humidity
            Case $oxmlnode2.nodename = "vis"
                $vis = $oxmlnode2.text  ;visibility
            Case $oxmlnode2.nodename = "uv"
                For $oxmlnode3 in $oxmlnode2.childnodes; ULTRAVIOLET INDEX
                    Select
                    Case $oxmlnode3.nodename = "i"
                        $uv = $oxmlnode3.text
                    Case $oxmlnode3.nodename = "t"
                        $uvt = $oxmlnode3.text
                    EndSelect
                Next
            Case $oxmlnode2.nodename = "dewp"
                $dewp = $oxmlnode2.text
            Case $oxmlnode2.nodename = "moon"
                For $oxmlnode3 in $oxmlnode2.childnodes
                    Select
                    Case $oxmlnode3.nodename = "icon"
                        $micon = $oxmlnode3.text
                    Case $oxmlnode3.nodename = "t"
                        $mt = $oxmlnode3.text
                    EndSelect
                Next
            EndSelect
        Next
    EndSelect
Next
$oXml = ""
EndIf
EndFunc

Showy()

attached weather.au3 and sample XML

BUXX0005.xml

Weather.au3

1 person likes this

I have nothing to be proud: I am Bulgarian :~But there is no better place than 127.0.0.1Tutorial for newbies

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now