-"""
- Bookmarks storage manager - json.
+"""Bookmarks storage manager - json
- Written by Broytman, Jul 2010. Copyright (C) 2010 PhiloSoft Design
+This file is a part of Bookmarks database and Internet robot.
"""
+__version__ = "$Revision$"[11:-2]
+__revision__ = "$Id$"[5:-2]
+__date__ = "$Date$"[7:-2]
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2010, 2011 PhiloSoft Design"
+__license__ = "GNU GPL"
+
+__all__ = ['storage_json']
+
try:
import json
dict["parent"] = b.parent_idx
dict["title"] = b.name.decode('utf-8')
dict["type"] = "text/x-moz-place"
- dict["uri"] = b.href
+ dict["uri"] = uri = b.href
+ if uri.startswith('place:'):
+ if uri.startswith('place:sort=8'):
+ value = 'MostVisited'
+ elif uri.startswith('place:folder=BOOKMARKS_MENU'):
+ value = 'RecentlyBookmarked'
+ elif uri.startswith('place:sort=14'):
+ value = 'RecentTags'
+ dict["annos"] = make_annos(value, name='Places/SmartBookmark')
+ del dict["dateAdded"]
+ del dict["lastModified"]
self.folder_stack[-1].append(dict)
def ruler(self, r, level):
outfile.close()
del self.dict
-
def load(self):
infile = open(self.filename, 'rb')
bkmk_s = infile.read()
# Work around a bug in Mozilla - remove the trailing comma
bkmk_s = bkmk_s.strip().replace(',]', ']')
bookmarks_dict = json.loads(bkmk_s)
+ del bkmk_s
root_folder = Folder()
root_folder.header = ''
def load_folder(self, folder, fdict):
if fdict["type"] != "text/x-moz-place-container":
- raise ValueError("Root object is not a Mozilla container")
+ raise ValueError("The object is not a Mozilla container")
folder.id = fdict["id"]
folder.index = fdict.get("index")
def get_comment(annos):
if not annos:
- return None
+ return ''
for a in annos:
if a["name"] == "bookmarkProperties/description" and \
a["type"] == 3:
return a["value"].encode('utf-8')
- return None
+ return ''
-def make_annos(comment):
+def make_annos(value, name="bookmarkProperties/description"):
return [{
"expires": 4,
"flags": 0,
"mimeType": None,
- "name": "bookmarkProperties/description",
+ "name": name,
"type": 3,
- "value": comment.decode('utf-8')}]
+ "value": value.decode('utf-8')}]