Skip to content

Instantly share code, notes, and snippets.

@leafnode
Forked from anonymous/gist:4356672
Last active Dec 10, 2015
Embed
What would you like to do?
Fetch all books from Wolne Lektury
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