Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more functions #2

Merged
merged 2 commits into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ ENV/

# Spyder project settings
.spyderproject
.idea/*
41 changes: 41 additions & 0 deletions inoreader/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .consts import BASE_URL, LOGIN_URL
from .exception import NotLoginError, APIError
from .article import Article
from .subscription import Subscription


class InoreaderClient(object):
Expand Down Expand Up @@ -97,6 +98,46 @@ def get_tags(self):
tags.sort(key=itemgetter('name'))
return tags

def get_subscription_list(self):
if not self.auth_token:
raise NotLoginError

url = urljoin(BASE_URL, 'subscription/list')
resp = self.session.get(url)
if resp.status_code != 200:
raise APIError(resp.text)

for item in resp.json()['subscriptions']:
yield Subscription.from_json(item)

def get_stream_contents(self, stream_id, c=''):
while True:
articles, c = self.__get_stream_contents(stream_id, c)
for a in articles:
yield Article.from_json(a)
if c is None:
break

def __get_stream_contents(self, stream_id, continuation=''):
if not self.auth_token:
raise NotLoginError

url = urljoin(BASE_URL, 'stream/contents/' + quote_plus(stream_id))
params = {
'n': 50, # default 20, max 1000
'r': '',
'c': continuation,
'output': 'json'
}
resp = self.session.post(url, params=params)
if resp.status_code != 200:
raise APIError(resp.text)

if 'continuation' in resp.json():
return resp.json()['items'], resp.json()['continuation']
else:
return resp.json()['items'], None

def fetch_unread(self, folder=None, tags=None):
if not self.auth_token:
raise NotLoginError
Expand Down
29 changes: 29 additions & 0 deletions inoreader/subscription.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


class Subscription(object):
def __init__(self, id, title, categories,
sortid, firstitemmsec, url, htmlUrl, iconUrl):
self.id = id
self.title = title
self.categories = categories
self.sortid = sortid
self.firstitemmsec = firstitemmsec
self.url = url
self.htmlUrl = htmlUrl
self.iconUrl = iconUrl

@classmethod
def from_json(cls, data):
subscription_info = {
'id': data['id'],
'title': data['title'],
'categories': [item for item in data['categories']],
'sortid': data['sortid'],
'firstitemmsec': data['firstitemmsec'],
'url': data['url'],
'htmlUrl': data['htmlUrl'],
'iconUrl': data['iconUrl']
}
return cls(**subscription_info)