-
-
Save leafnode/4441994 to your computer and use it in GitHub Desktop.
Fetch all books from Wolne Lektury
This file contains 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
import simplejson, requests, urllib, re | |
# -*- encoding: utf-8 -*- | |
from slughifi import slughifi | |
### http://trac.django-fr.org/browser/site/trunk/project/links/slughifi.py?rev=47 | |
### with django's slugify hardcoded inside from: | |
### http://code.activestate.com/recipes/577257/ | |
for z in simplejson.loads(requests.get("http://wolnelektury.pl/api/books/").content.decode('utf8')): | |
p = simplejson.loads(requests.get(z['href']).content) | |
if p['parent'] is None: | |
authorList = z['author'].split(' ') | |
authLen = len(authorList) | |
if authLen > 1: | |
lName = authorList[-1] | |
fNames = ' '.join(authorList[:-1]) | |
author = "%s, %s" % (lName, fNames) | |
else: | |
author = z['author'] | |
slug = slughifi(author+' - '+p['title']) | |
print "Fetching %s by %s (%s) to %s.mobi" % (p['title'], author, p['mobi'], slug) | |
urllib.urlretrieve(p['mobi'], slug + '.mobi') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment