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:
parent
851711a78e
commit
e10ba67b86
31
README.md
31
README.md
@ -351,6 +351,37 @@ Once exported, import the html file in your browser.
|
|||||||
BukuCrypt.decrypt_file(iterations, dbfile=None)
|
BukuCrypt.decrypt_file(iterations, dbfile=None)
|
||||||
NOTE: This flexibility is not exposed in the program.
|
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
|
### Related projects
|
||||||
|
|
||||||
- [bukubrow](https://github.com/SamHH/bukubrow), WebExtension for browser integration
|
- [bukubrow](https://github.com/SamHH/bukubrow), WebExtension for browser integration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user