Last active
December 17, 2015 19:59
-
-
Save pjob/5664544 to your computer and use it in GitHub Desktop.
Download Chrome bookmarks in OSX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2.7 | |
| # Chrome bookmark mirror on OSX | |
| import json | |
| import os | |
| import urllib2 | |
| SAVE_LOCATION = '/tmp/bookmarks' | |
| BOOKMARK_FILE = '/Users/user/Library/Application Support/Google/Chrome/Default/Bookmarks' | |
| bmfile = json.loads(open(BOOKMARK_FILE, 'r').read()) | |
| # bmfile.keys() = [u'checksum', u'version', u'roots'] | |
| # bmfile['roots'].keys() = [u'synced', u'bookmark_bar', u'other'] | |
| # iterate over each root bookmark and grab the children | |
| for root, parent in bmfile['roots'].iteritems(): | |
| root_dir = os.path.join(SAVE_LOCATION, root) | |
| # create dir if not exists | |
| if not os.path.exists(root_dir): | |
| os.makedirs(root_dir) | |
| for child in parent['children']: | |
| # Wrap this in try catch in case of javascript bookmarks | |
| # and other key error nonsense | |
| try: | |
| child_loc = os.path.join(root_dir, child['name']) | |
| u = urllib2.urlopen(child['url']) | |
| o = open(child_loc, 'w') | |
| o.write(u.read()) | |
| o.close() | |
| except: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment