Skip to content

Instantly share code, notes, and snippets.

@f0t0n
Created August 12, 2012 14:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save f0t0n/3332055 to your computer and use it in GitHub Desktop.
Save f0t0n/3332055 to your computer and use it in GitHub Desktop.
Converts lists of bookmarks in directories to dictionaries.
#!/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