本文整理汇总了Python中pocket.Pocket.archive方法的典型用法代码示例。如果您正苦于以下问题:Python Pocket.archive方法的具体用法?Python Pocket.archive怎么用?Python Pocket.archive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocket.Pocket
的用法示例。
在下文中一共展示了Pocket.archive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: archive_item
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import archive [as 别名]
def archive_item(item_id):
access_token = WF.get_password('pocket_access_token')
pocket_instance = Pocket(config.CONSUMER_KEY, access_token)
try:
pocket_instance.archive(item_id, wait=False)
return 'Link archived'
except PocketException:
return 'Connection error'
示例2: __init__
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import archive [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
)
#.........这里部分代码省略.........