Fredrik Håård avatar Fredrik Håård committed 32c0d25

RSS generation added

Comments (0)

Files changed (1)

 import os, os.path, sys, shutil, re
 from docutils.core import publish_parts
 from hgapi import hgapi
+import PyRSS2Gen
 
 CSS_NAME = "blaag.css"
 CSS_URL = '/blaag.css'
 CSS_PATH = 'css'
 ENTRIES_PATH = 'entries'
 HTML_PATH = 'html'
-BASE = '/'
+BASE = 'http://blaag.haard.se/'
 TITLE = u'Fredrik Håård\'s Blaag'
+DESCRIPTION = u'YAB'
 DISQUS_NAME = 'devrantblaag'
 
 defaults = {'disqus_name': DISQUS_NAME, 
 modified_tpl = Template(open("templates/modified.html").read().decode("utf-8"))
 
 
+def generate_rss(data):
+    items = []
+    for parts in data:
+        items.append(PyRSS2Gen.RSSItem(
+            title = parts['title'],
+            link = url(parts),
+            description = parts['html_body'],
+            guid = PyRSS2Gen.Guid(url(parts)),
+            pubDate = datetime.fromtimestamp(parts['created'])))
+
+
+
+    rss = PyRSS2Gen.RSS2(
+        title = TITLE,
+        link = BASE,
+        description = DESCRIPTION,
+        lastBuildDate = datetime.utcnow(),
+        items = items)
+
+    rss.write_xml(open(os.path.join(HTML_PATH, "rss.xml"), "w"))
+    
 def get_data(entry):
     """Parse the rst in the string entry and return the parts dict"""
     return publish_parts(entry, writer_name="html")
         target.write(page_tpl.substitute(defaults, links=links, 
                                          main="<hr/>".join(main)).encode("utf-8"))
 
+    #Write rss
+    generate_rss(data)
 if __name__ == "__main__":
     generate_blaag(get_entries(), "-f" in sys.argv)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.