From: Oleg Broytman Date: Sat, 31 May 2014 20:05:43 +0000 (+0400) Subject: Relax record schema requirements X-Git-Tag: v4.6.0~36 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=68e13edbb4761b0dc323a3f48b977c80e0139042;p=bookmarks_db.git Relax record schema requirements --- diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 04414f3..53eae9b 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -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)