]> git.phdru.name Git - bookmarks_db.git/commitdiff
Relax record schema requirements
authorOleg Broytman <phd@phdru.name>
Sat, 31 May 2014 20:05:43 +0000 (00:05 +0400)
committerOleg Broytman <phd@phdru.name>
Sat, 31 May 2014 20:05:43 +0000 (00:05 +0400)
Storage/bkmk_stjson.py

index 04414f3276631fb0b0acb0bbeaada1ea2f4f0690..53eae9b81c14b9a316ed6a46dc738cf81b5b7a5f 100644 (file)
@@ -120,12 +120,14 @@ class storage_json(Walker):
 
         root_folder = Folder()
         root_folder.header = ''
-        root_folder.add_date = convert_date_from_json(bookmarks_dict["dateAdded"])
+        root_folder.add_date = convert_date_from_json(bookmarks_dict.get("dateAdded"))
         root_folder.comment = ''
-        root_folder.last_modified = convert_date_from_json(bookmarks_dict["lastModified"])
+        root_folder.last_modified = convert_date_from_json(bookmarks_dict.get("lastModified"))
         self.folder_stack = [root_folder]
         self.current_folder = root_folder
 
+        if "type" not in bookmarks_dict:
+           bookmarks_dict = bookmarks_dict["children"][0]
         self.load_folder(root_folder, bookmarks_dict)
         if self.folder_stack:
             raise RuntimeError('Excessive folder stack: %s' % self.folder_stack)
@@ -145,9 +147,9 @@ class storage_json(Walker):
         for record in fdict["children"]:
             if record["type"] == "text/x-moz-place-container":
                 folder = Folder(
-                    add_date=convert_date_from_json(record["dateAdded"]),
+                    add_date=convert_date_from_json(record.get("dateAdded")),
                     comment=get_comment(record.get("annos")),
-                    last_modified=convert_date_from_json(record["lastModified"]))
+                    last_modified=convert_date_from_json(record.get("lastModified")))
                 self.current_folder.append(folder)
                 self.folder_stack.append(folder)
                 self.current_folder = folder
@@ -163,17 +165,17 @@ class storage_json(Walker):
                     charset=get_str(record, "charset"))
                 bookmark.id = record["id"]
                 bookmark.index = record.get("index")
-                bookmark.parent_idx = record["parent"]
+                bookmark.parent_idx = record.get("parent")
                 bookmark.name = encode_title(record["title"])
                 self.current_folder.append(bookmark)
 
             elif record["type"] == "text/x-moz-place-separator":
                 ruler = Ruler()
-                ruler.add_date = convert_date_from_json(record["dateAdded"])
+                ruler.add_date = convert_date_from_json(record.get("dateAdded"))
                 ruler.id = record["id"]
                 ruler.index = record["index"]
-                ruler.last_modified = convert_date_from_json(record["lastModified"])
-                ruler.parent_idx = record["parent"]
+                ruler.last_modified = convert_date_from_json(record.get("lastModified"))
+                ruler.parent_idx = record.get("parent")
                 ruler.name = encode_title(record["title"])
                 ruler.comment = get_comment(record.get("annos"))
                 self.current_folder.append(ruler)