C
CoolGenie
Hi!
I'm trying to write a small adesklet that will read newsfeeds. Here's
the code:
#
#####################################################################
# fparser.py
#
# P. Kaminski <[email protected]>
# Time-stamp: <>
######################################################################
import feedparser
import adesklets
from os import getenv, spawnlp, P_NOWAIT
from os.path import join, dirname
class Config(adesklets.ConfigFile):
cfg_default = { 'feedsrc' : 'http://slashdot.org/index.rss',
'numfeeds' : 5,
'numlines' : 4
}
def __init__(self, id, filename):
adesklets.ConfigFile.__init__(self, id, filename)
class Events(adesklets.Events_handler):
def __init__(self, basedir):
if len(basedir)==0:
self.basedir='.'
else:
self.basedir=basedir
adesklets.Events_handler.__init__(self)
def __del__(self):
adesklets.Events_handler.__del__(self)
def ready(self):
self.config = Config(adesklets.get_id(),
join(self.basedir, 'config.txt'))
self.feed = self.config['feedsrc']
self.numfeeds = self.config['numfeeds']
self.numlines = self.config['numlines']
self.w = 520
self.h = 12*self.numfeeds*(self.numlines+1)
adesklets.window_resize(self.w, self.h)
adesklets.window_reset(adesklets.WINDOW_UNMANAGED)
adesklets.window_set_transparency(True)
adesklets.window_show()
def quit(self):
print 'Quitting...'
def alarm(self):
print 'Alarm. Next in 360 seconds.'
self._display()
return 360
def _display(self):
print "Getting feed..."
y = 0
x = 0
d = feedparser.parse(self.feed)
print d.channel.title
print d.channel.description
# clear the buffer
buffer = adesklets.create_image(self.w, self.h)
adesklets.context_set_image(buffer)
adesklets.context_set_blend(False)
adesklets.context_set_color(0,0,0,0)
adesklets.image_fill_rectangle(0,0,self.w,self.h)
adesklets.context_set_blend(True)
adesklets.context_set_font(adesklets.load_font('Vera/7'))
adesklets.context_set_color(255, 0, 0, 255)
adesklets.text_draw(0, y, str(d.channel.title))
y+=12
l = len(d.entries)
l = min(l, self.numfeeds)
for i in range(l):
ent=d.entries
adesklets.context_set_color(255, 255, 0, 255)
adesklets.text_draw(0, y, str(ent.title))
print ent.title
y+=12
adesklets.context_set_color(255, 255, 255, 255)
for k in range(0, min(len(ent.summary)/100,
self.numlines)):
print str(ent.summary)[k*100k+1)*100]
adesklets.text_draw(0, y, str(ent.summary)[k*100k
+1)*100])
y+=12
adesklets.free_font(0)
adesklets.free_image(buffer)
Events(dirname(__file__)).pause()
Unfortunately, I'm getting this bug for some time now and I just don't
know what's going on:
File "./fparser.py", line 40
self.w = 520
^
SyntaxError: invalid syntax
Regards,
P.K.
I'm trying to write a small adesklet that will read newsfeeds. Here's
the code:
#
#####################################################################
# fparser.py
#
# P. Kaminski <[email protected]>
# Time-stamp: <>
######################################################################
import feedparser
import adesklets
from os import getenv, spawnlp, P_NOWAIT
from os.path import join, dirname
class Config(adesklets.ConfigFile):
cfg_default = { 'feedsrc' : 'http://slashdot.org/index.rss',
'numfeeds' : 5,
'numlines' : 4
}
def __init__(self, id, filename):
adesklets.ConfigFile.__init__(self, id, filename)
class Events(adesklets.Events_handler):
def __init__(self, basedir):
if len(basedir)==0:
self.basedir='.'
else:
self.basedir=basedir
adesklets.Events_handler.__init__(self)
def __del__(self):
adesklets.Events_handler.__del__(self)
def ready(self):
self.config = Config(adesklets.get_id(),
join(self.basedir, 'config.txt'))
self.feed = self.config['feedsrc']
self.numfeeds = self.config['numfeeds']
self.numlines = self.config['numlines']
self.w = 520
self.h = 12*self.numfeeds*(self.numlines+1)
adesklets.window_resize(self.w, self.h)
adesklets.window_reset(adesklets.WINDOW_UNMANAGED)
adesklets.window_set_transparency(True)
adesklets.window_show()
def quit(self):
print 'Quitting...'
def alarm(self):
print 'Alarm. Next in 360 seconds.'
self._display()
return 360
def _display(self):
print "Getting feed..."
y = 0
x = 0
d = feedparser.parse(self.feed)
print d.channel.title
print d.channel.description
# clear the buffer
buffer = adesklets.create_image(self.w, self.h)
adesklets.context_set_image(buffer)
adesklets.context_set_blend(False)
adesklets.context_set_color(0,0,0,0)
adesklets.image_fill_rectangle(0,0,self.w,self.h)
adesklets.context_set_blend(True)
adesklets.context_set_font(adesklets.load_font('Vera/7'))
adesklets.context_set_color(255, 0, 0, 255)
adesklets.text_draw(0, y, str(d.channel.title))
y+=12
l = len(d.entries)
l = min(l, self.numfeeds)
for i in range(l):
ent=d.entries
adesklets.context_set_color(255, 255, 0, 255)
adesklets.text_draw(0, y, str(ent.title))
print ent.title
y+=12
adesklets.context_set_color(255, 255, 255, 255)
for k in range(0, min(len(ent.summary)/100,
self.numlines)):
print str(ent.summary)[k*100k+1)*100]
adesklets.text_draw(0, y, str(ent.summary)[k*100k
+1)*100])
y+=12
adesklets.free_font(0)
adesklets.free_image(buffer)
Events(dirname(__file__)).pause()
Unfortunately, I'm getting this bug for some time now and I just don't
know what's going on:
File "./fparser.py", line 40
self.w = 520
^
SyntaxError: invalid syntax
Regards,
P.K.