initial commit
This commit is contained in:
commit
3a96009467
84
mark_as_read.py
Normal file
84
mark_as_read.py
Normal file
@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" mark entries in miniflux as read that are older than n days via api calls
|
||||
"""
|
||||
import argparse
|
||||
import configparser
|
||||
import sys
|
||||
import time
|
||||
import requests
|
||||
|
||||
def parse_commandline_args():
|
||||
""" assmble commandline arguments - for more infomration see correspnding help entries
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description='mark entries older than n days as read in miniflux using the api of miniflux'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--config', type=str, help='path to the config file', required=True
|
||||
)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def is_reachable_and_healthy():
|
||||
""" check if the api is reachable and healthy
|
||||
"""
|
||||
try:
|
||||
request_healthcheck = requests.get(config['options']['url']+"/healthcheck")
|
||||
except requests.exceptions.ConnectionError as error:
|
||||
print(error)
|
||||
sys.exit(1)
|
||||
else:
|
||||
if request_healthcheck.status_code != 200:
|
||||
request_failed(request_healthcheck)
|
||||
|
||||
def get_ids_older_ndays():
|
||||
""" find entries older then delta and add their id to id_array
|
||||
"""
|
||||
headers = {'X-Auth-Token': config['options']['token']}
|
||||
delta = int(time.time()) - int(config['options']['age'])
|
||||
params = {"status": "unread", "before" : delta}
|
||||
request_unread = requests.get(config['options']['url']+'/v1/entries', params=params, headers=headers)
|
||||
|
||||
if request_unread.status_code != 200:
|
||||
request_failed(request_unread)
|
||||
|
||||
entries = request_unread.json()
|
||||
|
||||
if entries["entries"]:
|
||||
for item in entries["entries"]:
|
||||
if item['feed']['category']['title'] in config['options']['ignore']:
|
||||
continue
|
||||
|
||||
id_array.append(item["id"])
|
||||
|
||||
def mark_as_read():
|
||||
""" mark ids from id_array as read
|
||||
"""
|
||||
headers = {'X-Auth-Token': config['options']['token']}
|
||||
payload = {"status": "read", "entry_ids" : id_array}
|
||||
request_put_ids = requests.put(config['options']['url']+'/v1/entries', json=payload, headers=headers)
|
||||
|
||||
if request_put_ids.status_code != 204:
|
||||
request_failed(request_put_ids)
|
||||
|
||||
def request_failed(request_input):
|
||||
""" called when requests did not delive 200 or 204
|
||||
"""
|
||||
print(request_input.status_code, request_input.text)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
id_array = []
|
||||
args = parse_commandline_args()
|
||||
config = configparser.ConfigParser()
|
||||
config.read(args.config)
|
||||
is_reachable_and_healthy()
|
||||
get_ids_older_ndays()
|
||||
|
||||
if id_array:
|
||||
mark_as_read()
|
||||
|
||||
print("entries marked as read:", len(id_array))
|
6
mark_as_read.service
Normal file
6
mark_as_read.service
Normal file
@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=mark certain entries as read in miniflux
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/env python3 ./mark_as_read.py --config ./mark_as_read.ini
|
8
mark_as_read.timer
Normal file
8
mark_as_read.timer
Normal file
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=mark certain entries as read in miniflux
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Reference in New Issue
Block a user