Personal wiki notebook (not under development)

Updates_rss.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import cgi
  2. from urllib import urlencode
  3. from Rss_channel import Rss_channel
  4. from Rss_item import Rss_item
  5. class Updates_rss( Rss_channel ):
  6. def __init__(
  7. self,
  8. recent_notes,
  9. notebook_id,
  10. notebook_name,
  11. https_url,
  12. ):
  13. if notebook_name == u"Luminotes":
  14. notebook_path = u"/"
  15. elif notebook_name == u"Luminotes user guide":
  16. notebook_path = u"/guide"
  17. elif notebook_name == u"Luminotes blog":
  18. notebook_path = u"/blog"
  19. else:
  20. notebook_path = u"/notebooks/%s" % notebook_id
  21. notebook_path = https_url + notebook_path
  22. Rss_channel.__init__(
  23. self,
  24. cgi.escape( notebook_name ),
  25. notebook_path,
  26. u"Luminotes notebook",
  27. recent_notes and [ Rss_item(
  28. title = u"Note updated",
  29. link = self.note_link( notebook_id, notebook_name, note_id, revision, https_url ),
  30. description = cgi.escape( u'A note in <a href="%s">this notebook</a> has been updated. <a href="%s?note_id=%s">View the note.</a>' % ( notebook_path, notebook_path, note_id ) ),
  31. date = revision.strftime( "%Y-%m-%dT%H:%M:%SZ" ),
  32. guid = self.note_link( notebook_id, notebook_name, note_id, revision, https_url ),
  33. ) for ( note_id, revision ) in recent_notes ] or [ Rss_item(
  34. title = u"Unknown notebook",
  35. link = None,
  36. description = cgi.escape( u'Sorry, that notebook is unknown.' ),
  37. date = None,
  38. guid = None,
  39. ) ],
  40. )
  41. @staticmethod
  42. def note_link( notebook_id, notebook_name, note_id, revision, https_url ):
  43. query = urlencode( [
  44. ( u"notebook_id", notebook_id ),
  45. ( u"notebook_name", notebook_name.encode( "utf8" ) ),
  46. ( u"note_id", note_id ),
  47. ( u"revision", unicode( revision ) ),
  48. ] )
  49. return cgi.escape( u"%s/notebooks/get_update_link?%s" % ( https_url, query ) )