Skip to content

Instantly share code, notes, and snippets.

@nothingrealhappen
Last active January 15, 2019 16:18
Show Gist options
  • Save nothingrealhappen/077d2eea4ce3650f7e0f89986f791af9 to your computer and use it in GitHub Desktop.
Save nothingrealhappen/077d2eea4ce3650f7e0f89986f791af9 to your computer and use it in GitHub Desktop.
org-babel-for-reading-notes

Book info

Reading notes

Favorite quotes

Things to look up

Futher reading

Babel Sourcecode

import urllib2
import json
res = urllib2.urlopen("https://api.douban.com/v2/book/" + str(id)).read()
b = json.loads(res)

def get(dic, names):
  head = names[0]
  tail = names[1-len(names):]
  return dic[head].encode('utf-8') if len(names) == 1 else get(dic[head], tail)

def g(*names):
  return get(b, names)

# download image to relative folder
img = urllib2.urlopen(urllib2.Request(b['images']['small'])).read()
img_name = "%s.jpg" % g('id')
with open (img_name, 'w') as f: f.write(img)

print "[[file:%s]]\n" % img_name
print "title: %s\n" % g('title')
print "subtitle: %s\n" % g('subtitle')
print "rating: %s\n" % g('rating', 'average')
print "publisher: %s\n" % g('publisher')
print "url: %s\n" % g('alt')
print "author: %s\n" % ', '.join(b['author']).encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment