new: doc: add example to use buku as library (#166)

* new: doc: add example buku as library

* fix: move to actual library section
This commit is contained in:
rachmadani haryono 2017-06-20 13:05:08 +08:00 committed by Arun Prakash Jana
parent 851711a78e
commit e10ba67b86

View File

@ -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