python pocket.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python pocket.py相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python

"""
Saves URL(s) to a user's Pocket queue.
It accepts either command line arguments or a URL from the OS X clipboard.
For information about Pocket see http://getpocket.com/
"""

import optparse
import subprocess
import urllib
import urllib2


# Fill these variable in with your own Pocket credentials.
POCKET_APIKEY = '<apikey>'
POCKET_USERNAME = '<username>'
POCKET_PASSWORD = '<password>'


def save_url(url, username=POCKET_USERNAME, password=POCKET_PASSWORD,
             apikey=POCKET_APIKEY, verbose=False):
    """Saves a URL to a user's Pocket queue."""
    params = dict(url=url, username=username, password=password, apikey=apikey)
    payload = urllib.urlencode(params)
    urllib2.urlopen('https://readitlaterlist.com/v2/add', payload)

    if verbose:
        print 'Saved URL: %s' % url


if __name__ == '__main__':
    parser = optparse.OptionParser()
    parser.add_option('-c', action='store_true', dest='clipboard',
                      help='save a URL from the clipboard')
    parser.add_option('-v', action='store_true', dest='verbose', default=True,
                      help='show status of URL save')
    (options, args) = parser.parse_args()

    # Save URLs supplied as command line arguments.
    for arg in args:
        save_url(arg, verbose=options.verbose)

    # Save URL from clipboard, if specified.
    if options.clipboard:
        clipboard = subprocess.check_output('pbpaste')
        save_url(clipboard, verbose=options.verbose)

以上是关于python pocket.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python