-
Notifications
You must be signed in to change notification settings - Fork 1
/
safari2chrome.py
38 lines (30 loc) · 1 KB
/
safari2chrome.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
from plistlib import *
# read plist file and get URLs and titles
with open('./Bookmarks.plist', 'rb') as fp:
plist = load(fp)
urlArray = plist['Children'][3]['Children']
marks = []
for dict in urlArray:
marks.append((dict['URLString'], dict['URIDictionary']['title']))
# create Chrome bookmark html file
fileHeader = '''<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
'''
rowHeader = '<DL><p>\n'
rowFooter = '</DL><p>'
bookmarkFolderLine = '<DT><H3 ADD_DATE="" LAST_MODIFIED="">Safari Web Bookmark</H3>\n'
f = open('chrome-bookmark.html', 'w')
f.write(fileHeader)
f.write(rowHeader)
f.write(bookmarkFolderLine)
f.write(rowHeader)
for target in marks:
str = u'<DT><A HREF="' + target[0] + u'" ADD_DATE="" ICON="">' + target[1] + u'</A>' + '\n'
f.write(str)
f.write(rowFooter)
f.write(rowFooter)