3 from rss_sqlite import Listing
7 from htmlentitydefs import name2codepoint
9 CONFIGDIR = "/home/user/.feedingit/"
18 return unichr(int(text[3:-1], 16))
20 return unichr(int(text[2:-1]))
26 text = unichr(name2codepoint[text[1:-1]])
29 return text # leave as is
30 return sub("&#?\w+;", fixup, text)
32 class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
34 def openTaskSwitch(self):
36 subprocess.Popen("dbus-send /com/nokia/hildon_desktop com.nokia.hildon_desktop.exit_app_view", shell=True)
38 def getConfigXml(self):
39 xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml>"
40 xml += "<hideReadFeed>True</hideReadFeed>"
41 xml += "<hideReadArticles>True</hideReadArticles>"
45 def generateCategoryXml(self):
46 xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml>"
47 for cat in listing.getListOfCategories():
49 xml += "<catname>%s</catname>" %listing.getCategoryTitle(cat)
50 xml += "<catid>%s</catid>" % cat
55 def fix_title(self, title):
56 return escape(unescape(title).replace("<em>","").replace("</em>","").replace("<nobr>","").replace("</nobr>","").replace("<wbr>","").replace("—","-"))
58 def generateFeedsXml(self, catid):
59 xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml>"
60 for key in listing.getSortedListOfKeys("Manual", category=catid):
62 xml += "<feedname>%s</feedname>" %listing.getFeedTitle(key)
63 xml += "<feedid>%s</feedid>" %key
64 xml += "<unread>%s</unread>" %listing.getFeedNumberOfUnreadItems(key)
65 xml += "<updatedDate>%s</updatedDate>" %listing.getFeedUpdateTime(key)
66 xml += "<icon>%s</icon>" %listing.getFavicon(key)
71 def generateArticlesXml(self, key, onlyUnread, markAllAsRead):
72 feed = listing.getFeed(key)
73 if markAllAsRead=="True":
75 listing.updateUnread(key)
76 xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml>"
77 if onlyUnread == "False":
79 for id in feed.getIds(onlyUnread):
81 xml += "<title>%s</title>" %self.fix_title(feed.getTitle(id))
82 xml += "<articleid>%s</articleid>" %id
83 xml += "<unread>%s</unread>" %str(feed.isEntryRead(id))
84 xml += "<updatedDate>%s</updatedDate>" %feed.getDateStamp(id)
85 xml += "<path>%s</path>" %feed.getContentLink(id)
91 (req, sep, arg) = self.path.partition("?")
92 request = req.split("/")
101 arguments[ele[0]] = ele[1]
104 if request[1] == "categories":
105 xml = self.generateCategoryXml()
106 elif request[1] == "feeds":
108 xml = self.generateFeedsXml(catid)
109 elif request[1] == "articles":
111 onlyUnread = arguments.get("onlyUnread","False")
112 markAllAsRead = arguments.get("markAllAsRead", "False")
113 xml = self.generateArticlesXml(key, onlyUnread, markAllAsRead)
114 elif request[1] == "html":
117 feed = listing.getFeed(key)
118 file = open(feed.getContentLink(article))
119 feed.setEntryRead(article)
120 html = file.read().replace("body", "body bgcolor='#ffffff'", 1)
122 self.send_response(200)
123 self.send_header("Content-type", "text/html")
125 self.wfile.write(html)
126 listing.updateUnread(key)
128 elif request[1] == "config":
129 xml = self.getConfigXml()
130 elif request[1] == "home":
131 file = open(self.path)
132 self.send_response(200)
133 self.send_header("Content-type", "text/html")
135 self.wfile.write(file.read())
138 elif request[1] == "task":
139 self.openTaskSwitch()
140 xml = "<xml>OK</xml>"
142 self.send_error(404, "File not found")
144 self.send_response(200)
145 self.send_header("Content-type", "text/xml")
147 self.wfile.write(xml.encode("utf-8"))
151 listing = Listing(CONFIGDIR)
153 httpd = BaseHTTPServer.HTTPServer(("127.0.0.1", PORT), Handler)
154 print "serving at port", PORT
155 httpd.serve_forever()