2 """Add a bookmark to the database
4 This file is a part of Bookmarks database and Internet robot.
8 __author__ = "Oleg Broytman <phd@phdru.name>"
9 __copyright__ = "Copyright (C) 2002-2017 PhiloSoft Design"
10 __license__ = "GNU GPL"
13 from bkmk_objects import Bookmark
14 from robots import robot
18 from getopt import getopt
19 optlist, args = getopt(sys.argv[1:], "t:")
24 for _opt, _arg in optlist:
35 sys.stderr.write("bkmk-add: too many or too few arguments\n")
36 sys.stderr.write("Usage: bkmk-add [-s] [-t title] url\n")
39 from storage import storage
43 sys.stdout.write("Loading %s: " % storage.filename)
46 root_folder = storage.load()
52 now = int(time.time())
53 bookmark = Bookmark(href, str(now), '0', '0')
55 bookmark.parent = None
60 if robot.check_url(bookmark): # get real title and last modified date
61 if title: # forced title
63 elif hasattr(bookmark, "real_title"):
64 bookmark.name = bookmark.real_title
66 sys.stdout.write("Adding %s with title '%s'\n" % (href, bookmark.name))
68 root_folder.append(bookmark)
71 sys.stdout.write("Storing %s: " % storage.filename)
74 storage.store(root_folder)
80 if __name__ == '__main__':