diff --git a/notebooks/References Notebook.ipynb b/notebooks/References Notebook.ipynb index 65d72f1..1dcadb0 100644 --- a/notebooks/References Notebook.ipynb +++ b/notebooks/References Notebook.ipynb @@ -1,5 +1,25 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Copyright 2019 Frances M. Skinner\n", + "SPDX-License-Identifier: Apache-2.0\n", + "\n", + "Licensed under the Apache License, Version 2.0 (the \"License\");\n", + "you may not use this file except in compliance with the License.\n", + "You may obtain a copy of the License at\n", + "\n", + " https://www.apache.org/licenses/LICENSE-2.0\n", + "\n", + "Unless required by applicable law or agreed to in writing, software\n", + "distributed under the License is distributed on an \"AS IS\" BASIS,\n", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", + "See the License for the specific language governing permissions and\n", + "limitations under the License." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -9,23 +29,20 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "# Import these modules\n", - "\n", "# Step 2 Bibcode\n", "import requests\n", "import json\n", - "\n", + "# ADS\n", "# Step 4 urllib\n", "import urllib.request\n", "from urllib.error import HTTPError\n", - "\n", "#Step 5 html encoder\n", "import html\n", - "\n", "# Step 6 bibtex\n", "import re\n", "import logging\n", @@ -68,12 +85,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ - "# Enter your token here: You need this for using step 3\n", - "# This is where the token goes, between the \"\" \n", + "# Enter your token here: You need this for using step 2 and 3\n", + "# A token can only be used once you have an account on NASA/ADS https://ui.adsabs.harvard.edu/. \n", + "# Once you have an account click on 'Account', then click on 'Customize Settings' on the dropdown menu. \n", + "# In 'Customize Settings' there is a panel to the left of the screen, if you scroll down that panel you will see 'API Token'. \n", + "# Click on 'API Token' and then click on 'generate a new key'.\n", + "# you can also enter your token in the local settings and Import ADS_TOKEN from local_settings\n", "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"" ] }, @@ -86,9 +107,18 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 99, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter DOI Here: 10.1016/j.jqsrt.2019.04.040\n", + "2019JQSRT.232...35H\n" + ] + } + ], "source": [ "def get_citeproc_authors(cpd_author):\n", " if cpd_author is None:\n", @@ -112,7 +142,6 @@ " initials = ' '.join(initials)\n", " names.append('{} {}'.format(initials, family))\n", " return ', '.join(names)\n", - "\n", "def parse_citeproc_json(citeproc_json):\n", " \"\"\"Parse the provided JSON into a Ref object.\"\"\"\n", " \n", @@ -122,7 +151,6 @@ " return None\n", " except KeyError:\n", " return None\n", - "\n", " authors = get_citeproc_authors(cpd.get('author', ''))\n", " title = cpd.get('title', '').replace('\\n', '')\n", " journal = cpd.get('container-title', '')\n", @@ -136,13 +164,11 @@ " try:\n", " year = cpd['issued']['date-parts'][0][0]\n", " except (KeyError, IndexError):\n", - " year = None\n", - " \n", + " year = None \n", " try:\n", " bibcode = cpd.get('bibcode', '')\n", " except (KeyError, IndexError):\n", - " bibcode = None\n", - " \n", + " bibcode = None \n", "# # =============================================================================\n", "# # OUTPUT\n", "# # =============================================================================\n", @@ -158,7 +184,6 @@ " article_number,\n", " citeproc_json]\n", " return ref \n", - "\n", "def get_citeproc_json_from_doi(doi):\n", " base_url = 'http://dx.doi.org/'\n", " url = base_url + doi\n", @@ -172,81 +197,21 @@ " raise ValueError('DOI not found.')\n", " raise\n", " return citeproc_json\n", - "\n", "def get_source_from_doi(doi):\n", " citeproc_json = get_citeproc_json_from_doi(doi)\n", " ref = parse_citeproc_json(citeproc_json)\n", - " return ref" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter DOI Here: fwejf\n" - ] - }, - { - "ename": "ValueError", - "evalue": "DOI not found.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mHTTPError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36mget_citeproc_json_from_doi\u001b[0;34m(doi)\u001b[0m\n\u001b[1;32m 75\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 76\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0murllib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0murlopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 77\u001b[0m \u001b[0mciteproc_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36murlopen\u001b[0;34m(url, data, timeout, cafile, capath, cadefault, context)\u001b[0m\n\u001b[1;32m 222\u001b[0m \u001b[0mopener\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_opener\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 223\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mopener\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 224\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, fullurl, data, timeout)\u001b[0m\n\u001b[1;32m 531\u001b[0m \u001b[0mmeth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprocessor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 532\u001b[0;31m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmeth\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 533\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36mhttp_response\u001b[0;34m(self, request, response)\u001b[0m\n\u001b[1;32m 641\u001b[0m response = self.parent.error(\n\u001b[0;32m--> 642\u001b[0;31m 'http', request, response, code, msg, hdrs)\n\u001b[0m\u001b[1;32m 643\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36merror\u001b[0;34m(self, proto, *args)\u001b[0m\n\u001b[1;32m 563\u001b[0m \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mproto\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 564\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_chain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 565\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36m_call_chain\u001b[0;34m(self, chain, kind, meth_name, *args)\u001b[0m\n\u001b[1;32m 503\u001b[0m \u001b[0mfunc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhandler\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 504\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 505\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36mhttp_error_302\u001b[0;34m(self, req, fp, code, msg, headers)\u001b[0m\n\u001b[1;32m 755\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 756\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparent\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 757\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, fullurl, data, timeout)\u001b[0m\n\u001b[1;32m 531\u001b[0m \u001b[0mmeth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprocessor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 532\u001b[0;31m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmeth\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 533\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36mhttp_response\u001b[0;34m(self, request, response)\u001b[0m\n\u001b[1;32m 641\u001b[0m response = self.parent.error(\n\u001b[0;32m--> 642\u001b[0;31m 'http', request, response, code, msg, hdrs)\n\u001b[0m\u001b[1;32m 643\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36merror\u001b[0;34m(self, proto, *args)\u001b[0m\n\u001b[1;32m 569\u001b[0m \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'default'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'http_error_default'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0morig_args\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 570\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_chain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 571\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36m_call_chain\u001b[0;34m(self, chain, kind, meth_name, *args)\u001b[0m\n\u001b[1;32m 503\u001b[0m \u001b[0mfunc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhandler\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 504\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 505\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/urllib/request.py\u001b[0m in \u001b[0;36mhttp_error_default\u001b[0;34m(self, req, fp, code, msg, hdrs)\u001b[0m\n\u001b[1;32m 649\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mhttp_error_default\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhdrs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 650\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfull_url\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhdrs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfp\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 651\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mHTTPError\u001b[0m: HTTP Error 404: ", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mdoi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Enter DOI Here: \"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mdoi_fetched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_source_from_doi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdoi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mads_token\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'4PtdkIDyxpjjZ1JDYJ4HI59VXJuJD98tACcrnfPv'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m\u001b[0m in \u001b[0;36mget_source_from_doi\u001b[0;34m(doi)\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_source_from_doi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdoi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 85\u001b[0;31m \u001b[0mciteproc_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_citeproc_json_from_doi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdoi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 86\u001b[0m \u001b[0mref\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparse_citeproc_json\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mciteproc_json\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mref\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m\u001b[0m in \u001b[0;36mget_citeproc_json_from_doi\u001b[0;34m(doi)\u001b[0m\n\u001b[1;32m 78\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mHTTPError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcode\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m404\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 80\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'DOI not found.'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 81\u001b[0m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 82\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mciteproc_json\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mValueError\u001b[0m: DOI not found." - ] - } - ], - "source": [ - "# DOI Example HITRAN Paper: = 10.1016/j.jqsrt.2017.06.038\n", - "# DOI Example Superscript Title: = 10.1103/PhysRevA.85.032515\n", - "# NO, NO2, N2O PAPER: = 10.1016/j.jqsrt.2019.04.040\n", - "# EAMON H2O 2020 PAPER: = 10.1016/j.jqsrt.2019.106711\n", - "\n", + " return ref\n", "doi = input(\"Enter DOI Here: \")\n", "doi_fetched = get_source_from_doi(doi)\n", - "\n", - "ads_token = '4PtdkIDyxpjjZ1JDYJ4HI59VXJuJD98tACcrnfPv'\n", - "token = ads_token\n", - "\n", "rdoi = doi\n", - "\n", "rdoi_bs = rdoi.replace(\"\\\\\", \"%2F\") # Remove backslash and replace with URL code for backslash\n", "rdoi_fs = rdoi_bs.replace(\"/\", \"%2F\") # Remove forwardslash and replace with URL code for backslash\n", - "\n", "rurl = requests.get(\"https://api.adsabs.harvard.edu/v1/search/query?q=doi:\"+rdoi_fs,\\\n", " params={\"q\":\"*:*\", \"fl\": \"*\", \"rows\":2000},\n", " headers={'Authorization': 'Bearer ' + token})\n", - "\n", "todos = json.loads(rurl.text)\n", "todos_response = todos.get('response', '')\n", - "\n", - "#Bibcode = (todos_response['docs']['bibcode'])\n", "Bibcode = (todos_response['docs'][0]['bibcode']) \n", - "\n", "print(Bibcode)" ] }, @@ -291,9 +256,25 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 100, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "authors: Hargreaves, R. J., I. E. Gordon, L. S. Rothman, S. A. Tashkun, V. I. Perevalov, A. A. Lukashevskaya, S. N. Yurchenko, J. Tennyson, and H. S. P. Müller\n", + "title: Spectroscopic line parameters of NO, NO2, and N2O for the HITEMP database\n", + "journal: Journal of Quantitative Spectroscopy and Radiative Transfer\n", + "volume: 232\n", + "start-page: 35\n", + "end-page: 53\n", + "year: 2019\n", + "doi: 10.1016/j.jqsrt.2019.04.040\n", + "bibcode: https://ui.adsabs.harvard.edu/abs/2019JQSRT.232...35H\n" + ] + } + ], "source": [ "# HTML with the characters &, <, >, and “ included\n", "payload = {\"bibcode\": [\"{}\".format(Bibcode)], # 2012PhRvA..85c2515Z\n", @@ -313,32 +294,8 @@ " 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']" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "authors: Ulenikov, O. N., E. S. Bekhtereva, O. V. Gromova, K. B. Berezkin, V.-M. Horneman, C. Sydow, C. Maul, and S. Bauerecker\n", - "title: First high resolution analysis of the 3ν2 and 3ν22 bands of 32S16O2\n", - "journal: Journal of Quantitative Spectroscopy and Radiative Transfer\n", - "volume: 202\n", - "start-page: 1\n", - "end-page: 5\n", - "year: 2017\n", - "doi: 10.1016/j.jqsrt.2017.07.012\n", - "bibcode: https://ui.adsabs.harvard.edu/abs/2017JQSRT.202....1U\n" - ] - } - ], - "source": [ - "authors = print('authors:', ref_json['authors'])\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", @@ -358,21 +315,22 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 101, "metadata": {}, "outputs": [ { - "ename": "JSONDecodeError", - "evalue": "Invalid \\escape: line 2 column 65 (char 101)", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mJSONDecodeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 18\u001b[0m data=json.dumps(payload))\n\u001b[1;32m 19\u001b[0m \u001b[0mresponse_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 20\u001b[0;31m \u001b[0mref_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse_json\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'export'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'ref_json'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/json/__init__.py\u001b[0m in \u001b[0;36mloads\u001b[0;34m(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m 352\u001b[0m \u001b[0mparse_int\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mparse_float\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mand\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 353\u001b[0m parse_constant is None and object_pairs_hook is None and not kw):\n\u001b[0;32m--> 354\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_default_decoder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 355\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcls\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 356\u001b[0m \u001b[0mcls\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mJSONDecoder\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/json/decoder.py\u001b[0m in \u001b[0;36mdecode\u001b[0;34m(self, s, _w)\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 338\u001b[0m \"\"\"\n\u001b[0;32m--> 339\u001b[0;31m \u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mraw_decode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0midx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m_w\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 340\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_w\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mend\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 341\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/anaconda/envs/pyref/lib/python3.6/json/decoder.py\u001b[0m in \u001b[0;36mraw_decode\u001b[0;34m(self, s, idx)\u001b[0m\n\u001b[1;32m 353\u001b[0m \"\"\"\n\u001b[1;32m 354\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 355\u001b[0;31m \u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscan_once\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0midx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 356\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 357\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mJSONDecodeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Expecting value\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mJSONDecodeError\u001b[0m: Invalid \\escape: line 2 column 65 (char 101)" + "name": "stdout", + "output_type": "stream", + "text": [ + "authors: Hargreaves, R.~J., I.~E. Gordon, L.~S. Rothman, S.~A. Tashkun, V.~I. Perevalov, A.~A. Lukashevskaya, S.~N. Yurchenko, J. Tennyson, and H.~S.~P. M{\"u}ller\n", + "title: Spectroscopic line parameters of NO, NO$_{2}$, and N$_{2}$O for the HITEMP database\n", + "journal: Journal of Quantitative Spectroscopy and Radiative Transfer\n", + "volume: 232\n", + "start-page: 35\n", + "end-page: 53\n", + "year: 2019\n", + "doi: 10.1016/j.jqsrt.2019.04.040\n", + "bibcode: https://ui.adsabs.harvard.edu/abs/2019JQSRT.232...35H\n" ] } ], @@ -382,8 +340,8 @@ " \"sort\": \"first_author asc\",\n", " \"format\": \n", " '''{\"ref_json\": {\"encoder\": \"%ZEncoding:latex\\\\bibitem\",\n", - " \"title\": \"%T\",\n", " \"journal\": \"%J\",\n", + " \"title\": \"%T\",\n", " \"volume\": \"%V\",\n", " \"start-page\": \"%p\",\n", " \"end-page\": \"%P\",\n", @@ -395,16 +353,8 @@ "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']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "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", @@ -425,9 +375,25 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 102, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "authors: Hargreaves, R. J., I. E. Gordon, L. S. Rothman, S. A. Tashkun, V. I. Perevalov, A. A. Lukashevskaya, S. N. Yurchenko, J. Tennyson, and H. S. P. Müller\n", + "title: Spectroscopic line parameters of NO, NO<SUB>2</SUB>, and N<SUB>2</SUB>O for the HITEMP database\n", + "journal: Journal of Quantitative Spectroscopy and Radiative Transfer\n", + "volume: 232\n", + "start-page: 35\n", + "end-page: 53\n", + "year: 2019\n", + "doi: 10.1016/j.jqsrt.2019.04.040\n", + "bibcode: https://ui.adsabs.harvard.edu/abs/2019JQSRT.232...35H\n" + ] + } + ], "source": [ "# HTML with the characters &, <, >, and “ are converted to &, <, >, and ", respectively.\n", "payload = {\"bibcode\": [\"{}\".format(Bibcode)],\n", @@ -448,31 +414,7 @@ " 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']" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "authors: Ulenikov, O. N., E. S. Bekhtereva, O. V. Gromova, K. B. Berezkin, V.-M. Horneman, C. Sydow, C. Maul, and S. Bauerecker\n", - "title: First high resolution analysis of the 3ν2 and 3ν22 bands of 32S16O2\n", - "journal: Journal of Quantitative Spectroscopy and Radiative Transfer\n", - "volume: 202\n", - "start-page: 1\n", - "end-page: 5\n", - "year: 2017\n", - "doi: 10.1016/j.jqsrt.2017.07.012\n", - "bibcode: https://ui.adsabs.harvard.edu/abs/2017JQSRT.202....1U\n" - ] - } - ], - "source": [ + "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", @@ -494,22 +436,23 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 103, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Authors: O. Ulenikov, E. Bekhtereva, O. Gromova, K. Berezkin, V. Horneman, C. Sydow, C. Maul, S. Bauerecker \n", - "Title: First high resolution analysis of the 3ν2 and3ν2−ν2bands of 32S16O2 \n", + "Authors: R. J. Hargreaves, I. E. Gordon, L. S. Rothman, S. A. Tashkun, V. I. Perevalov, A. A. Lukashevskaya, S. N. Yurchenko, J. Tennyson, H. S.P. Müller \n", + "Title: Spectroscopic line parameters of NO, NO2, and N2O for the HITEMP database \n", "Journal: Journal of Quantitative Spectroscopy and Radiative Transfer \n", - "Volume: 202 \n", - "Year: 2017 \n", - "Page Start: 1 \n", - "Page End: 5 \n", - "DOI: 10.1016/j.jqsrt.2017.07.012 \n", - "URL: http://dx.doi.org/10.1016/j.jqsrt.2017.07.012 \n" + "Volume: 232 \n", + "Year: 2019 \n", + "Page Start: 35 \n", + "Page End: 53 \n", + "Article Number: \n", + "DOI: 10.1016/j.jqsrt.2019.04.040 \n", + "URL: http://dx.doi.org/10.1016/j.jqsrt.2019.04.040 \n" ] } ], @@ -519,7 +462,7 @@ "\n", "# Below are the parameters for searching your citation\n", "# if you would like to add or change anything then refer to the initial code above to make your changes\n", - "reference = (doi_fetched[0],doi_fetched[1],doi_fetched[2],doi_fetched[3],doi_fetched[4],doi_fetched[5],doi_fetched[6],doi_fetched[7],doi_fetched[8])\n", + "reference = (doi_fetched[0],doi_fetched[1],doi_fetched[2],doi_fetched[3],doi_fetched[4],doi_fetched[5],doi_fetched[6],doi_fetched[7],doi_fetched[8],doi_fetched[9])\n", "\n", "print ('Authors:', doi_fetched[0], '')\n", "print ('Title:', doi_fetched[1], '')\n", @@ -528,6 +471,7 @@ "print ('Year:', doi_fetched[4], '')\n", "print ('Page Start:', doi_fetched[5], '')\n", "print ('Page End:', doi_fetched[6], '')\n", + "print ('Article Number:', doi_fetched[9],'')\n", "print ('DOI:', doi_fetched[7], '')\n", "print ('URL:', doi_fetched[8], '')" ] @@ -542,46 +486,16 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "('Y. Lin, A. V. Akimov', 'Dependence of Nonadiabatic Couplings with Kohn–Sham Orbitals on the Choice of Density Functional: Pure vs Hybrid', 'The Journal of Physical Chemistry A', '120', 2016, '9028', '9041', '10.1021/acs.jpca.6b09660', 'http://dx.doi.org/10.1021/acs.jpca.6b09660')\n" - ] - } - ], - "source": [ - "# This will give you a plain text reference with no html codes\n", - "def escape2(s, quote=True):\n", - " s = s.replace(\"}$\", \"\")\n", - " s = s.replace(\"$^{\", \"\") \n", - " s = s.replace(\"{\", \"\")\n", - " s = s.replace(\"}\", \"\")\n", - " s = s.replace(\"\\\"\", \"\")\n", - " #s = s.replace(\"'\", \"\")\n", - " s = s.replace(\"''\", \"\")\n", - " #s = s.replace(\" \", \"\")\n", - " s = s.replace(\",,\", \"\")\n", - " s = s.replace(\", ,\", \"\")\n", - " return s\n", - "print(escape2(\"{}\".format(reference)))" - ] - }, - { - "cell_type": "code", - "execution_count": 13, + "execution_count": 104, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'('S. Bin Zhang, D. L. Yeager', "Complex-scaled multireference configuration-interaction method to study Be and Be-like cations' (B, C, N, O, Mg) Auger resonances1s2s22p1,3Po", 'Physical Review A', '85', 2012, '', '', '10.1103/physreva.85.032515', 'http://dx.doi.org/10.1103/PhysRevA.85.032515')'" + "'('R. J. Hargreaves, I. E. Gordon, L. S. Rothman, S. A. Tashkun, V. I. Perevalov, A. A. Lukashevskaya, S. N. Yurchenko, J. Tennyson, H. S.P. Müller', 'Spectroscopic line parameters of NO, NO2, and N2O for the HITEMP database', 'Journal of Quantitative Spectroscopy and Radiative Transfer', '232', 2019, '35', '53', '10.1016/j.jqsrt.2019.04.040', 'http://dx.doi.org/10.1016/j.jqsrt.2019.04.040', '')'" ] }, - "execution_count": 13, + "execution_count": 104, "metadata": {}, "output_type": "execute_result" } @@ -603,26 +517,34 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 110, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "@article{tanintroduction,\n", + " title={Introduction of water-vapor broadening parameters and their temperature-dependence exponents into the HITRAN database, Part I: CO2, N2O, CO, CH4, O2, NH3, and H2S},\n", + " author={Tan, Y and Kochanov, RV and Rothman, LS and Gordon, IE},\n", + " journal={Journal of Geophysical Research: Atmospheres},\n", + " publisher={Wiley Online Library}\n", + "}\n" + ] + } + ], "source": [ "\"\"\"Library to query Google Scholar.\n", "Call the method query with a string which contains the full search\n", "string. Query will return a list of citations.\n", "\"\"\"\n", - "\n", "GOOGLE_SCHOLAR_URL = \"https://scholar.google.com\"\n", "HEADERS = {'User-Agent': 'Mozilla/5.0'}\n", - "\n", "FORMAT_BIBTEX = 4\n", "FORMAT_ENDNOTE = 3\n", "FORMAT_REFMAN = 2\n", "FORMAT_WENXIANWANG = 5\n", - "\n", - "\n", "logger = logging.getLogger(__name__)\n", - "\n", "# we are using query in our code\n", "def query(searchstr, outformat=FORMAT_BIBTEX, allresults=False):\n", " \"\"\"Query google scholar.\n", @@ -651,7 +573,6 @@ " html = html.decode('utf8')\n", " # grab the links\n", " tmp = get_links(html, outformat)\n", - "\n", " # follow the bibtex links to get the bibtex entries\n", " result = list()\n", " if not allresults:\n", @@ -664,7 +585,6 @@ " bib = bib.decode('utf8')\n", " result.append(bib)\n", " return result\n", - "\n", "def get_links(html, outformat):\n", " \"\"\"Return a list of reference links from the html.\n", " Parameters\n", @@ -689,15 +609,7 @@ " # escape html entities\n", " reflist = [re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:\n", " chr(name2codepoint[m.group(1)]), s) for s in reflist]\n", - " return reflist" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [], - "source": [ + " return reflist\n", "class Bibtex(object):\n", " \"\"\" Convert doi number to bibtex entries.\"\"\"\n", " def __init__(self, doi=None, title=None):\n", @@ -709,35 +621,23 @@ " self.doi = doi\n", " self.title = title\n", " self.bibtex = None\n", - " #if doi:\n", - " #self._edoi = parse.quote(doi)\n", - " #self.url = _base_url + self._edoi # Encoded doi.\n", - " #else:\n", - " #self.url = None\n", "# Beautiful Soup is a Python library for pulling data out of HTML and XML files\n", " def _soupfy(self, url):\n", " \"\"\"Returns a soup object.\"\"\"\n", " html = request.urlopen(url).read()\n", " self.soup = BeautifulSoup(html, 'html.parser')\n", - " return self.soup\n", - " \n", - " \n", + " return self.soup \n", " def getGScholar(self):\n", " \"\"\"Get bibtex entry from doi using Google database.\"\"\"\n", " bib = query(self.doi, 4)[0]\n", " bib = bib.split('\\n') \n", " self.bibtex = '\\n'.join(bib[0:-1]) #-9\n", " return self.bibtex\n", - "\n", "def main(argv=None):\n", " if argv is None:\n", " argv = sys.argv\n", - "\n", - " #args = parse_args(argv[1:])\n", - "\n", " doi = args.positional\n", " method = args.method\n", - "\n", " def allfailed():\n", " \"\"\"All failed message+google try.\"\"\"\n", " bold, reset = \"\\033[1m\", \"\\033[0;0m\"\n", @@ -749,79 +649,12 @@ " \\n{1}\n", " \"\"\".format(url, bib.bibtex)\n", " return msg\n", - "\n", - " bib = Bibtex(doi=doi)" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@article{lin2016dependence,\n", - " title={Dependence of Nonadiabatic Couplings with Kohn--Sham Orbitals on the Choice of Density Functional: Pure vs Hybrid},\n", - " author={Lin, Yuhan and Akimov, Alexey V},\n", - " journal={The Journal of Physical Chemistry A},\n", - " volume={120},\n", - " number={45},\n", - " pages={9028--9041},\n", - " year={2016},\n", - " publisher={ACS Publications}\n", - "}\n" - ] - } - ], - "source": [ + " bib = Bibtex(doi=doi)\n", "doi = '{}'.format(doi) \n", "bib = Bibtex(doi)\n", "bib = bib.getGScholar()\n", "print(bib)" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Authors List Fix\n", - "This last part is in case you would like to change the authors list generated from ADS. ADS provides many options for formatting the authors list but HITRAN has a specific format that ADS does not provide. The next cell fixes the first name from the ADS output to what HITRAN uses" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter First Author Name Here: Akimov, Alexey V\n", - " Alexey V Akimov\n" - ] - } - ], - "source": [ - "#s = \"de Ghellinck d'Elseghem Vaernewijck, X.\"\n", - "#s = \"Zhang, S. B.\"\n", - "#s = \"Zhang-Zow, Sh.\"\n", - "s = input(\"Enter First Author Name Here: \")\n", - "words = s.split(',') \n", - "string =[] \n", - "for word in words: \n", - " string.insert(-1, word) \n", - "print(\" \".join(string)) " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -840,9 +673,10 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 } + diff --git a/pyref/refs/models.py b/pyref/refs/models.py index 165d148..bbdc469 100644 --- a/pyref/refs/models.py +++ b/pyref/refs/models.py @@ -243,7 +243,7 @@ def get_fields_from_bibcode(bibcode, fmt='html'): } r = requests.post('https://api.adsabs.harvard.edu/v1/export/custom', headers={'Authorization': 'Bearer ' + ADS_TOKEN, - 'Content-type': 'application/json'}, \ + 'Content-type': 'application/json'}, data=json.dumps(payload)) response_json = r.json() title = response_json['export'] diff --git a/pyref/refs/tests.py b/pyref/refs/tests.py deleted file mode 100644 index 62357a1..0000000 --- a/pyref/refs/tests.py +++ /dev/null @@ -1,19 +0,0 @@ -from django.test import TestCase - - -class DOIResolveTest(TestCase): - - def test_resolving_doi_populates_add_reference_page(self): - doi = '10.1103/PhysRevA.85.032515' - url = '/refs/resolve/?doi=' + doi - response = self.client.get(url) - - self.assertContains(response, - r'', html=True) - - self.assertContains(response, - r'''''', html=True) - self.assertContains(response, - r'''''', html=True) diff --git a/pyref/refs/tests/test-dois.txt b/pyref/refs/tests/test-dois.txt new file mode 100644 index 0000000..ab5eddb --- /dev/null +++ b/pyref/refs/tests/test-dois.txt @@ -0,0 +1,35 @@ +DOI=10.1103/PhysRevA.85.032515 +JOURNAL=Physical Review A +HTML=Complex-scaled multireference configuration-interaction method to study Be and Be-like cations' (B, C, N, O, Mg) Auger resonances 1s2s<SUP>2</SUP>2p <SUP>1,3</SUP>P<SUP>o</SUP> +LATEX=Complex-scaled multireference configuration-interaction method to study Be and Be-like cations' (B, C, N, O, Mg) Auger resonances 1s2s$^{2}$2p $^{1,3}$P$^{o}$ + +DOI=10.1016/j.jqsrt.2019.04.040 +AUTHORS=R. J. Hargreaves, I. E. Gordon, L. S. Rothman, S. A. Tashkun, V. I. Perevalov, A. A. Lukashevskaya, S. N. Yurchenko, J. Tennyson, H. S.P. Müller +JOURNAL=Journal of Quantitative Spectroscopy and Radiative Transfer +TITLE=Spectroscopic line parameters of NO, NO2, and N2O for the HITEMP database +HTML=Spectroscopic line parameters of NO, NO<SUB>2</SUB>, and N<SUB>2</SUB>O for the HITEMP database +LATEX=Spectroscopic line parameters of NO, NO$_{2}$, and N$_{2}$O for the HITEMP database +VOLUME=232 +PAGE_START=35 +PAGE_END=53 +YEAR=2019 + +DOI=10.1016/j.jqsrt.2019.106711 +HTML=Calculated line lists for H<SUB>2</SUB><SUP>16</SUP>O and H<SUB>2</SUB><SUP>18</SUP>O with extensive comparisons to theoretical and experimental sources including the HITRAN2016 database +LATEX=Calculated line lists for H$_{2}$$^{16}$O and H$_{2}$$^{18}$O with extensive comparisons to theoretical and experimental sources including the HITRAN2016 database +ARTICLE_NUMBER=106711 + +DOI=10.1016/j.jqsrt.2014.07.005 +AUTHORS=D. Golebiowski, X. De Ghellinck D’Elseghem Vaernewijck, M. Herman, J. Vander Auwera, A. Fayt +HTML=High sensitivity (femto-FT-CEAS) spectra of carbonyl sulphide between 6200 and 8200 cm<SUP>-1</SUP>, and new energy pattern in the global rovibrational analysis of <SUP>16</SUP>O<SUP>12</SUP>C<SUP>32</SUP>S +LATEX=High sensitivity (femto-FT-CEAS) spectra of carbonyl sulphide between 6200 and 8200 cm$^{-1}$, and new energy pattern in the global rovibrational analysis of $^{16}$O$^{12}$C$^{32}$S + +DOI=10.1016/j.jqsrt.2017.07.012 +TITLE=First high resolution analysis of the 3ν2 and3ν2−ν2bands of 32S16O2 +HTML=First high resolution analysis of the 3ν<SUB>2</SUB> and 3ν<SUB>2</SUB> -ν<SUB>2</SUB> bands of <SUP>32</SUP>S<SUP>16</SUP>O<SUB>2</SUB> +LATEX=First high resolution analysis of the 3{\ensuremath{\nu}}$_{2}$ and 3{\ensuremath{\nu}}$_{2}$ -{\ensuremath{\nu}}$_{2}$ bands of $^{32}$S$^{16}$O$_{2}$ + +DOI=10.1093/mnras/stt1971 +TITLE=The [ /Fe] ratios of very metal-poor stars within the integrated galactic initial mass function theory +HTML=The [α/Fe] ratios of very metal-poor stars within the integrated galactic initial mass function theory +LATEX=The [{\ensuremath{\alpha}}/Fe] ratios of very metal-poor stars within the integrated galactic initial mass function theory diff --git a/pyref/refs/tests/tests.py b/pyref/refs/tests/tests.py new file mode 100644 index 0000000..fa9ebf1 --- /dev/null +++ b/pyref/refs/tests/tests.py @@ -0,0 +1,51 @@ +from django.test import TestCase + + +class DOIResolveTest(TestCase): + + field_template = {} + field_template['AUTHORS'] = '''''' + field_template['JOURNAL'] = '''''' + field_template['VOLUME'] = '''''' + field_template['PAGE_START'] = '''''' + field_template['PAGE_END'] = '''''' + field_template['YEAR'] = '''''' + field_template['ARTICLE_NUMBER']= '''''' + field_template['TITLE'] = '''''' + field_template['HTML'] = '''''' + field_template['LATEX'] = '''''' + + def _get_val(self, line): + return line[line.index('=')+1:].strip() + + def _read_test_dois(self): + test_dois = {} + with open('refs/tests/test-dois.txt') as fi: + for line in fi: + line = line.strip() + if not line or line.startswith('#'): + continue + if line.startswith('DOI'): + doi = self._get_val(line) + test_dois[doi] = {} + continue + for key in DOIResolveTest.field_template.keys(): + if line.startswith(key): + val = self._get_val(line) + test_dois[doi][key] = val + break + else: + print('Warning: unrecognised key:', key) + return test_dois + + + def test_resolving_doi_populates_add_reference_page(self): + test_dois = self._read_test_dois() + + for doi, test_fields in test_dois.items(): + url = '/refs/resolve/?doi=' + doi + response = self.client.get(url) + + for key, value in test_fields.items(): + self.assertContains(response, + DOIResolveTest.field_template[key].format(value), html=True)