diff --git a/README.md b/README.md index 50e9053..eaeb0c6 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,37 @@ Once exported, import the html file in your browser. BukuCrypt.decrypt_file(iterations, dbfile=None) NOTE: This flexibility is not exposed in the program. +Here is an example to print the status code of the saved url on buku. +To run the example you need to install [grequests](https://github.com/kennethreitz/grequests). + +```python +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/ +# ... +``` + ### Related projects - [bukubrow](https://github.com/SamHH/bukubrow), WebExtension for browser integration