-
-
Notifications
You must be signed in to change notification settings - Fork 298
Buku as a library
Arun Prakash Jana edited this page Aug 15, 2017
·
3 revisions
buku
is developed as a powerful python library for bookmark management. All functionality are available through carefully designed APIs. main()
is a good usage example. It's also possible to use a custom database file in multi-user scenarios. Check out the documentation for the following APIs which accept an optional argument as database file:
BukuDb.initdb(dbfile=None)
BukuCrypt.encrypt_file(iterations, dbfile=None)
BukuCrypt.decrypt_file(iterations, dbfile=None)
NOTE: This flexibility is not exposed in the program.
The api directory has several example wrapper web APIs, not necessarily updated. Feel free to update if you need them.
An example to print the http status code of urls saved in buku
goes below. To run, install grequests.
import buku
import grequests
bdb = buku.BukuDb()
recs = bdb.get_rec_all()
recs[0]
# output: (1, 'example.com', 'example', 'tag1,tag2', 'page description', 0)
# Records have following structure:
# - id,
# - url,
# - metadata,
# - tags,
# - description,
# - flags
urls = [x[1] for x in recs]
rs = (grequests.get(u) for u in urls)
gr_results = grequests.map(rs)
for resp, url in zip(gr_results, urls):
stat_code = None if resp.status_code is None else resp.status_code
print('{}: {}'.format(stat_code, url))
# output
# 200: http://example.com
# None: http://website1.com/
# 200: http://website2.com/
# ...