Jump to content

Google Weather


nobbe
 Share

Recommended Posts

; uses 2 google APIs for retrieving weather information and an online chart generator

;

; getting weather information from google API

;

; http://www.google.com/ig/api?weather=Berlin

;

; also uses google chart api for some a little trend display

; http://chart.apis.google.com/chart?chs=200...g&chds=0,40

retrieves the data by use of the _xmldomwrapper (all of the needed source is included in the main)

google_weather.au3

Edited by nobbe
Link to comment
Share on other sites

I get an error in expression at this line:

$objNodeList = $obj.documentElement.selectNodes($path)

which URL did you use for the data ?

could you post the xml file? or check it in ie browser if its valid? or post the error`?

Edited by nobbe
Link to comment
Share on other sites

which URL did you use for the data ?

could you post the xml file? or check it in ie browser if its valid? or post the error`?

Sure.. Here is my error:

C:\Google Weather.au3 (192) : ==> Error in expression.:

$objNodeList = $obj.documentElement.selectNodes($path)

$objNodeList = ^ ERROR

->12:17:40 AutoIT3.exe ended.rc:1

>Exit code: 1 Time: 4.027

Here is the url I am using:

http://www.google.com/ig/api?weather=tulsa

Link to comment
Share on other sites

seems like it misinterprets something ( tulsa works for me)

i update first post, maybe it helps? (comes with all the codes i used for it and compiled version)

which autoit version do you use?

Edited by nobbe
Link to comment
Share on other sites

I'm getting the same error

Line 194

$objNodeList = $obj.documentElement.selectNodes($path)

$objNodeList = ^ ERROR

Error: Error in expression.

That's using the code you provided (Berlin)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

can you check the xml file if it gets loaded correctly in ie browser - when it displays an error when loading the xml file its malformed XML for some reason.??

please try the updated first post source now . it Could be?? the $obj returned from

$obj = _XMLFileOpen($infile)

doesnt stay the same as the

$objDoc used in the _xml_domwrapper?

so i include now all code from _domwrapper in the regular code

Edited by nobbe
Link to comment
Share on other sites

Now it works for me. The XML DOM wrapper code that I was using returned success/failure from the file open call whereas your version is obviously expecting an object. Might be worth pointing to the right version of the include file if you want to go back to using it.

WBD

Link to comment
Share on other sites

Much better. It still has a couple of issues.

1 - Remove the GUI positioning or set it relative to desktop size. When it opens most of the GUI is below the bottom of my desktop

2 - it worked fine for Tulsa but for my locale, the image is not there for current conditions.

3 - You shouldn't automatically be changing to Centigrade. Most American users won't appreciate that. The °F and °C are both returned in the xml page (at least for me) as temp_f data and temp_c data.

The xml is not mal-formed

I'm playing with some work-arounds to using the DOM wrapper.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

code update , so i assume the obj code are returned incorrectly from _domwrapper.udf for some reason?

- now sets pos to upper left screen pos

- celsius & fahrenheit by using

Global $b_use_celsius = 1 ; 1 for celsius or 0 for farenheit

Link to comment
Share on other sites

Again, you have improved it. However it still misses the icon for My locale and it is in the XML under cirrent conditions.

<icon data="/images/weather/sunny.gif"/>

I'm wondering if part of this may not be associated with Google regionalization.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Again, you have improved it. However it still misses the icon for My locale and it is in the XML under cirrent conditions.

I'm wondering if part of this may not be associated with Google regionalization.

i dont know .. unfortunately i couldnt find much information about the google apis

also i get different results when i use IE browser to retrieve the data (here i already get the german data localized)

when is use inetget() i get englisch data

Link to comment
Share on other sites

i dont know .. unfortunately i couldnt find much information about the google apis

also i get different results when i use IE browser to retrieve the data (here i already get the german data localized)

when is use inetget() i get englisch data

Nice idea for script!

I also get english texts by InetGet.

I tried to make workaround by 

;~   InetGet($url, @ScriptDir & "\weather.xml", 1, 0); vrati anglickou verzi popisku
 $oIE = _IECreate ($url, 0, 0)
 $sText = _IEBodyReadText ($oIE)
 $sText = StringReplace($sText, '- <', '  <')
 $sText = StringReplace($sText, @CRLF & ' ', '')
 $sText = StringReplace($sText, '> <', '><')
 $sText = StringReplace($sText, '>  <', '><')
 $sText = StringStripWS($sText,1+2)
 FileDelete(@ScriptDir & "\weather.xml")
 FileWrite(@ScriptDir & "\weather.xml", $sText)

but it's not working well. XML parsing show errors.

Link to comment
Share on other sites

i dont know .. unfortunately i couldnt find much information about the google apis

also i get different results when i use IE browser to retrieve the data (here i already get the german data localized)

when is use inetget() i get englisch data

Well, I'm still playing with a work-around to the DOM wrapper using StringRegExp. I dropped the InetGet() in favor of _InetGetSource() which also returns the English version. Then To make it simpler to parse I used a StringReplace in it.

$sData = StringRegExp(StringReplace(_InetGetSource($sUrl), "><",">" & @CRLF & "<"), "(?i)(?s)(<weather.*weather>)", 1)
If NOT @Error Then
   $sData = $sData[0]
Else

EndIf
ClipPut($sData);; For testing only

From there I can call various functions to return the values that you need. I'm still curious why the image is missing for me on local conditions using your code. I don't see anything obviously wrong.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I also made the following change in your code for setting the Window Title

;WinSetTitle($GUI, "", "google weather for " & $town);

    $url = "http://www.google.com/ig/api?weather=" & $town;& "&hl=de";
    $url = _URLEncode($url)
    ConsoleWrite($url & @CRLF);

   ; save into TEMP file first to check the XML data by hand
   ;InetGet("http://www.google.com/ig/api?weather=Berlin" & '\&' & "hl=de", @ScriptDir & "\weather.xml", 1, 0)

    InetGet($url, @ScriptDir & "\weather.xml", 1, 0)

   ;$result = _INetGetSource($url)
   ;ConsoleWrite($result);

   ; now xml file in local drive @scriptdir

    $objDoc = _XMLFileOpen($infile)
    
    $town = _XMLGetAttrib("//xml_api_reply/weather/forecast_information/city", "data");
    WinSetTitle($GUI, "", "Google Weather for " & $town);

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

i found different url for the localized feeds (now inetget works fine with my towns and language)

Feed Url's

UK English: http://www.google.co.uk/ig/api?weather=

US English: http://www.google.com/ig/api?weather=

Norwegian: http://www.google.no/ig/api?weather=

Japanese: http://www.google.co.jp/ig/api?weather=

Russian: http://www.google.ru/ig/api?weather=

French: http://www.google.fr/ig/api?weather=

German: http://www.google.de/ig/api?weather=

Link to comment
Share on other sites

http://www.google.cz/ig/api?weather=Brno

But there are some problems:

- XML must be converted from OEM to ANSI code page

- _XMLFileOpen() show error: An invalid character was found in text content.

Here is Oem2Ansi()

Func Oem2Ansi($text)
 $text = DllCall('user32.dll','Int','OemToChar','str',$text,'str','')
 Return $text[2]
EndFunc

Here is my XML czech content:

<?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" ><forecast_information><city data="Brno"/><postal_code data="Brno"/><latitude_e6 data=""/><longitude_e6 data=""/><forecast_date data="2009-04-09"/><current_date_time data="2009-04-09 13:17:07 +0000"/><unit_system data="SI"/></forecast_information><current_conditions><condition data="Jasno"/><temp_f data="79"/><temp_c data="26"/><humidity data="Vlhkost: 29%"/><icon data="/images/weather/sunny.gif"/><wind_condition data="Vítr: S s rychlostí 2 km/h"/></current_conditions><forecast_conditions><day_of_week data="čt"/><low data="9"/><high data="22"/><icon data="/images/weather/mostly_sunny.gif"/><condition data="Skoro jasno"/></forecast_conditions><forecast_conditions><day_of_week data="pá"/><low data="7"/><high data="23"/><icon data="/images/weather/chance_of_rain.gif"/><condition data="Možnost deště"/></forecast_conditions><forecast_conditions><day_of_week data="so"/><low data="6"/><high data="22"/><icon data="/images/weather/sunny.gif"/><condition data="Jasno"/></forecast_conditions><forecast_conditions><day_of_week data="ne"/><low data="7"/><high data="22"/><icon data="/images/weather/sunny.gif"/><condition data="Jasno"/></forecast_conditions></weather></xml_api_reply>

I think I must encode czech letters somehow to be able use _XML parsing. Edited by Zedna
Link to comment
Share on other sites

- _XMLFileOpen() show error: An invalid character was found in text content.

I think I must encode czech letters somehow to be able use _XML parsing.

i suspect the ms xml parser is rather picky ..

the same happens to me here when i use the .com server with "&hl=de"

; http://www.google.com/ig/api?weather=Berlin&hl=de -> this is buggy here??

its shows the same error

"An invalid character was found in text content"

; http://www.google.com/ig/api?weather=Berlin -> this works??

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...