Advertisement
htnawsaj

Converter_Readability

May 13th, 2013
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. # firefoxize-starred-items.py
  2. #
  3. # Reads a Google "Reader JSON" file exported from Google Reader and
  4. # outputs an HTML file suitable for importing into Firefox's
  5. # bookmarks menu. This rescues you if you have been using Google
  6. # Reader Starred Items as a bookmark file for feeds.
  7. #
  8. # See http://googlereader.blogspot.com/2011/10/new-in-reader-fresh-design-and-google.html
  9. # and, when logged in, http://www.google.com/reader/settings?display=import
  10.  
  11. #original script from http://innocentpastimes.blogspot.in/2011/11/converting-google-reader-starred-items.html
  12.  
  13. import json, time, codecs
  14.  
  15. InputFile = 'C:\Personal\Python\Readability.json'  #download this
  16. OutputFile = 'C:\Personal\Python\Readability_new.html'  #import this
  17.  
  18. with codecs.open(InputFile, 'r', encoding='utf-8') as f:
  19.     ReadabilityItems = json.load(f)
  20.  
  21. FeedURLs = {}
  22. FeedItems = {}
  23.  
  24. for item in ReadabilityItems:
  25.     feedTitle = 'Readability'
  26.     feedUrl = item['article__url']
  27.     itemDate =  item['date_added']
  28.     itemTitle = item['article__title'].split('\n')[0]
  29.     itemURL = feedUrl
  30.     FeedURLs[feedTitle] = feedUrl
  31.     feedItems = FeedItems.setdefault(feedTitle, [])
  32.     feedItems.append((itemTitle, itemURL, itemDate))
  33.  
  34. with codecs.open(OutputFile, 'w', encoding='utf-8') as b:
  35.     b.write('''<!DOCTYPE html>
  36.   <html>
  37.        <head>
  38.                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  39.                <title>Instapaper: Export</title>
  40.        </head>\n''')
  41.     b.write('<body>\n\n')
  42.  
  43.     for feedTitle, feedURL in FeedURLs.items():
  44.         b.write('<h1>%s</h1>\n' % feedTitle)
  45.         b.write('<ol>\n')
  46.         for (title, url, date) in FeedItems[feedTitle]:
  47.             b.write('<li><a HREF="%s">%s</a></li>\n' % (url,title))
  48.         b.write('</ol>\n\n')
  49.     b.write('</body>\n\n\n')
  50.     b.write('</html>\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement