Skip to content

Instantly share code, notes, and snippets.

@nealrs
Created December 12, 2015 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nealrs/2f23b91b64e40e6f7b9c to your computer and use it in GitHub Desktop.
Save nealrs/2f23b91b64e40e6f7b9c to your computer and use it in GitHub Desktop.
Python script + cron job to add NextDraft articles to your Instagram list every day at 5:05pm
0 5 17 ? * MON-FRI * python ~/path/instadraft.py >> ~/path/instadraft.log
#!/usr/bin/env python
# This script will add every article from the current issue of NextDraft to your Instapaper list. Remember to change the l/p variables (if you don't have a password (you probably don't), you can leave p blank). FYI, NextDraft usually comes out weekdays between 3-4pm ET.
# Hi, I'm Neal (@nealrs on the interwebs). Earlier this week I made a PHP webapp that does this for Pocket (nextdraftpocket.com). And while that's cool, Instapaper's Simple API is stupid easy to use, lot's of people prefer IP, and I figured I could automate this as a cron job anyway. So here we are.
import requests
from lxml import html
from time import strftime
nd = html.fromstring(requests.get('http://nextdraft.com/current').content)
urls = nd.xpath('//div[@class="blurb-content"]/p/a/@href')
l = "foo@bar.baz" # required -- usually your email address
p = "" # optional (most people don't have passwords)
print strftime("%Y-%m-%d %H:%M:%S")+" | Ok "+ l + ", let's do this!"
for u in urls:
print "Adding "+u+" to Instapaper"
r = requests.get('https://www.instapaper.com/api/add?username='+l+'&password='+p+'&url='+u)
print r.content
print strftime("%Y-%m-%d %H:%M:%S")+" | Dunzo."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment