Skip to content

Commit f2dda4e

Browse files
authored
Merge pull request #2 from einverne/add_functions
Add more functions
2 parents 68300cf + d3ef6a1 commit f2dda4e

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ ENV/
6262

6363
# Spyder project settings
6464
.spyderproject
65+
.idea/*

inoreader/client.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .consts import BASE_URL, LOGIN_URL
1515
from .exception import NotLoginError, APIError
1616
from .article import Article
17+
from .subscription import Subscription
1718

1819

1920
class InoreaderClient(object):
@@ -97,6 +98,46 @@ def get_tags(self):
9798
tags.sort(key=itemgetter('name'))
9899
return tags
99100

101+
def get_subscription_list(self):
102+
if not self.auth_token:
103+
raise NotLoginError
104+
105+
url = urljoin(BASE_URL, 'subscription/list')
106+
resp = self.session.get(url)
107+
if resp.status_code != 200:
108+
raise APIError(resp.text)
109+
110+
for item in resp.json()['subscriptions']:
111+
yield Subscription.from_json(item)
112+
113+
def get_stream_contents(self, stream_id, c=''):
114+
while True:
115+
articles, c = self.__get_stream_contents(stream_id, c)
116+
for a in articles:
117+
yield Article.from_json(a)
118+
if c is None:
119+
break
120+
121+
def __get_stream_contents(self, stream_id, continuation=''):
122+
if not self.auth_token:
123+
raise NotLoginError
124+
125+
url = urljoin(BASE_URL, 'stream/contents/' + quote_plus(stream_id))
126+
params = {
127+
'n': 50, # default 20, max 1000
128+
'r': '',
129+
'c': continuation,
130+
'output': 'json'
131+
}
132+
resp = self.session.post(url, params=params)
133+
if resp.status_code != 200:
134+
raise APIError(resp.text)
135+
136+
if 'continuation' in resp.json():
137+
return resp.json()['items'], resp.json()['continuation']
138+
else:
139+
return resp.json()['items'], None
140+
100141
def fetch_unread(self, folder=None, tags=None):
101142
if not self.auth_token:
102143
raise NotLoginError

inoreader/subscription.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
5+
class Subscription(object):
6+
def __init__(self, id, title, categories,
7+
sortid, firstitemmsec, url, htmlUrl, iconUrl):
8+
self.id = id
9+
self.title = title
10+
self.categories = categories
11+
self.sortid = sortid
12+
self.firstitemmsec = firstitemmsec
13+
self.url = url
14+
self.htmlUrl = htmlUrl
15+
self.iconUrl = iconUrl
16+
17+
@classmethod
18+
def from_json(cls, data):
19+
subscription_info = {
20+
'id': data['id'],
21+
'title': data['title'],
22+
'categories': [item for item in data['categories']],
23+
'sortid': data['sortid'],
24+
'firstitemmsec': data['firstitemmsec'],
25+
'url': data['url'],
26+
'htmlUrl': data['htmlUrl'],
27+
'iconUrl': data['iconUrl']
28+
}
29+
return cls(**subscription_info)

0 commit comments

Comments
 (0)