Wolph

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 🙂

Exit mobile version