本文整理汇总了Python中pocket.Pocket.retrieve方法的典型用法代码示例。如果您正苦于以下问题:Python Pocket.retrieve方法的具体用法?Python Pocket.retrieve怎么用?Python Pocket.retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocket.Pocket
的用法示例。
在下文中一共展示了Pocket.retrieve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import retrieve [as 别名]
class PocketApp:
DEFAULT_WORDS_PER_MINUTE = 180
REDIRECT_URL = 'http://www.google.com'
def __init__(self):
self._configs = Configs()
self._storage = Storage()
self._pocket = Pocket(
self._configs.get('consumer_key'),
self._configs.get('access_token')
)
def configure(self, consumer_key, access_token,
words_per_minute, sort_field):
self._configs.set('consumer_key', consumer_key)
self._configs.set('access_token', access_token)
self._configs.set('words_per_minute', words_per_minute)
self._configs.set('sort_field', sort_field)
self._configs.set('last_fetch', 0)
self._configs.write()
self._storage.clear()
def get_request_token(self, consumer_key):
return self._pocket.get_request_token(
consumer_key, self.REDIRECT_URL
)
def get_access_token(self, consumer_key, request_token):
return self._pocket.get_access_token(
consumer_key, request_token
)
def add_article(self, url, title=None, tags=None):
if isinstance(tags, tuple):
tags = ','.join(list(tags))
try:
return self._pocket.add(url, title, tags)
except PocketException as e:
raise_from(self._check_exception(e), e)
def get_articles(self, limit=None, order=None):
if self._storage.is_empty():
self.fetch_articles(True)
articles = self._storage.read(limit, order)
sort_field = self._configs.get('sort_field')
if not sort_field:
sort_field = 'reading_time'
articles = sorted(articles,
key=itemgetter(sort_field))
return articles
def search(self, search, state, tag, sort):
try:
articles = self._pocket.retrieve(search=search,
state=state,
tag=tag,
sort=sort)
return self._get_articles_index(articles)
except PocketException as e:
raise_from(self._check_exception(e), e)
def archive_article(self, item_id):
try:
self._pocket.archive(int(item_id)).commit()
except PocketException as e:
raise_from(self._check_exception(e), e)
def find_article(self, item_id):
index = self._storage.read()
for article in index:
if str(article['id']) == str(item_id):
return article
return None
def fetch_articles(self, output_progress=False):
spinner = None
if output_progress:
spinner = Spinner('Loading articles ')
articles_index = []
last_fetch = self._configs.get('last_fetch')
offset = 0
count = 20
while(True):
try:
articles = self._pocket.retrieve(
state='unread',
count=count,
offset=offset,
since=last_fetch
)
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import retrieve [as 别名]
class PocketAPI:
""" Wrapper around https://pypi.python.org/pypi/pocket-api/ """
def __init__(self, consumer_key=None, access_token=None):
self.consumer_key = consumer_key
self.access_token = access_token
def get_request_token(self):
""" Get request token: https://getpocket.com/developer/docs/authentication """
headers = {
'content-type': 'application/json; charset=UTF-8',
'x-accept': 'application/json'
}
data = {
'consumer_key': self.consumer_key,
'redirect_uri': 'https://getpocket.com/v3/oauth/authorize'
}
pocket_api = requests.post(
'https://getpocket.com/v3/oauth/request',
data=json.dumps(data),
headers=headers
)
r = json.loads(pocket_api.text)
return r['code']
def get_access_token(self, request_token):
""" Get access token: https://getpocket.com/developer/docs/authentication """
headers = {
'content-type': 'application/json; charset=UTF-8',
'x-accept': 'application/json'
}
data = {
'consumer_key': self.consumer_key,
'code': request_token
}
pocket_api = requests.post(
'https://getpocket.com/v3/oauth/authorize',
data=json.dumps(data),
headers=headers
)
r = json.loads(pocket_api.text)
return r['access_token']
def connect(self):
""" Connect to the getpocket API and initiate python api """
# If access token is already provided skip this one
if not self.access_token:
# Get request token
self.request_token = self.get_request_token()
print("[*] Request token: %s" % self.request_token)
print("Now you need to authorize this app to access your getpocket list.")
print("Open this URL in your browser: https://getpocket.com/auth/authorize?request_token=%s&redirect_uri=https://getpocket.com" % self.request_token)
input("Press Enter to continue...")
# Get access token
self.access_token = self.get_access_token(self.request_token)
print("[*] Access token: %s" % self.access_token)
# Create pocket-api
self.p = Pocket(
consumer_key=self.consumer_key,
access_token=self.access_token
)
def get(self, **kwargs):
""" Fetch list of articles """
# Fetch a list of articles
try:
return self.p.retrieve(**kwargs)
except PocketException as e:
print(e.message)
return None