User:Megan Hoogenboom/rss

From XPUB & Lens-Based wiki
< User:Megan Hoogenboom
Revision as of 20:35, 23 September 2010 by Migratebot (talk | contribs) (Created page with "== NRC Next RSS reader == <source lang="text"> import feedparser import urllib2, urlparse, os, sys import html5lib import os def openURL (url): """ returns (...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

NRC Next RSS reader

import feedparser
import urllib2, urlparse, os, sys
import html5lib
import os

def openURL (url):
    """
    returns (page, actualurl)
    sets user_agent and resolves possible redirection
    realurl maybe different than url in the case of a redirect
    """    
    request = urllib2.Request(url)
    user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5"
    request.add_header("User-Agent", user_agent)
    pagefile=urllib2.urlopen(request)
    realurl = pagefile.geturl()
    return (pagefile, realurl)
    
newwork = feedparser.parse("http://feeds.nrcnext.nl/nrcnext-blog")

print """
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>feedbook</title>
    <link type="text/css" rel="stylesheet" media="all" href="stylesheet.css" />
  </head>
  <body>"""
  
for e in newwork.entries:
    print"<h1>"
    print e["title"].replace("&", "&amp;").encode("utf-8")
    print"</h1>"
    print"<p>"
    print e["summary"].replace("&", "&amp;").encode("utf-8")
    print"</p>"
    print
print"""
  </body>
</html>"""

#os.system('~/Documents/Technical_Trimester\ 2/assignment\ 1/makebook.sh')



python feed.py > feedbook/OEBPS/content.html
cd feedbook
zip -0Xq feedbook.epub mimetype
zip -Xr9Dq feedbook.epub *
lucidor feedbook.epub



Attachments