a collection of learned incantations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
1.4 KiB

  1. import requests
  2. # setup request headers
  3. host = 'http://192.168.1.100:800'
  4. form = 'json'
  5. path = '/api/entries.{ext}'.format(ext=form)
  6. pathToken = '/oauth/v2/token'
  7. # auth stuff
  8. user = 'wallabag'
  9. secret = open("/home/anish/usr/dev/secrets/wallabag", "r")
  10. password = secret.readline()[:-1]
  11. clientID = secret.readline()[:-1]
  12. clientSecret = secret.readline()[:-1]
  13. paramsToken = dict({'client_id': clientID,
  14. 'client_secret': clientSecret,
  15. 'username': user,
  16. 'grant_type': 'password',
  17. 'password': password})
  18. # params for the get request
  19. sort = 'updated',
  20. archive = 1
  21. perPage = 15
  22. since = 0
  23. detail = 'metadata'
  24. # get the token
  25. token = requests.post(host+pathToken, data=paramsToken)
  26. token = token.json()['access_token']
  27. # create the params for the request
  28. params = dict({'access_token': token,
  29. 'sort': sort,
  30. 'archive': archive,
  31. 'perPage': perPage,
  32. #'detail': detail,
  33. 'since': since})
  34. # make request and handle response
  35. # wallabag gives us the entire article, instead of just metadata :/
  36. r = requests.get(host+path, params=params)
  37. for links in r.json()['_embedded']['items']:
  38. count = 0
  39. for (key, link) in links.items():
  40. if key == 'title' or key == 'url':
  41. print(link)
  42. count = count + 1
  43. if count == 2:
  44. print()
  45. count = 0