123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #!/usr/bin/env python2
- ################
- # Configuration
- feeds = {
- "Lockergnome" : {
- "url" : "http://www.lockergnome.com/feed/",
- },
- "RS News" : {
- "url" : "http://services.runescape.com/m=news/c=CVj3SDbT5*Q/latest_news.rss",
- }
- }
- dataFilePath = '~/.appdata/feedgin.data'
- ################
- import dbus
- import feedparser
- import calendar
- import csv
- import os.path
- feedProcessedTimes = {name:0 for name in feeds}
- dataFilePathExpanded = os.path.expanduser(dataFilePath)
- if os.path.exists(dataFilePathExpanded):
- dataFile = open(dataFilePathExpanded, 'rb+')
- dataReader = csv.reader(dataFile)
- for row in dataReader:
- feedProcessedTimes[row[0]] = long(row[1])
- bus = dbus.SessionBus()
- obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
- purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
- activeAccounts = purple.PurpleAccountsGetAllActive()
- messageFlags = 0x2
- from datetime import datetime
- if (len(activeAccounts) > 0) :
- account = activeAccounts[0]
- conversation = purple.PurpleConversationNew(1, account, "feedgin")
- for feedName in feeds:
- print "Fetching", feedName, "[", datetime.now(), "]"
- feed = feeds[feedName]
- url = feed["url"]
- ast = feedparser.parse(url)
- #purple.PurpleConversationWrite(conversation, feedName, ast.feed.title, 0, 0)
- #print "feed:", ast.feed
- #print "entries:"
- for x in sorted(ast.entries, key = lambda entry: entry.updated_parsed):
- # for e in x: print e,':', x[e]
- time_since_epoch = calendar.timegm(x.updated_parsed)
- if time_since_epoch > feedProcessedTimes[feedName]:
- feedProcessedTimes[feedName] = time_since_epoch
- if x.has_key("author_detail"):
- author = x.author_detail
- else:
- class DummyAuthor:
- href='#'
- name='-'
- author = DummyAuthor()
- # Pidgin apparently doesn't show <img/> correctly
- #text = "<img id='42' src='"+x.media_thumbnail[0]["url"]+"' />"
- text = "<br/><b><a href='"+ x.link + "'>"+x.title+"</a></b> <em>by</em> <b><a href='"+author.href+"'>"+author.name+"</a></b>"
- if (feed.get("showSummary", True)):
- text += "<br/><small>" + x.summary + '</small>'
- im = purple.PurpleConvIm(conversation)
- purple.PurpleConvImWrite(im, feedName, text, messageFlags, time_since_epoch)
- else:
- print "No account is online right now."
- dataFile = open(dataFilePathExpanded, 'wb+')
- dataWriter = csv.writer(dataFile)
- for feedName in feedProcessedTimes:
- dataWriter.writerow([feedName, feedProcessedTimes[feedName]])
|