Batch adding data to Pocket

For some reason I do not understand, Pocket seems to have no support for batch adding articles to the reading list. After looking around quite a bit it doesn’t even seem possible to get a simple add url so you can add them with a little batch script…

Since I still wanted to have my articles added I have written a little script to do so. It requires the Pocket library (pip install pocket) and works out of the box beyond that.

Save as add_to_pocket.py and make sure you replace the consumer_key in the code. You can get the key from http://getpocket.com/developer/apps/new
[python]#!/usr/bin/env python

import sys
from pocket import Pocket

consumer_key = ‘18520-5994fa9c319241166deaf6b4′

request_token = Pocket.get_request_token(
consumer_key=consumer_key,
redirect_uri=’http://wol.ph/’,
)

auth_url = Pocket.get_auth_url(
code=request_token,
redirect_uri=’http://wol.ph/’,
)
print(‘Please authorize the app using the following url and press ENTER here’)
print(auth_url)
input()

access_token = Pocket.get_access_token(
consumer_key=consumer_key,
code=request_token,
)
print(‘Got authenticated request token’)
print(request_token)

def add_url(url):
print(‘adding’, url)
print(pocket_instance.add(url=url))

pocket_instance = Pocket(consumer_key, access_token)
for arg in sys.argv[1:]:
if arg.startswith(‘http’):
add_url(arg)
else:
print(‘Reading urls from %r’ % arg)
for line in open(arg):
add_url(line)
[/python]

Usage is quite simple:
[bash]python add_to_pocket.py http://w.wol.ph/2013/09/18/batch-adding-data-to-pocket/[/bash]

Or if you have a list of urls:
[bash]python add_to_pocket.py urls.txt[/bash]

If people are interested I can make it into a web-app, but for the time being it solved my issue 🙂

Bookmark and Share

Tags:

About Rick van Hattem

Rick van Hattem is a Dutch Internet entrepreneur and co-founder of Fashiolista.com

10 Responses to “Batch adding data to Pocket”

  1. Michael | 2013-11-01 at 14:28:29 #

    I can’t believe they don’t have this available somewhere in the interface…

  2. Paul | 2013-12-23 at 04:17:00 #

    Hi there,

    I tried your code, but got some error message that I don’t really understand. Can you help please? Thanks.

    Here is the error message from the terminal.

    Traceback (most recent call last):
    File “add_to_pocket.py”, line 23, in
    code=request_token,
    File “/Library/Python/2.7/site-packages/pocket.py”, line 326, in get_access_token
    return cls._make_request(url, payload, headers)[0][‘access_token’]
    File “/Library/Python/2.7/site-packages/pocket.py”, line 141, in _make_request
    ‘%s. %s’ % (error_msg, extra_info)
    pocket.RateLimitException: User was authenticated, but access denied due to lack of permission or rate limiting. User rejected code.

    • Anirudh | 2014-12-11 at 16:09:06 #

      Hey Paul. I think you haven’t created a consumer key and a request token. The code doesn’t work directly. You’re supposed to add your credentials, if you haven’t already.

    • Ethan | 2014-12-22 at 19:33:06 #

      Did you ever get this sorted out, Paul?

  3. wolph | 2013-12-31 at 03:40:12 #

    @Paul: as the error states, you are being rate limited. Ido not know what the limits are but I assumed there would be some. Just try again after a few hours.

  4. Chris Combs | 2014-03-03 at 19:37:04 #

    Hey, thanks!

    To any other python noobs out there, don’t try to save this as “pocket.py”… oops. That makes it try to import itself.

  5. Ethan | 2014-12-22 at 19:31:51 #

    I’m having the same error as Paul with this code, but the rate limit business makes zero sense to me, as I have added nothing with the script yet!

    • Rick van Hattem | 2015-01-28 at 19:37:49 #

      Hi Ethan, I’ve just tried to create a new application through the developer apps site and added the consumer-key in the code and it works like a charm for me.

      Perhaps the difference is in the checkboxes when creating the app. When creating the app (http://getpocket.com/developer/apps/new) I checked the following:
      Permissions: add
      Platforms: Desktop (other)

      Let me know if you have more problems, you can also mail me at wolph[at]wol.ph

  6. Zuzana | 2019-09-25 at 18:17:42 #

    Hi, I used your code to create my own version of adding new links to my pocket, which I intend to run automatically on a weekly basis. But I wonder – is there a way how to authorize my app automatically without manual confirmation?

    • Rick van Hattem | 2019-09-25 at 18:54:23 #

      If you store the request_token instead of requesting it every time you can skip the authentication

Leave a Reply