Skip to content

Instantly share code, notes, and snippets.

@sliem sliem/
Created Oct 15, 2011

What would you like to do?
Simple python script to publish an url to the Instapaper service.
#!/usr/bin/env python
import argparse, urllib, sys
def error(msg):
def main():
api = ''
argparser = argparse.ArgumentParser(description='Simple utility to add articles to an Instapaper account.')
argparser.add_argument('url', help='url to add')
argparser.add_argument('-u', '--username', help='account username')
argparser.add_argument('-p', '--password', help='account password')
argparser.add_argument('-t', '--title', default='', help='set title of article manually')
argparser.add_argument('-d', '--description', default='', help='set description')
argparser.add_argument('-v', '--verbose', action='store_true', default=False,
help='increase verbosity')
args = argparser.parse_args()
params = urllib.urlencode({
'username' : args.username,
'password' : args.password,
'url' : args.url,
'title' : args.title,
'selection' : args.description # While wierd the API documentation defines the 'selection'
# parameter an an description of the article.
r = urllib.urlopen(api, params)
status = r.getcode()
if status == 201:
if args.verbose:
print('%s saved as %s' % (r.headers['Content-Location'], r.headers['X-Instapaper-Title']))
elif status == 400:
error('Status 400: Bad request or exceeded the rate limit. Probably missing a required parameter, such as url.')
elif status == 403:
error('Status 403: Invalid username or password.')
elif status == 500:
error('Status 500: The service encountered an error. Please try again later')
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.