Kodi Community Forum
Release OzWeather - Australian Weather Addon using BOM data inc. animated radar support - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: Add-on Support (https://forum.kodi.tv/forumdisplay.php?fid=27)
+---- Forum: Weather Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=155)
+---- Thread: Release OzWeather - Australian Weather Addon using BOM data inc. animated radar support (/showthread.php?tid=116905)



- bossanova808 - 2012-02-27

Hi Scott - the problem with that is tying it to the user's location - it's no good to me if it is just capital cities, I really need a Weatherzone source for it and I couldn't find one. Otherwise how do I deal with Yackandanda's UV, for example?

Basically, I need a BOM ID of some sort, or a weahterzone one, or it gets pretty hard....

Also, please supply postcodes with issues as I want to look at that a bit more and can't find any...


New code - scotia - 2012-02-27

Bossa,

I was searching 3122. 3000 was also failing however. The search page in my browser had (http://www.) at the front, which was not matching your script.

Here is the new function. Changed lines are commented out with '#' with the new one below. I also added a line.

I'd rather the responseurl check for both a url WITH www. and with out it. I'm too lazy to google python regex!

Regards
Scott

Code:
##############################################
### NOW ACTUALLTY RUN THIS PUPPY - this is main() in the old language...

socket.setdefaulttimeout(100)

#the being called from the settings section where the user enters their postcodes
if sys.argv[1].startswith('Location'):
    keyboard = xbmc.Keyboard('', 'Enter your 4 digit postcode e.g. 3000', False)
    keyboard.doModal()
    if (keyboard.isConfirmed() and keyboard.getText() != ''):
        text = keyboard.getText()

        #need to submit the postcode to the weatherzone search
#        searchURL = 'http://weatherzone.com.au/search/'
        searchURL = 'http://www.weatherzone.com.au/search/'
        user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
        host = 'www.weatherzone.com.au'
        headers = { 'User-Agent' : user_agent, 'Host' : host }
        values = {'q' : text, 't' : '3' }
        data = urllib.urlencode(values)
        req = urllib2.Request(searchURL, data, headers)
        response = urllib2.urlopen(req)
        resultPage = str(response.read())
        #was there only one match?  If so it returns the page for that match so we need to check the URL
        responseurl = response.geturl()
#        if responseurl != 'http://weatherzone.com.au/search/':
        if responseurl != 'http://www.weatherzone.com.au/search/':  
            #we were redirected to an actual result page
            locationName = common.parseDOM(resultPage, "h1", attrs = { "class": "unenclosed" })
            locationName = str.split(locationName[0], ' Weather')
            locations = [locationName[0] + ', ' + text]
            locationids = [responseurl]
        else:
            #we got back a page to choose a more specific location
# next line added
            middle = common.parseDOM(resultPage, "div", attrs = { "id": "structure_middle" })
#            skimmed = common.parseDOM(resultPage, "ul", attrs = { "class": "typ2" })
            skimmed = common.parseDOM(middle, "ul", attrs = { "class": "typ2" })
            #ok now get two lists - one of the friendly names
            #and a matchin one of the URLs to store
            locations = common.parseDOM(skimmed[0], "a")
            templocs = common.parseDOM(skimmed[0], "a", ret="href")
            #build the full urls
            locationids = []
            for count, loc in enumerate(templocs):
                locationids.append(WeatherZoneURL + loc)
            #if we did not get enough data back there are no locations with this postcode
#            if len(skimmed)<=1:
            if len(locations)<=1:
                locations = []
                locationids = []
                
### no changes past this point



- bossanova808 - 2012-02-27

What was in your browser isn't really relevant to be honest, it's what the result of the Python urlopen and it was coming back without the www hence the code.

But more importantly, both those codes work here on my Windows box, and 3000 at least definitely works on my linux box, so I can't see why they are failing for you...

What's your platform details?


- bossanova808 - 2012-02-27

(that said I am happy to make the changes as they don't appear to break anything, it's just odd and hard for me to test as they all work fine here anyway!)


- scotia - 2012-02-27

Ok, when I was debugging the script I got:

Code:
NOTICE: Oz Weather-0.3.5: Exception: OzWeather: got responseurl [http://www.weatherzone.com.au/search/]
(I added a line to print out the response url)

But my browser returns the www. as well.

What the site returns is really up to it. I am using a squid proxy may alter the request.

Also of some use:
Code:
[root]# curl -D /tmp/curl-headers "http://weatherzone.com.au/search"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://www.weatherzone.com.au/search">here</a>.</p>
</body></html>



- bossanova808 - 2012-02-27

Ok cool well I have changed it to use 'endswith' so basically anything with weatherzone.com.au/search/ on it will work Smile

I wonder if the proxy is the root cause though, bceause I can't trigger the error. But your way seems safer anyway (going to the div first, then down to the typ2 marker) - so I've whacked it in and will push a new version soon.

Thanks for your help!


- scotia - 2012-02-27

My pleasure. Thanks for a great plugin.

It'd be interesting to tell that other guy with the postcode problem to try the new code to see if it fixes it.

Scott


- bossanova808 - 2012-02-27

OK pushed it out....leaving here soon, so wanted to tidy up before I go but it seems to be working fine.


OZWeather Error - Jolly181 - 2012-03-11

Hi All..

I am new to XBMC and I have been trying (IN VAIN) to get this add-on to work correctly for me..

I followed bossanova808's instructions and installed from the downloaded zip file.
I was able to add new locations (PARRAMATTA, PENRITH and SYDNEY) and even enabled IDR714 (Terry Hills at 64KM).

But when I go to display the Weather from the main screen, I continually get a script error. i.e "SCRIPT FAILED WEATHER.OZWEATHER"

I have uninstalled and reinstalled this add-on multiple times, looked thru the forum for possible fixes Etc. but I cannot get it to work.??

WHAT AM I DOING WRONG... PLEASE HELP.!!

Regards

Sad Jolly Sad


- bossanova808 - 2012-03-11

Posting a log file would be a starting point...


- bossanova808 - 2012-03-11

and full details (postcodes, radar codes) of the locations you are using.


- Jolly181 - 2012-03-11

Sorry bout this.. BUT.. where do I find the logfiles.??

Post Codes:

Parramatta = 2150
Penrith = 2750
Sydney = 2000

Radar Code was IDR714

Regards

Jolly


- bossanova808 - 2012-03-11

http://lmgtfy.com/?q=xbmc+log+file


- bossanova808 - 2012-03-11

(FULL debug log file, please)


- Jolly181 - 2012-03-11

I found a logfile but not sure how I can get it attached here though.Huh

Regards

Jolly