Weather Underground

Discussion of plugin / script development for XBMC4Xbox
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Weather Underground

Post by byron »

I thought I would lay this out in a manner in which someone with better knowledge of python than myself could easily see what's going on, why this is failing, and then help fix/guide me a step at a time perhaps...this is based off of the most up to date "frodo" release of weather underground and using xbmc4xbox r32598

Wunderground (for browsing)

Wunderground (for download)

Why it isn't working OTB (error report)

If we got it to work, there would still be the problem of .po (language files) but I don't think that would be too difficult for me to remedy...also it seems to take a fair amount of ram on initiation.
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

It kinda tells you what the problem is and if you look at some other examples, you can see xbmcaddon.Addon() requires one more parameter (the __init__ part is coming from xbmcaddon module initilization, self is the first one, id is the second, see link below):

Code: Select all

11:54:27 M: 24166400   ERROR: Traceback (most recent call last):
                                              File "Q:\plugins\weather\weather.wunderground\default.py", line 28, in <module>
                                                __addon__      = xbmcaddon.Addon()
                                            TypeError: __init__() takes exactly 2 arguments (1 given)
Also see these:
https://svn.exotica.org.uk:8443/xbmc4xb ... mcaddon.py
https://addons4xbox.googlecode.com/svn/trunk/

Try changing line 28 in default.py to (got the id from addon.xml):

Code: Select all

__addon__      = xbmcaddon.Addon(id="weather.wunderground")
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

Hey thanks for the quick response...so after doing that it now leads to this (btw I did know how to do that but wanted to start from absolute scratch as far as fixing this so that it might be done correctly):

Code: Select all

13:36:09 M: 23822336    INFO: -->Python script returned the following error<--
13:36:09 M: 23851008   ERROR: Error Type: <type 'exceptions.KeyError'>
13:36:09 M: 23851008   ERROR: Error Contents: ('version',)
13:36:09 M: 23846912   ERROR: Traceback (most recent call last):
                                              File "Q:\plugins\weather\weather.wunderground\default.py", line 46, in <module>
                                                XBMC_PYTHON      = xbmcaddon.Addon(id='xbmc.python').getAddonInfo('version')
                                              File "Q:\scripts\.modules\script.module.xbmcaddon\lib\xbmcaddon.py", line 164, in getAddonInfo
                                                return self._info[ id.lower() ]
                                            KeyError: ('version',)
13:36:09 M: 23826432    INFO: -->End of Python script error report<--
13:36:09 M: 23846912    INFO: Python script stopped
So then I looked at the first link you posted, not sure how to implement this (if it's even what's necessary):

Code: Select all

self._info[ "id" ] = item.getAttribute( "id" )
            if self._info[ "id" ] != id:
                return None
            self._info[ "name" ] = item.getAttribute( "name" )
            self._info[ "version" ] = item.getAttribute( "version" )
            self._info[ "author" ] = item.getAttribute( "provider-name" )
            for extension in dom.getElementsByTagName( "extension" ):
I'm guessing it has something to do with that chunk of code for the next step...
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

If you could run that with XBMC4Xbox 3.3 in debug mode, we'll get more info on locations from xbmc.log - cause if you look at __init__ it will call _set_addon_info() to do exactly that, find the location of the addon, find it's addon.xml and parse it to populate the values, then when you call getAddonInfo() to return it back.
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

Here ya go:

http://www.xbmclogs.com/show.php?id=97864

But that's the problem I was running into...the time issue (which is why I started trying this on the latest nightly hoping for some python difference that might help). So now we are where I was totally stuck :(
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

Yeah ok, didn't know what build you were running since what you uploaded first it was truncated, and you didn't get the good stuff in the long since it wasn't getting there, then you didn't posted a new log. What I'm trying to say :-) excerpts are fine here, but if you could please post a full log at xbmclogs.com as well that would be useful.

Re time error there, yes, older 2.4 Python doesn't have ternary operator, so you probably need to change:

Code: Select all

hour = ('12' if (hour == 0) else '%02d' % (hour))
into

Code: Select all

if (hour == 0) :
  hour = '12'
else:
  hour = '%02d' % (hour))
or this might work if you want to get fancy:

Code: Select all

hour = [ '%02d' % (hour), '12' ][ bool(hour == 0) ]
http://stackoverflow.com/a/10158775/308836

But at the same time, use whatever XBMC4Xbox build you want, the latest stable or nightly, it's fine, point is we need more info from xbmcaddons.py
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

Sorry, I posted what build I was using in OP and was just following suit to what you were doing thinking that you were understanding what I was posting (from the code snippets). At any rate, I'll post full debug logs and honestly I thought that was the issue ( ternary operator as you call it) but wasn't sure how to remedy it. What you're suggesting seems logical, but I get this error next...

http://www.xbmclogs.com/show.php?id=97879

this is what I have done in default py:
Untitled.png
btw, thanks for your interest here :D
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

No problem, it's easier when you know a few things, it will get easier for you too :-)

Right, so, the error in the log says:

Code: Select all

15:13:04 M: 35909632   ERROR: Error Type: exceptions.IndentationError
15:13:04 M: 35909632   ERROR: Error Contents: ('unindent does not match any outer indentation level', ('Q:\\plugins\\weather\\weather.wunderground\\default.py', 268, 9, '\t\t\telse:\n'))
Python is quite particular about the amount and consistency of indentation, because it uses it to define blocks (notice there's no end statement for else for example) - as a side note, line 270 has too much indentation which makes the line run under the else branch (that's a logical issue, not a syntax error).

Line 268 is the bigger problem (says in the log, line 268 char 9) and that's because while to you might look like it's correctly indented, the indentation might be a fix of spaces / tabs and different from the lines above it - use the "Show all characters" toolbar icon in Notepad++ (the reverse P, to the right of word-wrap) to see what's it made of (spaces are displayed as centered dot, while tabs are a right pointing arrow) and correct it. Same goes for the other lines you modified, make sure they are correctly indented, otherwise you will be getting this error quite a few times.

PS: If you do this a lot, I would recommend you this tool I wrote a while ago for Windows, it will allow you to refresh the log, look at it and upload from the same place, without a need for an additional tool. It uses an FTP connection, so you might need to increase the number of connections to allow for both your FTP client to change the scripts as well as this tool to connect and get the log - see this blog post below about a different issue, but it shows you how to get to the FileZilla server XML or how to use an old FileZilla Server console to connect and increase the number of allowed connections remotely.

https://code.google.com/p/dandar3-xbmc- ... loads/list
http://dandar3.blogspot.com/2010/03/xbm ... t-ftp.html
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

So the way I was tabbing was incorrect since whomever wrote the file used spaces...I never would have thought that mattered in a million attempts!

So here's the new code (screenshot makes more sense to me than code block here):
spacing.jpg
Here's the new debug log: http://xbmclogs.com/show.php?id=98492

obviously the same process will have to be done with sunset as well once you help me figure out this chunk of the code. Thanks for holding my hand through this :) I am starting to see some things more clearly after reading a couple of the links that you've provided.
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

No problem, I think it's an interesting exercise for yourself and maybe others.

Code: Select all

10:41:08 M: 35745792   ERROR: Error Type: exceptions.SyntaxError
10:41:08 M: 35745792   ERROR: Error Contents: ('invalid syntax', ('Q:\\plugins\\weather\\weather.wunderground\\default.py', 269, 39, "                hour = '%02d' % (hour))\n"))
10:41:08 M: 35725312   ERROR:   File "Q:\plugins\weather\weather.wunderground\default.py", line 269
                                                hour = '%02d' % (hour))
                                                                      ^
                                            SyntaxError: invalid syntax
Notice on line 269 and 275 as well, you've got one too many closing round brackets (notice the ^ character pointing at the problem)

PS: Btw, there are better tools for this - Eclipse with PyDev plugin shows you the syntax errors and indentation from right there when editing, but that's something I need to should you through a live session (e.g. TeamViewer).
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

yea, I was about to edit my post once I saw that :oops: I'll change lines 280-284 in the same manner and get back
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

Okay here we go: http://xbmclogs.com/show.php?id=98496

So this goes back to the problem where I was using r32598 (python must have accepted the ternary operator in that build because it never threw an error about it), how to get the info from xbmcaddon emulator module.

I read THIS, and from what sense I can make of it the key error comes from the fact that ".getAddonInfo" is not defined in xbmcaddon.py
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

Yeah, it's crashing on this cause we don't have an addon named "xbmc.python" to read it's addon.xml, so yes the dictionary lookup will fail later.

I would remove these lines from the original code:

Code: Select all

46. XBMC_PYTHON      = xbmcaddon.Addon(id='xbmc.python').getAddonInfo('version')

Code: Select all

625. elif XBMC_PYTHON == '1.0' or XBMC_PYTHON == '2.0' or XBMC_PYTHON == '2.0.0':
626.    clear()
627.    log('older versions of XBMC are not supported by the weather underground addon')
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

Nice, that got it running. I had to convert stings.po to strings.xml (it's really gonna suck doing that for all of the languages btw) in order for x4x to get the labels. After that, I went in to set up my location via weather settings:
location setup 1.jpg
and then when I click this button and enter the info for location:
location setup 2.jpg
Script fails: http://xbmclogs.com/show.php?id=98529

Here is a fresh view of default.py with the changes I've made so far (so the line numbers match up with the log) After looking at the log, I have absolutely no idea where to go from here...
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

Ok, very good, thanks for that. Now, up at the top, import urllib (either on it's own line or just add in the comma list), and then change line 91 to use urllib.quote() instead.

To change strings.po into strings.xml on Windows recursively, paste this code into a file next to default.py, I don't know call it fix or change.bat (PS: if you intend to run the command from a cmd.exe yourself, you need to change %% into a single %). If you're wondering where all that comes from, you can read all about it by running "for /?" in a command line yourself, but basically it recurses through and renames the files; double quotes are used cause some directories have spaces in their names, e.g. Chinese (Simple).

Code: Select all

fix.bat
~~~~
for /r %%i in (strings.po) do rename "%%i" "%%~ni.xml"
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

I have no idea how you knew that, just out of curiosity what made you suggest adding urllib?

urllib.quote() did not work
urllib.quote(loc) did (I'm assuming this is what you were suggesting anyway)

After importing urllib and changing that line xbmc opened up DialogSelect and I was able to choose my location at that point. However it led to this:

http://xbmclogs.com/show.php?id=98563

I tried changing line 93 to use urllib as well but it threw the same error...as far as the po vs. xml, it's not just a file extension rename that's necessary afaik. They're set up entirely different

Here's a po string:

Code: Select all

msgctxt "#32102"
msgid "Advanced options"
msgstr ""
and then xml (as I'm sure you're familiar with):

Code: Select all

<strings>
	<string id="32101">Location setup</string>
	<string id="32102">Advanced options</string>
etc...
Unless you know something that I don't, I didn't think x4x could parse the info in a po file properly (but if it can and it's that easy I'll certainly give it a go).
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

Right, I knew there two, urllib and urllib2 from previous experience - maybe you could have found it if you were going to Google for "urllib2.quote()+python+docs", I didn't think there was one... Yeah, I meant to change the name and keep parameters, sorry I left it out, seemed to easy not requiring an explanation. You always want to keep parameters, maybe in some cases having to add more although most of the time when they get enhanced they allow more optional parameters to allow to change the behavior for flexibility but without breaking old code.

For the last error:

Code: Select all

14:08:18 M: 34185216   ERROR: Traceback (most recent call last):
                                              File "Q:\plugins\weather\weather.wunderground\default.py", line 657, in ?
                                                forecast(location, locationid)
                                              File "Q:\plugins\weather\weather.wunderground\default.py", line 148, in forecast
                                                while (retry < 6) and (not xbmc.abortRequested):
                                            AttributeError: 'module' object has no attribute 'abortRequested'
I would remove " and (not xbmc.abortRequested)" from line 146, practically becoming:

Code: Select all

    while (retry < 6):
XBMC4Xbox doesn't have xbmc.abortRequested, that's a new feature to XBMC (didn't know about this until I searched for it)
http://wiki.xbmc.org/index.php?title=Ho ... g_services

Right, sorry I haven't looked at the contents and didn't keep up with all XBMC changes - time to teach you write proper programs like C# with Visual Studio Express (free btw) :-) I'm sure someone crafty could write a script to convert one into the other, but it's a lot easier with a higher level language. I don't have the time to maintain it, but I could get you started if you want.
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

Success...sort of :)
working.jpg
Having a couple more issues...http://xbmclogs.com/show.php?id=98602

Haven't really had a chance to play around with the plugin settings (not even sure if they all appear like they should honestly), but there should be a way to switch between f/c and not seeing that. As far as the debug log, sorry about all of the info from the addon (I turned on logging in the settings). I'm trying to wrap my head around this still, not really getting all of it though. Thanks mostly to you it's at least running and pulling info from wunderground through our platform. So...as far as the xbmcvfs error I'm pretty much clueless, as far as the map dir error it's attempting this:

Code: Select all

567      mapdir = xbmc.translatePath('special://profile/addon_data/%s/map' % __addonid__)
it's making the map folder (which is empty btw) in addon_data, but should the above line be an absolute path to the directory?

Code: Select all

567     mapdir = xbmc.translatePath('special://profile//UserData/addon_data/weather.wunderground/map' % __addonid__)
Dan Dar3 wrote:time to teach you write proper programs like C# with Visual Studio Express (free btw) :-) I'm sure someone crafty could write a script to convert one into the other, but it's a lot easier with a higher level language. I don't have the time to maintain it, but I could get you started if you want.
Baby steps man, lets see if we can't figure this out first and then I can worry about how to sort the strings ;)
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: Weather Underground

Post by Dan Dar3 »

Ok, we're missing xbmcvfs.listdir() - you'll need to edit the file below and add the block at the end (if it works I'll create a ticket to be added into the product):

Q:\scripts\.modules\script.module.xbmcvfs\lib\xbmcvfs.py

Code: Select all

def listdir ( path ):
    """ listdir(path) -- return a list containing the names of the entries in the directory given by path.
    """
    xbmc.log( "[xbmcvfs] listdir(%s)" % ( path ), xbmc.LOGDEBUG )
    return os.listdir(xbmc.translatePath( path ) )
No, I don't think it does - you see, those paths are "translated" and special://profile it basically translates into Q:\UserData, so just leave them as they are.
http://www.xbmc4xbox.org.uk/wiki/Special_protocol

What you might want to change in it is not adding UserData, but change "addon_data" into "plugin_data".

Code: Select all

567      mapdir = xbmc.translatePath('special://profile/plugin_data/%s/map' % __addonid__)
What "xxx %s yyyy" % ( "abc" ) means is that it will insert the values on the right inside of the string on the left where it finds the markers (%s = string type).
So for you really that means is, translated and replaced:

Code: Select all

Q:\UserData\plugin_data\weather.wunderground\map\
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: Weather Underground

Post by byron »

well...if you're not getting sick of looking through them yet, I'm not getting tired of posting them:

http://xbmclogs.com/show.php?id=98638

so does this mean that there's a value error in xbmcvfs.py or default.py? Also thanks for the clarification...basically %s is passing a value if I understand correctly then.

Btw, changing addon_data/plugin_data made no difference whatsoever that I could tell...
Post Reply