SHARE
TWEET

Converter

htnawsaj Apr 4th, 2013 933 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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\starred.json'  #download this
  16. OutputFile = 'C:\Personal\Python\starred.html'  #import this
  17.  
  18. with codecs.open(InputFile, 'r', encoding='utf-8') as f:
  19.     GooglesItems = json.load(f)['items']
  20.  
  21. FeedURLs = {}
  22. FeedItems = {}
  23.  
  24. for item in GooglesItems:
  25.     feedTitle = item['origin']['title']
  26.     feedUrl = item['origin']['htmlUrl']
  27.     itemDate =  item['published']
  28.     if item.has_key('title'):
  29.         itemTitle = item['title'].split('\n')[0]
  30.     else:
  31.         itemTitle = feedTitle + ', ' +  time.strftime('%x', time.localtime(itemDate))
  32.     if item.has_key('alternate'):
  33.         itemURL = item['alternate'][0]['href']
  34.     elif item.has_key('enclosure'):
  35.         itemURL = item['enclosure'][0]['href']
  36.     else:
  37.         itemURL = feedURL
  38.     FeedURLs[feedTitle] = feedUrl
  39.     feedItems = FeedItems.setdefault(feedTitle, [])
  40.     feedItems.append((itemTitle, itemURL, itemDate))
  41.  
  42. with codecs.open(OutputFile, 'w', encoding='utf-8') as b:
  43.     b.write('''<!DOCTYPE html>
  44.    <html>
  45.         <head>
  46.                 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  47.                 <title>Instapaper: Export</title>
  48.         </head>\n''')
  49.     b.write('<body>\n\n')
  50.  
  51.     for feedTitle, feedURL in FeedURLs.items():
  52.         b.write('<h1>%s</h1>\n' % feedTitle)
  53.         b.write('<ol>\n')
  54.         for (title, url, date) in FeedItems[feedTitle]:
  55.             b.write('<li><a HREF="%s">%s</a></li>\n' % (url,title))
  56.         b.write('</ol>\n\n')
  57.     b.write('</body>\n\n\n')
  58.     b.write('</html>\n')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top