Created
April 24, 2012 09:50
-
-
Save rikva/2478460 to your computer and use it in GitHub Desktop.
Simpel Python script om de huidige NRC Next PDF te downloaden en te openen (voor NRC Next abonnees)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from sys import argv, exc_info | |
from mechanize import Browser | |
from datetime import datetime | |
from subprocess import call | |
pdfreader = '/usr/bin/okular' | |
if len(argv) == 3: | |
try: | |
datestring = datetime.now().strftime('%Y%m%d') | |
br = Browser() | |
br.open('https://login.nrc.nl/login?service=http://digitaleeditie.nrc.nl/digitaleeditie/') | |
br.select_form(nr=0) | |
br['username'], br['password'] = argv[1], argv[2] | |
br.submit() | |
print 'Retrieving PDF file ...' | |
pdffile = br.retrieve('http://digitaleeditie.nrc.nl/digitaleeditie/helekrant/fullpdf/%s_NRC_Next.pdf' % datestring)[0] | |
call([pdfreader, pdffile]) | |
except: | |
print "ERROR: %s" % exc_info()[1] | |
else: | |
print 'USAGE: python file.py <username> <password>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simply removing ?service=http://digitaleeditie.nrc.nl/digitaleeditie/ from the br.open() command dit the trick...