views:

22

answers:

1

I'm trying to load a weather plugin for a website I'm working on. The weather plugin is a separate weather.py file located at /var/www/piss/plugins/base/weather.py. In the PSP it seems to import correctly, but I am unable to access any variables or objects from the weather.py plugin in the PSP. Here's the code I have:

    ...HTML and CSS stuff...

<% 
sys.path.append('/var/www/piss/plugins/base/')
pwd = os.getcwd()
import sys, os
import string
from weather import weather
%>
            <%= pwd %>
            <%= html1 %>
            <%= currentWeather %>
            </div>
        </div>
        <div id="footer">Piss + INK Version                     0.00001</div>
        <div id="bottom"></div>
    </div>
</body>
</html>

Here's the weather.py code:

from basePlugin import plugin
import MySQLdb
import pywapi

class weather(plugin):
    """
    weather.py
    Built-in weather plugin.
    """
    def __init__(self,zipcode):
        self.zipcode = zipcode

#Tested without DB access
    #db=_mysql.connect(host="localhost",user="things",passwd="things",db="things")
    #zip="SELECT zipcode FROM "+currentUser+"\;"
    #c = db.cursor()
    #dbResult = c.execute (zip)
    wResult=pywapi.get_weather_from_google('05401')
    html1="""
<div class="weather">
Weather:<br />
"""
    print html1
    currently = wResult['current_conditions']
    currentWeather = currently['condition']
    print currentWeather
    print "<br />"

    if currentWeather == "Mostly Cloudy":
        print '<img src="themes/default/images/weather/cloudy.png" alt="cloudy">'

    if currentWeather == "Cloudy":
        print '<img src="themes/default/images/weather/cloudy.png" alt="cloudy">'

    if currentWeather == "Sunny":
        print '<img src="themes/default/images/weather/sunny.png" alt="sunny">'

    if currentWeather == "Showers":
        print '<img src="themes/default/images/weather/rain.png" alt="rain">'

#More conditions will be added in actual plugin.

print "</div>"
A: 

PSP isn't particularly popular in the Python world, and for good reason. Pretty much any other templating system is a better choice. It's been a very long time since I looked at PSP, and I may be misremembering how it works, but I'm not sure you expect PSP to know that pwd, html1 and currentWeather come from the weather class you imported from the weather module. I'm also not sure the print statements in the class are doing what you think they're doing, considering they're in the class body, not a method.

All in all I would suggest you pick a saner templating system. Django's templates, Mako, Jinja, anything but PSP.

Thomas Wouters
Yes, I expected html1 and currentWeather to be available when the weather plugin is imported. The print statements were just for testing the module.
chris
The question is *why* you expect that. How is PSP to know you mean for `currentWeather` and `html1` to be taken from attributes of the `weather` class from the `weather` module?
Thomas Wouters