X-Git-Url: https://git.phdru.name/?p=bookmarks_db.git;a=blobdiff_plain;f=set-real_title.py;h=a97a421ce84fcf44b20d93d089f14da19f2c59d6;hp=f216b1f376ba5d7a2ab3eb7d20565a17e302cf7b;hb=HEAD;hpb=9edef5a570ea28f7c06d8d92fdd70afe0ea86809 diff --git a/set-real_title.py b/set-real_title.py index f216b1f..60b3c20 100755 --- a/set-real_title.py +++ b/set-real_title.py @@ -1,84 +1,86 @@ -#! /usr/bin/env python -""" - Run through the bookmarks database and set name to real title +#! /usr/bin/env python3 +"""Run through the bookmarks database and set name to real title - Written by BroytMann, Jul 2002 - May 2003. Copyright (C) 2002-2003 PhiloSoft Design +This file is a part of Bookmarks database and Internet robot. """ - +from __future__ import print_function import sys -def run(): - from getopt import getopt - optlist, args = getopt(sys.argv[1:], "s") - - report_stats = 1 - - for _opt, _arg in optlist: - if _opt == '-s': - report_stats = 0 - try: - del _opt, _arg - except NameError: - pass - - if report_stats: - print "BroytMann set-real_title, Copyright (C) 2003 PhiloSoft Design" - - if args: - sys.stderr.write("set-real_title: too many arguments\n") - sys.stderr.write("Usage: set-real_title [-s]\n") - sys.exit(1) - - from storage import storage - storage = storage() - - if report_stats: - sys.stdout.write("Loading %s: " % storage.filename) - sys.stdout.flush() - - root_folder = storage.load() - from bkmk_objects import make_linear - make_linear(root_folder) - objects = len(root_folder.linear) +__author__ = "Oleg Broytman " +__copyright__ = "Copyright (C) 2002-2023 PhiloSoft Design" +__license__ = "GNU GPL" - if report_stats: - print "Ok" - - changed = 0 - for object_no in range(objects): - object = root_folder.linear[object_no] - - if object.isBookmark: - if not hasattr(object, "real_title"): - continue - - real_title = object.real_title - if not real_title: - real_title = object.href - if object.name <> real_title: - object.name = real_title - changed += 1 - - - if changed and report_stats: - sys.stdout.write("Saving %s: " % storage.filename) - sys.stdout.flush() - - if not changed and report_stats: - sys.stdout.write("No need to save data\n") - sys.stdout.flush() - - if changed: - storage.store(root_folder) - - if changed and report_stats: - print "Ok" - print objects, "objects passed" - print changed, "objects changed" +def run(): + from getopt import getopt + optlist, args = getopt(sys.argv[1:], "s") + + report_stats = 1 + + for _opt, _arg in optlist: + if _opt == '-s': + report_stats = 0 + try: + del _opt, _arg + except NameError: + pass + + if report_stats: + print("Broytman set-real_title, Copyright (C)" + " 2003-2023 PhiloSoft Design") + if args: + sys.stderr.write("set-real_title: too many arguments\n") + sys.stderr.write("Usage: set-real_title [-s]\n") + sys.exit(1) + + from storage import storage + storage = storage() + + if report_stats: + sys.stdout.write("Loading %s: " % storage.filename) + sys.stdout.flush() + + root_folder = storage.load() + from bkmk_objects import make_linear + make_linear(root_folder) + objects = len(root_folder.linear) + + if report_stats: + print("Ok") + + changed = 0 + for object_no in range(objects): + object = root_folder.linear[object_no] + + if object.isBookmark: + if not hasattr(object, "real_title"): + continue + + real_title = object.real_title + if not real_title: + real_title = object.href + if object.name != real_title: + object.name = real_title + changed += 1 + + if changed and report_stats: + sys.stdout.write("Saving %s: " % storage.filename) + sys.stdout.flush() + + if not changed and report_stats: + sys.stdout.write("No need to save data\n") + sys.stdout.flush() + + if changed: + storage.store(root_folder) + + if changed and report_stats: + print("Ok") + print(objects, "objects passed") + print(changed, "objects changed") if __name__ == '__main__': - run() + run()