start of writing code to download and write DOAB covers to local file storage
parent
f40350c868
commit
ce05d4e5ba
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:c352661b24fd347f5d7ec95e8931373d1be8d54bb1a5fd638e58413916ccadef"
|
||||
"signature": "sha256:c124c7b321845a9c3a2e8dd2fa376f604a42da2230625a4beae73249e4329621"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -452,6 +452,7 @@
|
|||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# the code in this cell will write links to doabooks.org\n",
|
||||
"# http://www.doabooks.org/doab?func=cover&rid=12592\n",
|
||||
"\n",
|
||||
"def update_cover_doab(doab_id):\n",
|
||||
|
@ -459,11 +460,7 @@
|
|||
" edition = work.preferred_edition\n",
|
||||
" edition.cover_image = \"http://www.doabooks.org/doab?func=cover&rid={0}\".format(doab_id)\n",
|
||||
" edition.save()\n",
|
||||
" return work\n",
|
||||
"\n",
|
||||
"for d in no_google_book_id:\n",
|
||||
" work = update_cover_doab(d['doab_id'])\n",
|
||||
" print work.id, work.cover_image_small()\n"
|
||||
" return work"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -473,11 +470,46 @@
|
|||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# hmmm...just because there is a google book id doesn't mean there's a good cover...\n",
|
||||
"# maybe I should check on those cases and add the doab cover if no google cover\n",
|
||||
"# NEXT STEP\n",
|
||||
"# Eric is advocating another approach\n",
|
||||
"# https://github.com/Gluejar/regluit/pull/363#issuecomment-48373487\n",
|
||||
"# \"I would retrieve the doab cover and re-serve it.\"\n",
|
||||
"\n",
|
||||
"work = Work.objects.get(id='138980')\n",
|
||||
"work.cover_image_small()"
|
||||
"# based on \n",
|
||||
"# https://github.com/Gluejar/regluit/blob/420cbdf448ef744ed2a2ab45f279f6bdddc14ca8/frontend/views.py#L609\n",
|
||||
"\n",
|
||||
"from django.core.files.storage import default_storage\n",
|
||||
"from StringIO import StringIO\n",
|
||||
"import requests\n",
|
||||
"\n",
|
||||
"def update_cover_doab_2(doab_id):\n",
|
||||
" work = Identifier.objects.get(type='doab', value=doab_id).work\n",
|
||||
" edition = work.preferred_edition\n",
|
||||
"\n",
|
||||
" url = \"http://www.doabooks.org/doab?func=cover&rid={0}\".format(doab_id)\n",
|
||||
" r = requests.get(url)\n",
|
||||
" cover_file = StringIO(r.content)\n",
|
||||
" \n",
|
||||
" cover_file_name= '/Users/%s/covers/%s/doab_%s' % (\"RaymondYee\", edition.pk, doab_id)\n",
|
||||
" file = default_storage.open(cover_file_name, 'w')\n",
|
||||
" file.write(cover_file.read())\n",
|
||||
" file.close()\n",
|
||||
" #and put its url into cover_image\n",
|
||||
" edition.cover_image = default_storage.url(cover_file_name)\n",
|
||||
" edition.save()\n",
|
||||
" return edition\n"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"for d in no_google_book_id:\n",
|
||||
" work = update_cover_doab(d['doab_id'])\n",
|
||||
" print work.id, work.cover_image_small()"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
|
Loading…
Reference in New Issue