~greg.grossmeier/gwibber/prefs

« back to all changes in this revision

Viewing changes to gwibber/microblog/rss.py

  • Committer: Ryan Paul
  • Date: 2008-11-09 11:06:40 UTC
  • Revision ID: segphault@arstechnica.com-20081109110640-5xdb89niunmdxiyb
Adding rss.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
"""
 
3
 
 
4
RSS interface for Gwibber
 
5
SegPhault (Ryan Paul) - 11/08/2008
 
6
 
 
7
"""
 
8
 
 
9
import urllib2, feedparser, can, support
 
10
 
 
11
PROTOCOL_INFO = {
 
12
  "name": "RSS",
 
13
  "version": 0.1,
 
14
  
 
15
  "config": [
 
16
    "feed_url",
 
17
    "message_color",
 
18
    "receive_enabled",
 
19
  ],
 
20
 
 
21
  "features": [
 
22
    can.RECEIVE,
 
23
  ],
 
24
}
 
25
 
 
26
feedparser._HTMLSanitizer.acceptable_elements = []
 
27
 
 
28
class Message:
 
29
  def __init__(self, client, data):
 
30
    self.client = client
 
31
    self.account = client.account
 
32
    self.protocol = client.account["protocol"]
 
33
    self.data = data
 
34
    self.sender = data.get("author", "")
 
35
    self.sender_nick = self.sender
 
36
    self.sender_id = self.sender
 
37
 
 
38
    if hasattr(data, "summary"):
 
39
      self.text = data.summary
 
40
    elif hasattr(data, "content"):
 
41
      if hasattr(data.content, "value"):
 
42
        self.text = data.content.value
 
43
      else: self.text = ""
 
44
    else: self.text = ""
 
45
 
 
46
    self.time = support.parse_time(data.updated)
 
47
    self.bgcolor = "message_color"
 
48
    self.url = data.link
 
49
    self.profile_url = "" # feed.author_detail.href
 
50
    self.title = "%s <br /> <small>By %s</small>" % (data.title, self.sender)
 
51
 
 
52
    if len(self.text) > 300:
 
53
      self.html_string = "%s..." % self.text[:300]
 
54
    else: self.html_string = self.text
 
55
 
 
56
class Client:
 
57
  def __init__(self, acct):
 
58
    self.account = acct
 
59
 
 
60
  def receive(self):
 
61
    f = feedparser.parse(self.account["feed_url"])
 
62
    
 
63
    for data in f.entries:
 
64
      yield Message(self, data)