Skip to content

Commit

Permalink
Print in proper @Article format BibTeX
Browse files Browse the repository at this point in the history
  • Loading branch information
fskinner19 authored May 6, 2021
1 parent 32d3b2f commit f355729
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions notebooks/References Notebook 2020.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"outputs": [],
"source": [
"# BibTeX Reference\n",
"# authors used to be %I\n",
"payload = {\"bibcode\": [\"{}\".format(Bibcode)],\n",
" \"sort\": \"first_author asc\",\n",
" \"format\": \n",
Expand All @@ -308,25 +309,30 @@
" \"volume\": \"%V\",\n",
" \"start-page\": \"%p\",\n",
" \"end-page\": \"%P\",\n",
" \"pages\":\"%pp\",\n",
" \"year\": %Y,\n",
" \"authors\": \"%I\",\n",
" \"author\": \"%A\",\n",
" \"doi\": \"%d\",\n",
" \"key_format\":\"%ZAuthorSep:\" and \"\",\n",
" \"bibcode\": \"%u\"}}'''\n",
" }\n",
"r = requests.post(\"https://api.adsabs.harvard.edu/v1/export/custom\", \\\n",
" headers={\"Authorization\": \"Bearer \" + token, \"Content-type\": \"application/json\"}, \\\n",
" data=json.dumps(payload))\n",
"response_json = r.json() \n",
"ref_json = json.loads(response_json['export'])['ref_json']\n",
"print('authors:', ref_json['authors'])\n",
"print('title:', ref_json['title'])\n",
"print('journal:', ref_json['journal'])\n",
"print('volume:', ref_json['volume'])\n",
"print('start-page:', ref_json['start-page'])\n",
"print('end-page:', ref_json['end-page'])\n",
"print('year:', ref_json['year'])\n",
"print('doi:', ref_json['doi'])\n",
"print('bibcode:', ref_json['bibcode'])\n",
"print(f'@ARTICLE{{{doi},')\n",
"print('\\tauthor=', \"{{{0}}},\".format(ref_json['author']))\n",
"print('\\ttitle=', '\"{{{0}}}\",'.format(ref_json['title']))\n",
"print('\\tjournal=', \"{{{0}}},\".format(ref_json['journal']))\n",
"print('\\tvolume=', \"{{{0}}},\".format(ref_json['volume']))\n",
"print('\\tpages=', \"{{{0}}},\".format(ref_json['pages']))\n",
"#print('\\tstart-page=', '({}),'.format(ref_json['start-page']))\n",
"#print('\\tend-page=', '({}),'.format(ref_json['end-page']))\n",
"print('\\tyear=', \"{{{0}}},\".format(ref_json['year']))\n",
"print('\\tdoi=', \"{{{0}}},\".format(ref_json['doi']))\n",
"print('\\tbibcode=', \"{{{0}}}\".format(ref_json['bibcode']))\n",
"print(\"}\")\n",
"# Note if this gives you an error then please remove \"encoder\": \"%ZEncoding:latex\\\\bibitem\", and enter a \\ before each J, T, V,\n",
"# etc. therefore \"journal\": \"%J\", would be changed to \"journal\": \"%\\J\", thereby encoding the journal name into BibTeX format\n",
"# this error occurs when the bibtex encoder cannot encode a section of the citation."
Expand Down

0 comments on commit f355729

Please sign in to comment.