Permalink
Browse files

SUP, logging

  • Loading branch information...
Benjamin Golub
Benjamin Golub committed Nov 30, 2008
1 parent ab6b7f3 commit 1c700dcff649efdf6d675714eb278370e04cf902
Showing with 24 additions and 2 deletions.
  1. +24 −2 main.py
View
26 main.py
@@ -1,6 +1,8 @@
import BeautifulSoup
import feedgenerator
import functools
+import hashlib
+import logging
import os
import uuid
import urllib
@@ -185,6 +187,14 @@ def find_thumbnail(self, html):
if img:
return {"url": img["src"]}
return None
+
+ def generate_sup_id(self, url=None):
+ return hashlib.md5(url or self.request.url).hexdigest()[:10]
+
+ def set_sup_id_header(self):
+ sup_id = self.generate_sup_id()
+ self.response.headers["X-SUP-ID"] = \
+ "http://friendfeed.com/api/public-sup.json#%s" % sup_id
def render_feed(self, entries):
f = MediaRSSFeed(
@@ -205,6 +215,7 @@ def render_feed(self, entries):
)
data = f.writeString("utf-8")
self.response.headers["Content-Type"] = "application/atom+xml"
+ self.set_sup_id_header()
self.response.out.write(data)
def render_json(self, entries):
@@ -241,13 +252,19 @@ def render(self, template_file, extra_context={}):
self.response.out.write(template.render(path, extra_context))
def ping(self, entry=None):
+ feed = "http://" + self.request.host + "/?format=atom"
args = urllib.urlencode({
"name": TITLE,
"url": "http://" + self.request.host + "/",
- "changesURL": "http://" + self.request.host + "/?format=atom",
+ "changesURL": feed,
})
response = urlfetch.fetch("http://blogsearch.google.com/ping?" + args)
- return response.status_code
+ args = urllib.urlencode({
+ "url": feed,
+ "supid": self.generate_sup_id(feed),
+ })
+ response = urlfetch.fetch("http://friendfeed.com/api/public-sup-ping?" \
+ + args)
def is_valid_xhtml(self, entry):
args = urllib.urlencode({
@@ -315,6 +332,10 @@ def get(self):
class MainPageHandler(BaseRequestHandler):
+ def head(self):
+ if self.request.get("format", None) == "atom":
+ self.set_sup_id_header()
+
def get(self):
offset = self.get_integer_argument("start", 0)
if not offset:
@@ -428,6 +449,7 @@ def get(self, tag):
], debug=True)
def main():
+ logging.getLogger().setLevel(logging.DEBUG)
run_wsgi_app(application)
if __name__ == "__main__":

0 comments on commit 1c700dc

Please sign in to comment.