X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Storage%2Fbkmk_stjson.py;h=04414f3276631fb0b0acb0bbeaada1ea2f4f0690;hb=ff7bf8d52beff0156f82cd4447768ebef4898b41;hp=ede71f38502aeba7314cabe05a44ce6d2a6586bc;hpb=61c2651bac82753c783545e633374a747a84c1cc;p=bookmarks_db.git diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index ede71f3..04414f3 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -3,11 +3,8 @@ 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 " -__copyright__ = "Copyright (C) 2010, 2011 PhiloSoft Design" +__copyright__ = "Copyright (C) 2010-2012 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['storage_json'] @@ -28,9 +25,9 @@ class storage_json(Walker): self.dict = dict = {} dict["children"] = children = [] self.folder_stack = [children] - dict["dateAdded"] = f.add_date + dict["dateAdded"] = convert_date_to_json(f.add_date) dict["id"] = f.id - dict["lastModified"] = f.last_modified + dict["lastModified"] = convert_date_to_json(f.last_modified) dict["root"] = "placesRoot" dict["title"] = "" dict["type"] = "text/x-moz-place-container" @@ -40,11 +37,11 @@ class storage_json(Walker): comment = getattr(f, 'comment') if comment: dict["annos"] = make_annos(comment) dict["children"] = children = [] - dict["dateAdded"] = f.add_date + dict["dateAdded"] = convert_date_to_json(f.add_date) dict["id"] = f.id index = getattr(f, 'index') if index: dict["index"] = index - dict["lastModified"] = f.last_modified + dict["lastModified"] = convert_date_to_json(f.last_modified) parent_idx = getattr(f, 'parent_idx') if parent_idx: dict["parent"] = parent_idx root = getattr(f, 'root') @@ -63,32 +60,25 @@ class storage_json(Walker): if comment: dict["annos"] = make_annos(comment) charset = getattr(b, 'charset') if charset: dict["charset"] = charset - dict["dateAdded"] = b.add_date + dict["dateAdded"] = convert_date_to_json(b.add_date) dict["id"] = b.id index = getattr(b, 'index') if index: dict["index"] = index keyword = getattr(b, 'keyword') if keyword: dict["keyword"] = keyword - dict["lastModified"] = b.last_modified + dict["lastModified"] = convert_date_to_json(b.last_modified) dict["parent"] = b.parent_idx dict["title"] = b.name.decode('utf-8') dict["type"] = "text/x-moz-place" dict["uri"] = uri = b.href if uri.startswith('place:'): - if uri.startswith('place:sort=8') \ - or uri.startswith('place://sort=8'): - value = 'MostVisited' - elif uri.startswith('place://redirectsMode'): - value = 'Most Visited' - elif uri.startswith('place:folder=BOOKMARKS_MENU') \ - or uri.startswith('place://folder=BOOKMARKS_MENU'): - value = 'RecentlyBookmarked' - elif uri.startswith('place://folder'): + if uri.startswith('place:folder'): value = 'Recently Bookmarked' - elif uri.startswith('place:sort=14') \ - or uri.startswith('place://sort=14'): - value = 'RecentTags' - elif uri.startswith('place://type'): + elif uri.startswith('place:sort=8') or \ + uri.startswith('place:redirectsMode'): + value = 'Most Visited' + elif uri.startswith('place:sort=14') or \ + uri.startswith('place:type=6'): value = 'Recent Tags' else: raise ValueError('UNKNOWN place URI: %s' % uri) @@ -101,10 +91,10 @@ class storage_json(Walker): dict = {} comment = getattr(r, 'comment') if comment: dict["annos"] = make_annos(comment) - dict["dateAdded"] = r.add_date + dict["dateAdded"] = convert_date_to_json(r.add_date) dict["id"] = r.id dict["index"] = r.index - dict["lastModified"] = r.last_modified + dict["lastModified"] = convert_date_to_json(r.last_modified) dict["parent"] = r.parent_idx dict["title"] = r.name.decode('utf-8') dict["type"] = "text/x-moz-place-separator" @@ -130,9 +120,9 @@ class storage_json(Walker): root_folder = Folder() root_folder.header = '' - root_folder.add_date = bookmarks_dict["dateAdded"] + root_folder.add_date = convert_date_from_json(bookmarks_dict["dateAdded"]) root_folder.comment = '' - root_folder.last_modified = bookmarks_dict["lastModified"] + root_folder.last_modified = convert_date_from_json(bookmarks_dict["lastModified"]) self.folder_stack = [root_folder] self.current_folder = root_folder @@ -155,9 +145,9 @@ class storage_json(Walker): for record in fdict["children"]: if record["type"] == "text/x-moz-place-container": folder = Folder( - add_date=record["dateAdded"], + add_date=convert_date_from_json(record["dateAdded"]), comment=get_comment(record.get("annos")), - last_modified=record["lastModified"]) + last_modified=convert_date_from_json(record["lastModified"])) self.current_folder.append(folder) self.folder_stack.append(folder) self.current_folder = folder @@ -166,8 +156,8 @@ class storage_json(Walker): elif record["type"] == "text/x-moz-place": bookmark = Bookmark( href=record["uri"].encode('utf-8'), - add_date=record.get("dateAdded"), - last_modified=record.get("lastModified"), + add_date=convert_date_from_json(record.get("dateAdded")), + last_modified=convert_date_from_json(record.get("lastModified")), keyword=get_str(record, "keyword"), comment=get_comment(record.get("annos")), charset=get_str(record, "charset")) @@ -179,10 +169,10 @@ class storage_json(Walker): elif record["type"] == "text/x-moz-place-separator": ruler = Ruler() - ruler.add_date = record["dateAdded"] + ruler.add_date = convert_date_from_json(record["dateAdded"]) ruler.id = record["id"] ruler.index = record["index"] - ruler.last_modified = record["lastModified"] + ruler.last_modified = convert_date_from_json(record["lastModified"]) ruler.parent_idx = record["parent"] ruler.name = encode_title(record["title"]) ruler.comment = get_comment(record.get("annos")) @@ -197,6 +187,19 @@ class storage_json(Walker): else: self.current_folder = None + +def convert_date_to_json(date): + if date: + date = int(date) * 10**6 + return date + +def convert_date_from_json(date): + if date: + date = int(date) + if date > 10**10: + date /= 10**6 + return date + def encode_title(title): return title.encode("UTF-8", "xmlcharrefreplace") @@ -210,8 +213,7 @@ def get_comment(annos): return '' for a in annos: - if a["name"] == "bookmarkProperties/description" and \ - a["type"] == 3: + if a["name"] == "bookmarkProperties/description": return a["value"].encode('utf-8') return ''