User Tools

Site Tools


dev:codesnip:unread_leed

# LeedUnread

## Overview

It's a small Python3 script that retrieve the total of unread RSS feed from your Leed RSS Reader. The plugin LeedApi needs to be installed for this script to work

You need to provide:

* The URL fo your server * Your username, in plain text * The salted password that's stored in the `users` table

  • It seems to be the only way to use the API… Not really easy though >_<

## Code

LeedUnread.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# Python modules
import requests			# API Calls
import json			# Parse API data
 
_ServURL = 'http://YOUR_SERVER/plugins/api/'
_Login = 'YOUR_LOGIN'
_Pwd = 'YOUR_SALTED_PASSWORD'
 
def APICall(cmd):
	sess = requests.Session()
	url = _ServURL + 'login.php?login='+_Login+'&password='+_Pwd
	payload = { }
	headers = {'content-type': 'application/x-www-form-urlencoded'}
	r = sess.get(url, data=json.dumps(payload), headers=headers, auth=requests.auth.HTTPDigestAuth(_Login, _Pwd))
 
	url = _ServURL + 'json.php?option='+cmd
	payload = { }
	headers = {'content-type': 'application/x-www-form-urlencoded'}
	r = sess.post(url, data=json.dumps(payload), headers=headers)
	rj = json.loads(r.text)
	return rj
 
# Pretty dump of a JSON object
def jDump(obj):
	print(json.dumps(obj,indent=2))
 
Nb = 0;
rj = APICall('getFolders&unreadOnly')
#jDump(rj)
if 'folders' in rj:
	folders = rj['folders']
	for folder in folders:
		if 'flux' in folder:
			#if 'titre' in folder:
			#	print(folder['titre'])
			for flux in folder['flux']:
				flux = folder['flux'][flux]
				if 'nbNoRead' in flux:
					#if 'name' in flux:
						#print(flux['name'],'-',flux['nbNoRead'])
					Nb = Nb + int(flux['nbNoRead']);
print(Nb)
/home/share/www/redox.ws/wiki/data/pages/dev/codesnip/unread_leed.txt · Last modified: 2023/11/24 21:55 by 127.0.0.1