Created
August 12, 2012 14:22
-
-
Save f0t0n/3332055 to your computer and use it in GitHub Desktop.
Converts lists of bookmarks in directories to dictionaries.
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 python | |
def list_to_dict(pages): | |
return {page['name']: page for page in pages} | |
def convert_bookmarks(bookmarks): | |
for root, directory in bookmarks['roots'].iteritems(): | |
directory['children'] = list_to_dict(directory['children']) | |
if __name__ == '__main__': | |
bookmarks = { | |
'checksum': 'b884cbfb1a6697fa9b9eea9cb2054183', | |
'version': 1, | |
'roots': { | |
'synced': { | |
'name': 'bbb', | |
'date_modified': '0', | |
'children': [], | |
'date_added': '12989159700896558', | |
'type': 'folder', | |
'id': '3' | |
}, | |
'bookmark_bar': { | |
'name': 'bookmark_bar', | |
'date_modified': '12989159740428363', | |
'children': [{ | |
'url': 'chrome://bookmarks/#1', | |
'date_added': '12989159740428363', | |
'type': 'url', | |
'id': '4', | |
'name': 'test2' | |
}, { | |
'url': 'chrome://bookmarks/#2', | |
'date_added': '12989159740428363', | |
'type': 'url', | |
'id': '4', | |
'name': 'test' | |
}], | |
'date_added': '12989159700896551', | |
'type': 'folder', 'id': '1' | |
}, | |
'other': { | |
'name': 'aaa', | |
'date_modified': '0', | |
'children': [{ | |
'url': 'chrome://bookmarks/#1', | |
'date_added': '12989159740428363', | |
'type': 'url', | |
'id': '4', | |
'name': 'test' | |
}], | |
'date_added': '12989159700896557', | |
'type': 'folder', | |
'id': '2' | |
} | |
} | |
} | |
convert_bookmarks(bookmarks) | |
print bookmarks['roots']['bookmark_bar']['children']['test2']['url'] | |
print bookmarks['roots']['bookmark_bar']['children']['test']['url'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment