You are not logged in.
okay so basically i'm writting an RSS reader, and it opens links in firefox (or whatever) in new tabs, however it doesn't quite behave right if there isn't already an instance of firefox running (opens firefox to the homepage instead of link, and the program freezes).
So I'm looking for a succint way of checking if there is an instance of firefox/whatever.
also this is the first time i've ever used Python or made a gui application everything prior to this was comand line C or numerical anaylsis in like Matlab/IDL
so while it's pretty retardedly simple at the moment (next step: I want to add a combo box for selecting/adding a feed instead of just combining them all, and a button/timer for updating the feeds) if you want to look at it and tell me if there's a better way to do anything
import gtk, gtkmozembed, os
import feedparser, fileinput
class TinyGecko:
def __init__(self):
self.moz = gtkmozembed.MozEmbed()
# make window, add html widget, define size
########
win = gtk.Window()
win.add(self.moz)
self.moz.set_size_request(400,300)
win.show_all()
geometry = '0x0+0+0'
win.parse_geometry(geometry)
#opens up list of feeds, from plaintext file, just one feed url per line
#then concatonates them all into one massive html string and renders it
#don't try with more than two or three feeds
########
#FEED = open(os.path.expanduser('~/.feeds'),'r')
FEED = open('feeds','r')
data = ' '
for line in FEED.readlines():
site = line.rstrip('n')
blog = feedparser.parse(site)
data = data + '<P> <FONT>' + blog.feed.title + '</FONT> </P>'
i = 0
for s in blog.entries:
data = data + blog.entries[i].title
data = data + s.content[0].value
i = i + 1
self.moz.render_data(data, long(len(data)), 'file:///', 'text/html')
#opens clicked links in firefox tabs and sends True to open-uri signal to prevent the widget from following
########
def openbrow(b,url):
comnd = 'firefox -new-tab ' + url
os.system(comnd)
return True
self.moz.connect('open-uri', openbrow)
win.connect("destroy", gtk.main_quit)
if __name__ == '__main__':
TinyGecko()
gtk.main()
syntax for "feeds" is just:
http://foo.com/feed
http://bar.com/feed
...
although it depends on gnome-python-extras so if your not a gnome user it's not really "lightweight", also depends of python-feedparser
Offline
I don't see any module for this but you could use subprocess and open up the system to use pgrep:
>>> from subprocess import Popen, PIPE
>>> p = Popen(['pgrep', 'X'], stdout=PIPE)
>>> signal = p.stdout.read().strip()
>>> p.stdout.close()
>>>if signal != '': print 'process running'
...
>>>process running
Offline