You are not logged in.
Pages: 1
Here is an adesklet that watches the Arch forum. In the config file, you can supply keywords that will be used to watch the forum topics. Once the desklet is running, click the desired message to start your browser. As it stands right now, the desklet refreshes every 5 minutes. I should put that in the config file.
Typical config file look like so:
# -*- coding: ASCII -*-
id0 = {'body_color': (176, 196, 222, 255),
'browser': '/usr/bin/firefox',
'h': 200,
'message_keyword': ['kernel', 'browser', 'backup', 'server'],
'show_author': True,
'show_when': False,
'text_color': (0, 0, 125, 255),
'title_color': (0, 0, 255, 255),
'w': 450,
'x': 0,
'y': 20}
Get the source code here:
http://git.mariostg.com/?p=afc/.git;a=summary
Offline
I am posting the code down here hoping it is going to stimulate more interest...
#!/usr/bin/python
"""
afc.py - Mario St-Gelais <mario.stg@sympatico.ca>, 2009
Display recent forum message titles in a small window on the desktop.
To try it:
- Just run it straight out of the box. Recent message having a title
that contains a selected keyword will be displayed. Click the item
to open the forum at the selected message.
Customize it:
Set message_keyword parameters to display message title containing desired keywords.
Set show_author to True to display message author.
Set show_when to True to display message time stamp.
Set w to change desklet width.
Set h to change desklet height.
Set browser to your browser path.
"""
import adesklets
import re
import urllib2
from os.path import join, dirname
from os import system
class Config(adesklets.ConfigFile):
cfg_default = {
'body_color':(176, 196, 222, 255),
'text_color':(0, 0, 125, 255),
'title_color':(0, 0, 255, 255),
'browser':'/usr/bin/firefox',
'show_author':True,
'show_when':False,
'x':0,
'y':20,
'w':450,
'h':200,
'message_keyword':['kernel','browser','backup','server']
}
def __init__(self,id,filename):
adesklets.ConfigFile.__init__(self,id,filename)
class My_Events(adesklets.Events_handler):
def __init__(self,basedir):
if len(basedir)==0:
self.basedir='.'
else:
self.basedir=basedir
self.w = None
self.buffer= None
self.id= None
self.delay=None
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.buffer=adesklets.create_image(self.config['w'],self.config['h'])
adesklets.window_resize(self.config['w'],self.config['h'])
adesklets.window_set_transparency(True)
adesklets.image_fill_rectangle(self.config['x'],
self.config['y'],
self.config['w'],
self.config['h'])
adesklets.context_set_color(*self.config['title_color'])
adesklets.context_set_font(adesklets.load_font('VeraBd/12'))
adesklets.text_draw(0,0,'Arch Forum Checker')
adesklets.free_font(0)
adesklets.window_show()
def _display(self):
self.link_id=[]
adesklets.context_set_color(*self.config['body_color'])
adesklets.image_fill_rectangle(self.config['x'],
self.config['y'],
self.config['w'],
self.config['h'])
adesklets.context_set_color(*self.config['text_color'])
adesklets.context_set_font(adesklets.load_font('Vera/10'))
self.clean_list=self.check_forum()
dy=self.config['y']+5
if len(self.clean_list)>1:
for item in self.clean_list:
line_text=item[1]
if self.config['show_author']==True:
line_text=line_text+' (%s)' % item[4]
if self.config['show_when']==True:
line_text=line_text+' (%s)' % item[3]
adesklets.text_draw(0,dy,line_text)
dy+=15
else:
adesklets.text_draw(0,dy,'No article at this time')
self.ymax=dy
def quit(self):
print 'Quitting...'
def alarm(self):
self.block()
self._display()
self.unblock()
return 300
def button_press(self,delayed,x,y,button):
ymin=self.config['y']+5
url='http://bbs.archlinux.org/viewtopic.php?pid='
if y>=ymin and y<=self.ymax:
item_index=(y-ymin)/15
system('%s %s%s' % (self.config['browser'], url,
self.clean_list[item_index][2]))
def check_forum(self):
thread_id=[]
subject=[]
message_id=[]
timestamp=[]
user=[]
clean_list=[]
try:
f = urllib2.urlopen("http://bbs.archlinux.org/search.php?action=show_24h")
output = f.read()
#print output
f.close()
thread_subject_pattern='<div class="tclcon">\s*.*<a\shref="viewtopic.php\?id=(\d+)">(.*)</a> <span '
for thread_subject in re.findall(thread_subject_pattern, output):
thread_id.append(thread_subject[0])
subject.append(thread_subject[1])
msg_author_pattern='<td\sclass="tcr"><a\shref="viewtopic.php\?pid=(.*)">(.*)</a>\sby (.*)</td>'
for msg_author_line in re.findall(msg_author_pattern,output):
message_id.append(msg_author_line[0])
timestamp.append(msg_author_line[1])
user.append(msg_author_line[2])
msg_list=zip(thread_id, subject, message_id, timestamp, user)
for mk in self.config['message_keyword']:
for ml in msg_list:
if mk in ml[1].lower():
clean_list.append(ml)
del msg_list[msg_list.index(ml)]
if len(clean_list)==0:
clean_list=[]
return clean_list
except Exception,error:
print "FAILED"
My_Events(dirname(__file__)).pause()
Offline
Pages: 1