-
Notifications
You must be signed in to change notification settings - Fork 0
/
chbookmarks.py
executable file
·48 lines (40 loc) · 1.25 KB
/
chbookmarks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import os
import argparse
import sys
import json
from pprint import pprint
# https://pythonexample.com/code/parse-chrome-bookmarks-file/
def bookmarklist(path):
if path['type'] == 'folder':
for n in path['children']:
if n['type'] == 'url':
if n['name'] == None:
title = ""
else:
title = n['name']
print(title)
print(n['url'])
elif n['type'] == 'folder':
for child in n['children']:
bookmarklist(child)
elif path['type'] == 'url':
if path['name'] == None:
title = ""
else:
title = path['name']
print(title)
print(path['url'])
def main():
parser = argparse.ArgumentParser(description="chbookmarks")
parser.add_argument("--path", help="Path of the JSON file to be scanned")
args = vars(parser.parse_args())
jsonPath = os.path.abspath(os.path.expanduser(args['path']))
with open(jsonPath) as data_file:
jsonObject = json.load(data_file)
roots = jsonObject['roots']
for root in roots:
rootObject = roots[root]
bookmarklist(rootObject)
if __name__ == "__main__":
main()