|
14 | 14 | from .consts import BASE_URL, LOGIN_URL |
15 | 15 | from .exception import NotLoginError, APIError |
16 | 16 | from .article import Article |
| 17 | +from .subscription import Subscription |
17 | 18 |
|
18 | 19 |
|
19 | 20 | class InoreaderClient(object): |
@@ -97,6 +98,44 @@ def get_tags(self): |
97 | 98 | tags.sort(key=itemgetter('name')) |
98 | 99 | return tags |
99 | 100 |
|
| 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): |
| 114 | + c = '' |
| 115 | + while True: |
| 116 | + articles, c = self.__get_stream_contents(stream_id, c) |
| 117 | + for a in articles: |
| 118 | + yield Article.from_json(a) |
| 119 | + if c is None: |
| 120 | + break |
| 121 | + |
| 122 | + def __get_stream_contents(self, stream_id, continuation=''): |
| 123 | + if not self.auth_token: |
| 124 | + raise NotLoginError |
| 125 | + |
| 126 | + url = urljoin(BASE_URL, 'stream/contents/' + quote_plus(stream_id)) |
| 127 | + params = { |
| 128 | + 'n': 50, # default 20, max 1000 |
| 129 | + 'r': '', |
| 130 | + 'c': continuation, |
| 131 | + 'output': 'json' |
| 132 | + } |
| 133 | + resp = self.session.post(url, params=params) |
| 134 | + if resp.status_code != 200: |
| 135 | + raise APIError(resp.text) |
| 136 | + |
| 137 | + return resp.json()['items'], resp.json()['continuation'] |
| 138 | + |
100 | 139 | def fetch_unread(self, folder=None, tags=None): |
101 | 140 | if not self.auth_token: |
102 | 141 | raise NotLoginError |
|
0 commit comments