46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
|
#!/usr/bin/env python
|
||
|
import json
|
||
|
import requests
|
||
|
from icecream import ic
|
||
|
import time
|
||
|
|
||
|
# settings
|
||
|
my_host = 'http://read.mossnet.lan'
|
||
|
oauth_url = '/oauth/v2/token'
|
||
|
params = {'username': 'anish',
|
||
|
'password': 'wallabag',
|
||
|
'grant_type': 'password',
|
||
|
'client_id': '2_4mo0x9udt4owwwo0kg8g004okgos0ccsgggg8c0o0484kc484s',
|
||
|
'client_secret': '1nv0k19p3mck4sk4kc0wcc8ssc44o80okcggccwk8cckkgww00',
|
||
|
'extension': 'json'}
|
||
|
|
||
|
def main():
|
||
|
# get a new token
|
||
|
header = {}
|
||
|
try:
|
||
|
request = requests.get(my_host+oauth_url, params=params)
|
||
|
content = json.loads(request.content)
|
||
|
access_token = content['access_token']
|
||
|
expires = time.time() + content['expires_in']
|
||
|
header = {'Authorization': "Bearer {0}".format(access_token)}
|
||
|
# dns error
|
||
|
except (requests.exceptions.ConnectionError, requests.exceptions.MissingSchema):
|
||
|
ic("Could not connect")
|
||
|
exit
|
||
|
|
||
|
# get all entries
|
||
|
count = 0
|
||
|
entries = requests.get(my_host+'/api/entries', params=params, headers=header)
|
||
|
entries = json.loads(entries.content)
|
||
|
for entry in entries['_embedded']['items']:
|
||
|
if entry['content'] == 'wallabag can\'t retrieve contents for this article. Please <a href="https://doc.wallabag.org/en/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.\n':
|
||
|
r = requests.patch(my_host+'/api/entries/{0}/reload'.format(entry['id']), params=params, headers=header)
|
||
|
count = count + 1
|
||
|
print("Reloading {0}, title: {1}".format(entry['id'], entry['title']))
|
||
|
|
||
|
print("{} entries reloaded".format(count))
|
||
|
return 0
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|