-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (33 loc) · 1.2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import requests
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("feed_name")
parser.add_argument("maxarticles")
args = parser.parse_args()
feedname=args.feed_name
maxarticles=int(args.maxarticles)
username='username'
password='supersecretpassword'
url='https://example.com/tt-rss/api/'
sendlogin='{"op":"login","user":"'+ username +'","password":"'+password +'"}'
response=requests.post(url,data=sendlogin)
sid=json.loads(response.content.decode('utf-8'))['content']['session_id']
getfeeds='{"sid":"'+sid+'","op":"getFeeds","cat_id":"-3"}'
feedresponse=requests.post(url,data=getfeeds)
feedlist=json.loads(feedresponse.content.decode('utf-8'))
for feed in feedlist['content']:
if feed['title'] == feedname:
feedid=feed['id']
unreadcount=int(feed['unread'])
#print(unreadcount)
getheadlines='{"sid":"'+sid+'","op":"getHeadlines","feed_id":"'+str(feedid)+'"}'
headlinesresp=requests.post(url,data=getheadlines)
headlines=json.loads(headlinesresp.content.decode('utf-8'))
artnr=0
for article in headlines['content']:
if article['unread']:
print(article['title'])
artnr+=1
if artnr >= min(maxarticles,int(unreadcount)):
break