fetch-favourites.py 839 B

12345678910111213141516171819202122232425262728293031
  1. import os
  2. from pprint import pprint as pp
  3. from pocket import Pocket, PocketException
  4. if __name__ == '__main__':
  5. p = Pocket(
  6. consumer_key=os.environ.get('POCKET_CONSUMER_KEY', ''),
  7. access_token=os.environ.get('POCKET_ACCESS_TOKEN', ''),
  8. )
  9. # Fetch a list of articles
  10. try:
  11. fetch_more = True
  12. offset = 0
  13. count = 10
  14. while fetch_more:
  15. items = p.retrieve(favorite=True, offset=offset, count=count)
  16. try:
  17. for item_id, item in items['list'].items():
  18. if not item['resolved_url']:
  19. continue
  20. print(item['resolved_url'])
  21. offset += count
  22. except AttributeError:
  23. fetch_more = False
  24. except PocketException as e:
  25. print(e.message)