当前位置: 首页>>代码示例>>Python>>正文


Python Pocket.archive方法代码示例

本文整理汇总了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'
开发者ID:hbcbh1999,项目名称:alfred-pocket,代码行数:10,代码来源:pocket_launcher.py

示例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
                )
#.........这里部分代码省略.........
开发者ID:jean,项目名称:pocket-cli,代码行数:103,代码来源:app.py


注:本文中的pocket.Pocket.archive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。