diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..3904430 --- /dev/null +++ b/README.rst @@ -0,0 +1,73 @@ +===== +refs +===== + +refs is a Django application to create references for scientific databases. +The goal of the app is to create a referencing system where an administrator need only enter the Digital Object Identifier (DOI) +of an article and in return get the full citation of the aforementioned article. +This system is setup to output references in HTML, BibTeX and JSON format with the following information from the article: +The citations in this notebook are retrieving the following information on a paper: Title, Authors, Journal Name, Volume Number, Page Range, Year, Hyperlink(s) to the Article and DOI of the Article. + +Detailed Setup +----------- +1. Set up your local_settings.py file. + + Include your Secret_Key in Secret_Key = : This is used to provide cryptographic signing, and should be set to a unique, unpredictable value. +django-admin startproject automatically adds a randomly-generated SECRET_KEY to each new project. +Uses of the key shouldn’t assume that it’s text or bytes. +Every use should go through force_str() or force_bytes() to convert it to the desired type. +Django will refuse to start if SECRET_KEY is not set. + + Setup your database information: An example is shown below, + DATABASES = + 'default': + 'ENGINE': 'django.db.backends.postgresql', + + 'NAME': 'mydatabase', + + 'USER': 'mydatabaseuser', + + 'PASSWORD': 'mypassword', + + 'HOST': '127.0.0.1', + + 'PORT': '5432', + + More information on how to setup your settings.py file can be found here: https://docs.djangoproject.com/en/3.0/ref/settings/ + +2. Setup your conf.py file. + + webapp_path = os.path.join('/Users/user_name/name_of_file') + + In the above webapp_path information you should change user_name to your user name listed on your computer. + file_name is the name of the file where the refs django application is stored. + +3. Create your environment and upload the required modules and packages. A good reference for this step is at https://tutorial.djangogirls.org/en/django_installation/ + + Execute the following in your command line (for windows users) other users please refer to the link above + + cd file_name + + python -m venv myvenv + + myvenv\\Scripts\\activate + + pip install -r requirements.txt + + python manage.py migrate + + python manage.py runserver + +Notes: + + *S in Scripts is capitalized + + *file_name is the file where this django application is stored + + *myvenv is the created virtual environment, you can call it any name, here I chose myvenv + + *you may need to manually install mysqlclient 1.4.4, django 1.11 and requests 2.22, and for windows you may need the binary file 'mysqlclient-1.4.4-64_or_32_bit.whl' which can be found online (commonly on university websites) + + *after you complete runserver step, copy and paste the http generated link, in the webpage and upon reaching the refs page enter your doi press enter and observe your generated reference! + + *depending on your database setup, upon pasting the link and reaching the webpage you may be prompted to enter a username and password. If you encounter problems with access to the refs webpage then run "python manage.py createsuperuser" this is a quick fix to the issue. diff --git a/notebooks/Gscholar original code.ipynb b/notebooks/Gscholar original code.ipynb deleted file mode 100644 index 5d29b55..0000000 --- a/notebooks/Gscholar original code.ipynb +++ /dev/null @@ -1,400 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "# Import these modules\n", - "import gscholar \n", - "import requests\n", - "import json\n", - "import urllib\n", - "import html\n", - "import urllib.request\n", - "import re\n", - "import sys\n", - "import httplib2\n", - "import argparse\n", - "\n", - "from gscholar import query\n", - "from urllib import request, parse \n", - "from bs4 import BeautifulSoup \n", - "from html.entities import html5 as _html5\n", - "from urllib.error import HTTPError" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import gscholar\n", - "\n", - "gscholar.query(\"laboratory measurements\")" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "#!/usr/bin/env python\n", - "\n", - "\"\"\"\n", - "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", - "try:\n", - " # python 2\n", - " from urllib2 import Request, urlopen, quote\n", - "except ImportError:\n", - " # python 3\n", - " from urllib.request import Request, urlopen, quote\n", - "\n", - "try:\n", - " # python 2\n", - " from htmlentitydefs import name2codepoint\n", - "except ImportError:\n", - " # python 3\n", - " from html.entities import name2codepoint\n", - "\n", - "import re\n", - "import os\n", - "import subprocess\n", - "import logging\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", - " This method queries google scholar and returns a list of citations.\n", - " Parameters\n", - " ----------\n", - " searchstr : str\n", - " the query\n", - " outformat : int, optional\n", - " the output format of the citations. Default is bibtex.\n", - " allresults : bool, optional\n", - " return all results or only the first (i.e. best one)\n", - " Returns\n", - " -------\n", - " result : list of strings\n", - " the list with citations\n", - " \"\"\"\n", - " logger.debug(\"Query: {sstring}\".format(sstring=searchstr))\n", - " searchstr = '/scholar?q='+quote(searchstr)\n", - " url = GOOGLE_SCHOLAR_URL + searchstr\n", - " header = HEADERS\n", - " header['Cookie'] = \"GSP=CF=%d\" % outformat\n", - " request = Request(url, headers=header)\n", - " response = urlopen(request)\n", - " html = response.read()\n", - " 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", - " tmp = tmp[:1]\n", - " for link in tmp:\n", - " url = GOOGLE_SCHOLAR_URL+link\n", - " request = Request(url, headers=header)\n", - " response = urlopen(request)\n", - " bib = response.read()\n", - " bib = bib.decode('utf8')\n", - " result.append(bib)\n", - " return result\n", - "\n", - "\n", - "def get_links(html, outformat):\n", - " \"\"\"Return a list of reference links from the html.\n", - " Parameters\n", - " ----------\n", - " html : str\n", - " outformat : int\n", - " the output format of the citations\n", - " Returns\n", - " -------\n", - " List[str]\n", - " the links to the references\n", - " \"\"\"\n", - " if outformat == FORMAT_BIBTEX:\n", - " refre = re.compile(r'\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mdoi\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Enter doi Here: \"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mbibG\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mBibtex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdoi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbibG\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetGScholar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36mgetGScholar\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 46\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mgetGScholar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 47\u001b[0m \u001b[1;34m\"\"\"Get bibtex entry from doi using Google database.\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 48\u001b[1;33m \u001b[0mbibtex\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mquery\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdoi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 49\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbibtex\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mbibtex\u001b[0m \u001b[1;31m#.decode('utf-8')\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 50\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbibtex\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIndexError\u001b[0m: list index out of range" - ] - } - ], - "source": [ - "# If ADS Fails this is the full BibTeX citation\n", - "# 10.1103/PhysRevA.85.032515\n", - "doi = input(\"Enter doi Here: \")\n", - "bibG = Bibtex(doi)\n", - "print(bibG.getGScholar())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/HITRAN References Code_Different Formats of JSON Outputs.ipynb b/notebooks/HITRAN References Code_Different Formats of JSON Outputs.ipynb deleted file mode 100644 index 4974334..0000000 --- a/notebooks/HITRAN References Code_Different Formats of JSON Outputs.ipynb +++ /dev/null @@ -1,368 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Explanation of Contents\n", - "\n", - " 1. Exporting using bibcodes require two things. 1.Bibcode Number 2.Token \n", - " 2. I provided several options to test the json output, the two main methods is by exporting and then requesting\n", - " 3. The first option is a custom exportation of a reference using bibcodes, the html for the doi begins with https://doi.org/\n", - " 4. Next I provided a similar option but this time with an html for the doi that begins with http://dx.doi.org/\n", - " 5. I noticed that most references in HITRAN have three options, regular text, html or latex fields for entering information, therefore I provide options for encoding references in html and latex as well as regular text (if needed)\n", - " 6. The second option is to encode the output in html format, this method still uses 'exportation' from ADS\n", - " 7. The third option is to encode the output in latex format, this method still uses 'exportation' from ADS\n", - " 8. The fourth option is to encode using requests, which pulls information using an encoded DOI\n", - " 9. If you would like to test the json output then simply copy the json output and paste it in a text file, then change the .txt part of the file name to .html and save it. Then open the document (which should now be an html document) and click on the hyperlinks and review the output format" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "*** You will need to know what a Token is. It must be used whenever you want to access the ADS database.\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' in the top right hand corner, 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', if you want to use this notebook you may also use the token that is provided. \n", - "\n", - "*** This is the link to the NASA/ADS API Information tool on GitHub https://github.com/adsabs/adsabs-dev-api#access-settings" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exporting using BibCodes" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': '%Z:H2O-nu-0: Kurtz, M. J., G. Eichhorn, A. Accomazzi, C. S. Grant, S. S. Murray, and J. M. Watson,\"The NASA Astrophysics Data System: Overview\", Astronomy and Astrophysics Supplement Series, 143, 41-59, (2000), DOI}, Bibcode'}\n" - ] - } - ], - "source": [ - "# Before each exporting option it should always start with 'import requests' and 'import json'\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "# This is where the token goes, between the \"\" \n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "# In the [] is where the bibcode(s) is/are entered, yes you can enter more than one bibcode at a time using this method\n", - "# If you want to enter more than one bibcode just put a \\ inbetween them to seperate them\n", - "payload = {\"bibcode\":[\"2000A&AS..143...41K\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format':\\\n", - " '%Z:H2O-nu-0: %I,\"%T\", %J, %V, %p-%P, (%Y), DOI}, Bibcode'}\n", - "# Above in payload, is the code for the format. I will explain what everything means in notes here.\n", - "# %Z allows us to give the reference an identifer, here thats H2O-nu-0\n", - "# %I is a custom output for the authors, they generate the authors names as f. i. lastname with commas in between each author\n", - "# \"%T\" gives the Title of the article and puts the title in quotes\n", - "# %J this gives the journal name and italisizes it \n", - "# %V this gives the volume number for the article and bolds it\n", - "# %p-%P this gives the first page to the last page for the article\n", - "# (%Y) this gives the year of the article and puts it in parenthasis\n", - "# hyperlinks only work with the format LINK IDENTIFIER\n", - "# %d in the first hyperlink grabs the DOI for the article, therefore this is in the hyperlink portion so the output is https://doi.org/doi_number (labeled as DOI)\n", - "# %u in the second hyperlink, it grabs the bibcode only(%u), no need to add an https portion, then the identifer is Bibcode\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", - "# above we are requesting ads for permission to access this information, then we ask it to provide an output for our reference\n", - "# below is we print the reference in json format\n", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Below is almost exactly the same as the one above, except here the hyperlink for the doi has the url 'http://dx.doi.org/" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': '%Z:H2O-nu-0: Kurtz, M. J., G. Eichhorn, A. Accomazzi, C. S. Grant, S. S. Murray, and J. M. Watson,\"The NASA Astrophysics Data System: Overview\", Astronomy and Astrophysics Supplement Series, 143, 41-59, (2000), DOI}, Bibcode'}\n" - ] - } - ], - "source": [ - "import requests\n", - "import json\n", - "\n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "payload = {\"bibcode\":[\"2000A&AS..143...41K\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format':\\\n", - " '%Z:H2O-nu-0: %I,\"%T\", %J, %V, %p-%P, (%Y), DOI}, Bibcode'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Below is the Prompt for adding references" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# DO not run this cell, it is incomplete and is only to be used as a template\n", - "# Prompt (only change in ENTER HERE PORTIONS)\n", - "# I provided this prompt to make it easier to see the coding without all the notes\n", - "# Also note that there is only two 'enter here options', thats where the token and bibcode(s) go, those should be the only two parts that need to be added\n", - "import requests\n", - "import json\n", - "\n", - "token=\"ENTER TOKEN HERE\"\n", - "payload = {\"bibcode\":[\"ENTER BIBCODE(S) HERE\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': \\\n", - " '%Z:ENTER IDENTIFIER NAME HERE, %I, \"%T\", %J, %V, %p-%P, (%Y), DOI:DOI}, Bibcode'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Encoding in HTML" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': '

%Z:H2O-nu-0, Kurtz, M. J., G. Eichhorn, A. Accomazzi, C. S. Grant, S. S. Murray, and J. M. Watson, \"The NASA Astrophysics Data System: Overview\", Astronomy and Astrophysics Supplement Series, 143, 41-59, (2000), DOI, Bibcode'}\n" - ] - } - ], - "source": [ - "# I provided this as a second option, it is exactly the same as the first except there is an %Encoding:html

portion\n", - "# this portion converts characters in URLs to hex notation, and & to &. Outside URLs, the characters &, <, >, and “ are converted to &, <, >, and \", respectively.\n", - "# in simple terms this helps encode the output to be html formatted\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "payload = {\"bibcode\":[\"2000A&AS..143...41K\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': '%ZEncoding:html

%Z:H2O-nu-0, %I, \"%T\", %J, %V, %p-%P, (%Y), DOI, Bibcode'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Encoding in Latex" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': '\\\\item \\textit Kurtz, M.~J., G. Eichhorn, A. Accomazzi, C.~S. Grant, S.~S. Murray, and J.~M. Watson, \"The NASA Astrophysics Data System: Overview\", Astronomy and Astrophysics Supplement Series, 143, 41-59, (2000), \\\\href{https://ui.adsabs.harvard.edu/abs/2000A\\\\&AS..143...41K}:'}\n" - ] - } - ], - "source": [ - "# I provided this as a third option, it is exactly the same as the first except there is an %Encoding:latex\\\\item portion and a differnt format code\n", - "# This encoding converts all special Tex characters into their Tex escape sequences\n", - "# For instance ‘\\’ is converted to ‘$\\backslash $’, ‘$’ is converted into ‘\\$’, ‘^’ is converted into ‘\\^{}’, etc.\n", - "# The format is also latex encoded too, the first change starts with \\textit{%J} which italisizes the journal name\n", - "# \\textbf{%V} bolds the volume number\n", - "# and finally \\href{%u}: is the way to call a hyperlink in latex format\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "payload = {\"bibcode\":[\"2000A&AS..143...41K\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': '%ZEncoding:latex\\\\item %I, \"%T\", \\textit{%J}, \\textbf{%V}, %p-%P, (%Y), \\href{%u}:'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Requests, Note that the reference information such as author/ journal etc. is not printed here, which is why Requests may not work, We can check with Kelly if we want to pursue this option further." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'responseHeader': {'status': 0, 'QTime': 9, 'params': {'q': 'identifier=10.1006/jmsp.1997.7483', 'x-amzn-trace-id': 'Root=1-5d2dc07c-d0eec72083c073f6f2be2604', 'fl': 'id', 'start': '0', 'rows': '10', 'wt': 'json'}}, 'response': {'numFound': 0, 'start': 0, 'docs': []}}\n" - ] - } - ], - "source": [ - "# This is the fourth option, requesting from ADS.\n", - "# All that needs to be entered is the token and the coded DOI number in the url. \n", - "# You enter the coded DOI number after 'https://api.adsabs.harvard.edu/v1/search/query?q=' thereofore it goes right after the q=\n", - "# There is an example of how to code the DOI correctly at the end of this notebook.\n", - "# The json output using this method seems to generate little information on the article, this is why exportation is recommended\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "r = requests.get(\"https://api.adsabs.harvard.edu/v1/search/query?q=identifier=10.1006%2Fjmsp.1997.7483\",\\\n", - " headers={'Authorization': 'Bearer ' + token})\n", - "\n", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Prompt for Requesting: Note you must code your 'search parameter' first: i.e. code your DOI in UTF-8 and URL which I show below " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# DO not run this cell, it is incomplete and is only to be used as a template\n", - "# This is the prompt for requesting articles using DOI's \n", - "# You only change the token information as well as the ENTER CODED DOI HERE portion\n", - "# Therefore there are two prompts total in this notebook, one for retrieving referencees using 'export' and one for 'requests'\n", - "# You may note here that the main difference between the two prompts is the payload option that includes the format of our search when referencing the article\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "token=\"ENTER TOKEN HERE\"\n", - "r = requests.get(\"https://api.adsabs.harvard.edu/v1/search/query?q=ENTER CODED DOI HERE\",\\\n", - " headers={'Authorization': 'Bearer ' + token})\n", - "\n", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### coding search parameters" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "UTF-8 and URL encoded search parameters, Python has a package for this, though the functionality is slightly different between python 2 and python 3" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "identifier=10.1006%2Fjmsp.1997.7483\n" - ] - } - ], - "source": [ - "# This is how a DOI is encoded into UTF-8 and URL\n", - "# There are many different options for encoding in UTF-8 and URL, but this is the one that is provided by ADS\n", - "# However from my tests any type of preferred method of encoding to UTF-8 and URL works just as well \n", - "# The output from this cell gives an encoded DOI number that is used in the first 'requests' cell (which is just one cell above this one)\n", - "\n", - "import sys\n", - "\n", - "v = sys.version\n", - "\n", - "if int(v[0]) == 2:\n", - " import urllib\n", - " query = {'identifier':'10.1006/jmsp.1997.7483'} #a doi wont work but the author did??\n", - " encoded_query = urllib.quote(query)\n", - "else:\n", - " from urllib.parse import urlencode, quote_plus\n", - " query = {\"identifier\":\"10.1006/jmsp.1997.7483\"}\n", - " encoded_query = urlencode(query,quote_via=quote_plus)\n", - "print(encoded_query)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.9" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/References Notebook.ipynb b/notebooks/References Notebook 2020.ipynb similarity index 77% rename from notebooks/References Notebook.ipynb rename to notebooks/References Notebook 2020.ipynb index 4a9b8b4..f5d6e50 100644 --- a/notebooks/References Notebook.ipynb +++ b/notebooks/References Notebook 2020.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Copyright 2019 Frances M. Skinner\n", + "Copyright 2020 Frances M. Skinner\n", "SPDX-License-Identifier: Apache-2.0\n", "\n", "Licensed under the Apache License, Version 2.0 (the \"License\");\n", @@ -24,7 +24,27 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Before Doing Anything, Import the Necessary Modules" + "# **A Guide to creating citations using only a DOI**\n", + "*Note: This Notebook seeks to retrieve citations for papers as 3 outputs; JSON, BibTeX and HTML. The citations in this notebook are retrieving the following information on a paper: Title, Authors, Journal Name, Volume Number, Page Range, Year, Hyperlink(s) to the Article and DOI of the Article. If you are looking for more detailed citations or other outputs then please refer to step 3 after completing steps 1 & 2!*\n", + "\n", + "### You only need to click run on each cell in this notebook and everything should populate normally!\n", + "\n", + "Step 1. Get DOI of the paper you want to cite
\n", + "Step 2. Use DOI to search for the Bibcode -- Enter DOI in prompt provided -- Output will be the Bibcode for the paper
\n", + "Step 3. The Bibcode will automatically be populated for you to search in ADS method. The Output is customizable, all formats possible. This method includes links to paper by DOI url & ADS url
\n", + "Note. (This May Happen to Some Users) Error! My paper was not in ADS! There is no Bibcode for the paper! -- If there is no Bibcode then please Move to Step 4
\n", + "Step 4. Use DOI to search in Urllib method -- your DOI is already populated from step 1 in Urllib Method -- Output will be the full citation as a plain text/JSON output. Output is customizable as HTML through Step 5, or in BibTeX format through Step 6
\n", + "Step 5. The full JSON output will be populated from the Urllib method to encode it as HTML

\n", + "Step 6. The DOI is already populated and you will recieve the full BibTeX citation for the paper using the GScholar Method
\n", + "\n", + "### *All Done!* Now you have the citation for your paper in 3 different formats!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Before Doing Anything, Import the Necessary Modules" ] }, { @@ -37,7 +57,6 @@ "# Step 2 Bibcode\n", "import requests\n", "import json\n", - "# ADS\n", "# Step 4 urllib\n", "import urllib.request\n", "from urllib.error import HTTPError\n", @@ -55,67 +74,61 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# **A Guide to creating citations using only a DOI**\n", - "*Note: This Notebook seeks to retrieve citations for papers as 3 outputs; JSON, BibTeX and HTML. The citations in this notebook are retrieving the following information on a paper: Title, Authors, Journal Name, Volume Number, Page Range, Year, Hyperlink(s) to the Article and DOI of the Article. If you are looking for more detailed citations or other outputs then please refer to step 3 after completing steps 1 & 2!*\n", - "\n", - "Step 1. Get DOI of the paper you want to cite
\n", - "Step 2. Use DOI to search for the Bibcode -- Enter DOI in prompt provided -- Output will be the Bibcode for the paper
\n", - "Step 3. The Bibcode will automatically be populated for you to search in ADS method. The Output is customizable, all formats possible. This method includes links to paper by DOI url & ADS url
\n", - "Note. (This May Happen to Some Users) Error! My paper was not in ADS! There is no Bibcode for the paper! -- If there is no Bibcode then please Move to Step 4
\n", - "Step 4. Use DOI to search in Urllib method -- your DOI is already populated from step 1 in Urllib Method -- Output will be the full citation as a plain text/JSON output. Output is customizable as HTML through Step 5, or in BibTeX format through Step 6
\n", - "Step 5. The full JSON output will be populated from the Urllib method to encode it as HTML
\n", - "Step 6. The DOI is already populated and you will recieve the full BibTeX citation for the paper using the GScholar Method
\n", - "\n", - "### *All Done!* Now you have the citation for your paper in 3 different formats!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 1.\n", + "## Step 1. Enter your DOI and Token\n", "\n", - "You can retrieve the DOI for your paper in many different ways.\n", - "1. The DOI is a unique alphanumeric string assigned by the International DOI Foundation, to identify content and provide a persistent link to its location on the Internet. It is written in the general format of '10.1000/xyz123'\n", - "2. The DOI should be written on the top left or top right corner of your paper, it is written as 'DOI:10.1000/xyz123'\n", - "3. The DOI should be listed in the details or citation section on the publishers website where you have found your paper\n", - "4. The DOI may also be written as a link, next to the papers information on the publishers website, the link is written as https://doi.org/10.1000/xyz123 or https://dx.doi.org/10.1000/xyz123\n", - "5. In order to use this notebook please type in \"ENTER HERE\" spots the DOI in the '10.1000/xyz123' format, *NOT* as hyperlink" + "You can retrieve the DOI for your paper in many different ways.\n", + "1. What is a DOI?\n", + " - The DOI is a unique alphanumeric string assigned by the International DOI Foundation, to identify content and provide a persistent link to its location on the Internet. It is written in the general format of '10.1000/xyz123'\n", + "2. Where Can I find a DOI?\n", + " - The DOI should be written on the top left or top right corner of your paper, it is written as 'DOI:10.1000/xyz123'\n", + " - The DOI should be listed in the details or citation section on the publishers website where you have found your paper\n", + " - The DOI may also be written as a link, next to the papers information on the publishers website, the link is written as https://doi.org/10.1000/xyz123 or https://dx.doi.org/10.1000/xyz123\n", + "3. How do I run this notebook?\n", + " - In order to use this notebook please type in \"ENTER HERE\" spots the DOI in the '10.1000/xyz123' format, *NOT* as hyperlink\n", + " - You only need to run each cell after entering your DOI, everything else will populate for you" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter DOI Here: 10.1016/j.jqsrt.2019.106711\n" + ] + } + ], "source": [ "# 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\"" + "# If your using the django application you can enter your token in the settings file and Import ADS_TOKEN from settings.py\n", + "token=\"Enter Your Token Here\" \n", + "doi = input(\"Enter DOI Here: \")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Step 2. Retrive Bibcode " + "## Step 2. Retrive Bibcode" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Enter DOI Here: 10.1016/j.jqsrt.2019.106711\n", - "2020JQSRT.24106711C\n" + "Bibcode: 2020JQSRT.24106711C\n" ] } ], @@ -143,8 +156,7 @@ " names.append('{} {}'.format(initials, family))\n", " return ', '.join(names)\n", "def parse_citeproc_json(citeproc_json):\n", - " \"\"\"Parse the provided JSON into a Ref object.\"\"\"\n", - " \n", + " \"\"\"Parse the provided JSON into a Ref object.\"\"\" \n", " cpd = json.loads(citeproc_json)\n", " try:\n", " if cpd['type'] != 'article-journal':\n", @@ -201,7 +213,6 @@ " citeproc_json = get_citeproc_json_from_doi(doi)\n", " ref = parse_citeproc_json(citeproc_json)\n", " return ref\n", - "doi = input(\"Enter DOI Here: \")\n", "doi_fetched = get_source_from_doi(doi)\n", "rdoi = doi\n", "rdoi_bs = rdoi.replace(\"\\\\\", \"%2F\") # Remove backslash and replace with URL code for backslash\n", @@ -212,21 +223,21 @@ "todos = json.loads(rurl.text)\n", "todos_response = todos.get('response', '')\n", "Bibcode = (todos_response['docs'][0]['bibcode']) \n", - "print(Bibcode)" + "print(\"Bibcode:\",Bibcode)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Step 3. ADS Method" + "## Step 3. ADS Method" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Note before using ADS Method\n", + "### Note before using ADS Method\n", " 1. Exporting using bibcodes require two things.\n", " - A Bibcode Number (which you got from step 2)
\n", " - A Token--You will need to know what a Token is. It must be used whenever you want to access the ADS database. A token can only be used once you have an account on NASA/ADS https://ui.adsabs.harvard.edu/. Once you have an account click on 'Account' in the top right hand corner, then click on 'Customize Settings' on the dropdown menu. In 'Customize Settings' there is a panel to the left of the screen, if you scroll down that panel you will see 'API Token'. Click on 'API Token' and then click on 'generate a new key'.
\n", @@ -236,27 +247,27 @@ " - You can search more than 1 bibcode at a time
\n", " - You have more output options such as... EndNote, ProCite, RIS (Refman), RefWorks, MEDLARS, AASTeX, Icarus, MNRAS, Solar Physics (SoPh), DC (Dublin Core) XML, REF-XML, REFABS-XML, VOTables and RSS
\n", " - This notebook does not display examples of all of these output format options, if you are interested in any of these choices or extra features please refer to http://adsabs.github.io/help/actions/export
\n", - " 3. The first option is to retrieve a citation where the output is in JSON format
\n", - " 4. The second option is to retrieve a citation where the output is in html format
\n", - " 6. The third option is to retrieve a citation where the output is in LaTeX format\n", + " 3. The first option is to retrieve a citation where the output is in HTML unique character (JSON) format
\n", + " 4. The second option is to retrieve a citation where the output is in BibTeX format
\n", + " 6. The third option is to retrieve a citation where the output is in HTML converted character format\n", " \n", - "*Overall you need to make an account on ADS in order to use this method. *\n", + "*Overall you need to make an account on ADS in order to use this method.*\n", "\n", - "*If you do not want to make an account then use the BibTeX citation from step 6 and if you want, use steps 4 & 5 to retrieve html and JSON citation formats, in steps 4 & 5 you only need to enter the DOI to retrieve citations *\n", + "*If you do not want to make an account then use the BibTeX citation from step 6 and if you want, use steps 4 & 5 to retrieve html and JSON citation formats, in steps 4 & 5 you only need to enter the DOI to retrieve citations (the DOI is set to populate for you automatically)*\n", "\n", - "*However there are many benefits to using the ADS method, your citation output is completely customizable! So if your willing and you have your Bibcode then its recommended to use this method!*" + "*However there are many benefits to using the ADS method, your citation output is completely customizable! So if your willing and you have your Bibcode then its recommended to use this method!*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "After running the cell below and then the print cell you will recieve an HTML reference with the characters &, <, >, and “ included" + "After running the cell below, you will recieve an HTML reference with the characters &, <, >, and “ included" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -277,7 +288,7 @@ ], "source": [ "# HTML with the characters &, <, >, and “ included\n", - "payload = {\"bibcode\": [\"{}\".format(Bibcode)], # 2012PhRvA..85c2515Z\n", + "payload = {\"bibcode\": [\"{}\".format(Bibcode)],\n", " \"sort\": \"first_author asc\",\n", " \"format\":\n", " '''{\"ref_json\": {\"authors\": \"%I\",\n", @@ -310,12 +321,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "After running the cell below and then the print cell you will recieve a BibTeX reference" + "After running the cell, you will recieve a BibTeX reference" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -363,19 +374,22 @@ "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'])" + "print('bibcode:', ref_json['bibcode'])\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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "After running the cell below and then the print cell you will recieve an HTML reference with the characters &, <, >, and “ converted to & amp; & lt; & gt; and & quot; respectively." + "After running the cell below, you will recieve an HTML reference with the characters &, <, >, and “ converted to & amp; & lt; & gt; and & quot; respectively." ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -430,39 +444,38 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Step 4. Urllib method\n", - " If you did not have a bibcode or you want a plain text reference then use this method " + "## Step 4. Urllib method\n", + "If you did not have a bibcode or you want a plain text reference then use this method " ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Enter doi Here: 10.1093/mnras/stt1971\n", - "Authors: S. Recchi, F. Calura, B. K. Gibson, P. Kroupa \n", - "Title: The [ /Fe] ratios of very metal-poor stars within the integrated galactic initial mass function theory \n", - "Journal: Monthly Notices of the Royal Astronomical Society \n", - "Volume: 437 \n", - "Year: 2013 \n", - "Page Start: 994 \n", - "Page End: 1008 \n", - "Article Number: \n", - "DOI: 10.1093/mnras/stt1971 \n", - "URL: http://dx.doi.org/10.1093/mnras/stt1971 \n" + "Authors: E. K. Conway, I. E. Gordon, A. A. Kyuberis, O. L. Polyansky, J. Tennyson, N. F. Zobov \n", + "Title: Calculated line lists for H216O and H218O with extensive comparisons to theoretical and experimental sources including the HITRAN2016 database \n", + "Journal: Journal of Quantitative Spectroscopy and Radiative Transfer \n", + "Volume: 241 \n", + "Year: 2020 \n", + "Page Start: 106711 \n", + "Page End: \n", + "Article Number: 106711 \n", + "DOI: 10.1016/j.jqsrt.2019.106711 \n", + "URL: http://dx.doi.org/10.1016/j.jqsrt.2019.106711 \n" ] } ], "source": [ - "doi = input(\"Enter doi Here: \")\n", + "#doi = input(\"Enter doi Here: \")\n", "doi_fetched = get_source_from_doi('{}'.format(doi))\n", "\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", + "# if you would like to add or change anything then refer to the initial code in step 2 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],doi_fetched[9])\n", "\n", "print ('Authors:', doi_fetched[0], '')\n", @@ -481,31 +494,31 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Step 5. Encoding JSON in HTML
\n", - "Reference is populated from the Urllib Method" + "## Step 5. Encoding JSON in HTML
\n", + "Reference is populated from the Urllib Method" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'('S. Recchi, F. Calura, B. K. Gibson, P. Kroupa', 'The [\\\\xa0/Fe] ratios of very metal-poor stars within the integrated galactic initial mass function theory', 'Monthly Notices of the Royal Astronomical Society', '437', 2013, '994', '1008', '10.1093/mnras/stt1971', 'http://dx.doi.org/10.1093/mnras/stt1971', '')'" + "'('E. K. Conway, I. E. Gordon, A. A. Kyuberis, O. L. Polyansky, J. Tennyson, N. F. Zobov', 'Calculated line lists for H216O and H218O with extensive comparisons to theoretical and experimental sources including the HITRAN2016 database', 'Journal of Quantitative Spectroscopy and Radiative Transfer', '241', 2020, '106711', '', '10.1016/j.jqsrt.2019.106711', 'http://dx.doi.org/10.1016/j.jqsrt.2019.106711', '106711')'" ] }, - "execution_count": 14, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# I am populating our output from the urllib method\n", + "# Here is the populated output from the urllib method\n", "# This will replace (\"\"\"& < \" '> \"\"\" ) with (& < " ' >)\n", "s = html.escape( \"\"\"& < \" '> \"\"\" ) \n", - "html.escape(s) #(s, quote=True)\n", + "html.escape(s)\n", "html.escape(\"{}\".format(reference))" ] }, @@ -513,27 +526,26 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Step 6. BibTeX citation" + "## Step 6. BibTeX citation" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "@article{recchi2013alpha,\n", - " title={The [$\\alpha$/Fe] ratios of very metal-poor stars within the integrated galactic initial mass function theory},\n", - " author={Recchi, S and Calura, F and Gibson, Brad K and Kroupa, P},\n", - " journal={Monthly Notices of the Royal Astronomical Society},\n", - " volume={437},\n", - " number={1},\n", - " pages={994--1008},\n", - " year={2013},\n", - " publisher={The Royal Astronomical Society}\n", + "@article{conway2020calculated,\n", + " title={Calculated line lists for H216O and H218O with extensive comparisons to theoretical and experimental sources including the HITRAN2016 database},\n", + " author={Conway, Eamon K and Gordon, Iouli E and Kyuberis, Aleksandra A and Polyansky, Oleg L and Tennyson, Jonathan and Zobov, Nikolai F},\n", + " journal={Journal of Quantitative Spectroscopy and Radiative Transfer},\n", + " volume={241},\n", + " pages={106711},\n", + " year={2020},\n", + " publisher={Elsevier}\n", "}\n" ] } @@ -660,13 +672,6 @@ "bib = bib.getGScholar()\n", "print(bib)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -685,7 +690,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/notebooks/Updated Notebook Containing Changes .ipynb b/notebooks/Updated Notebook Containing Changes .ipynb deleted file mode 100644 index c52d338..0000000 --- a/notebooks/Updated Notebook Containing Changes .ipynb +++ /dev/null @@ -1,1116 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# **A Guide to creating citations using only a DOI**\n", - "*Note: This Notebook seeks to retrieve citations for papers as 3 outputs; JSON, BibTeX and HTML. The citations in this notebook are retrieving the following information on a paper: Title, Authors, Journal Name, Volume Number, Page Range, Year, Hyperlink(s) to the Article and DOI of the Article. If you are looking for more detailed citations or other outputs then please refer to step 3 after steps 1 & 2!*\n", - "\n", - "Step 1. Get DOI of the paper you want to cite
\n", - "Step 2. Use DOI to search in GScholar method -- Enter DOI in \"Enter Here\" in GScholar Method -- Output will be the full citation in BibTeX format, and the Bibcode for the paper will be displayed
\n", - "Step 3. Use Bibcode to search in ADS method -- Enter Bibcode in \"Enter Here\" in ADS Method -- Output is customizable, all formats possible. This method includes links to paper by DOI url & ADS url
\n", - "Note. (This May Happen to Some Users) Error! My paper was not in ADS! There is no Bibcode for the paper! -- Move to Step 4
\n", - "Step 4. Use DOI to search in Urllib method -- Enter DOI in \"Enter Here\" in Urllib Method -- Output will be the full citation as a JSON output. Output is customizable as HTML through Step 5, or in BibTeX format through Step 6
\n", - "Step 5. Enter the full JSON output in \"Enter Here\" to encode it as HTML
\n", - "Step 6. Enter DOI in \"Enter Here\" to retrieve the BibTeX citation for the paper
\n", - "\n", - "### *All Done!* Now you have the citation for your paper in 3 different formats!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 1.\n", - "\n", - "You can retrieve the DOI for your paper in many different ways.\n", - "1. The DOI is a unique alphanumeric string assigned by the International DOI Foundation, to identify content and provide a persistent link to its location on the Internet. It is written in the general format of '10.1000/xyz123'\n", - "2. The DOI should be written on the top left or top right corner of your paper, it is written as 'DOI:10.1000/xyz123'\n", - "3. The DOI should be listed in the details or citation section on the publishers website where you have found your paper\n", - "4. The DOI may also be written as a link, next to the papers information on the publishers website, the link is written as https://doi.org/10.1000/xyz123 or https://dx.doi.org/10.1000/xyz123\n", - "5. In order to use this notebook please type in \"ENTER HERE\" spots the DOI in the '10.1000/xyz123' format, *NOT* as hyperlink" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 2. GScholar Method" - ] - }, - { - "cell_type": "code", - "execution_count": 151, - "metadata": {}, - "outputs": [], - "source": [ - "# This is the code to retrieve the citation. \n", - "# Below this cell is an example of retrieving the citation using an example DOI and a Prompt to Enter your DOI!\n", - "\n", - "# Import these modules, install them if needed (you may need to 'pip install gscholar')\n", - "from urllib import request, parse \n", - "# The urllib.request module defines functions and classes which help in opening URLs (mostly HTTP)\n", - "# allows you to send HTTP/1.1 requests, without the need for manual labor\n", - "# There’s no need to manually add query strings to your URLs, or to form-encode your POST data. HTTP connection pooling are 100% automatic, thanks to urllib3.\n", - "from bs4 import BeautifulSoup \n", - "# Beautiful Soup is a Python library for pulling data out of HTML and XML files. \n", - "import gscholar \n", - "# This package provides a python package and CLI to query google scholar and get references in various formats\n", - "\n", - "# Classifing the BibTex Object to get a BibTeX output format\n", - "class Bibtex(object):\n", - " \"\"\" Convert doi number to get bibtex entries.\"\"\"\n", - " def __init__(self, doi=None, title=None):\n", - " \"\"\"Input doi number-- Returns doi, encoded doi, and doi url.\"\"\"\n", - " _base_url = \"http://dx.doi.org/\"\n", - " 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 \n", - " else:\n", - " self.url = None \n", - "\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)\n", - " return self.soup \n", - "\n", - "# Get the ADS link for the paper \n", - " def getADS(self):\n", - " \"\"\"Get bibtex entry from doi using ADS database.\"\"\"\n", - " uri = \"http://adsabs.harvard.edu/cgi-bin/basic_connect?qsearch=\"\n", - " url = uri + self._edoi\n", - "\n", - "# Make Beautiful Soup look for ADS Bibcode (which is necessary for retrieving the ADS link)\n", - " soup = self._soupfy(url)\n", - " try:\n", - " tag = soup.findAll('input', attrs={\"name\": \"bibcode\"})[0]\n", - " except IndexError:\n", - " print(\"\\nADS failed\\n\")\n", - " else:\n", - " bibcode = tag.get('value') if tag.get('value') else None\n", - " uri = 'http://adsabs.harvard.edu/cgi-bin/nph-bib_query?bibcode='\n", - " end = '&data_type=BIBTEX&db_key=AST%26nocookieset=1'\n", - " url = uri + bibcode + end\n", - " bib = request.urlopen(url).read().decode('utf-8')\n", - " bib = bib.split('\\n')\n", - " self.bibtex = '\\n'.join(bib[5:-1])\n", - " finally:\n", - " return self.bibtex" - ] - }, - { - "cell_type": "code", - "execution_count": 152, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@ARTICLE{2015PLoSO..1015434S,\n", - " author = {{Simon}, S.~L. and {Field}, J. and {Miller}, L.~E. and {DiFrancesco}, M. and \n", - "\t{Beebe}, D.~W.},\n", - " title = \"{Sweet/Dessert Foods Are More Appealing to Adolescents after Sleep Restriction}\",\n", - " journal = {PLoS ONE},\n", - " year = 2015,\n", - " month = feb,\n", - " volume = 10,\n", - " pages = {e0115434},\n", - " doi = {10.1371/journal.pone.0115434},\n", - " adsurl = {https://ui.adsabs.harvard.edu/abs/2015PLoSO..1015434S},\n", - " adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n", - "}\n", - "\n" - ] - } - ], - "source": [ - "# Example\n", - "doi = \"10.1371/journal.pone.0115434\"\n", - "bib = Bibtex(doi)\n", - "print(bib.getADS())\n", - "\n", - "# The first part after @ARTICLE is the Bibcode, in this case the Bibcode is '1998JMoSp.187...70B'" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "ADS failed\n", - "\n", - "None\n" - ] - } - ], - "source": [ - "# Prompt!!!\n", - "doi = \"ENTER DOI HERE\"\n", - "bib = Bibtex(doi)\n", - "print(bib.getADS())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 3. ADS Method" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Note before using ADS Method\n", - " 1. Exporting using bibcodes require two things.\n", - " - A Bibcode Number (which you got from step 2)
\n", - " - A Token--You will need to know what a Token is. It must be used whenever you want to access the ADS database. A token can only be used once you have an account on NASA/ADS https://ui.adsabs.harvard.edu/. Once you have an account click on 'Account' in the top right hand corner, then click on 'Customize Settings' on the dropdown menu. In 'Customize Settings' there is a panel to the left of the screen, if you scroll down that panel you will see 'API Token'. Click on 'API Token' and then click on 'generate a new key'.
\n", - " - You are technically using ADS's API when you are using this method. So for any questions/concerns please refer to the NASA/ADS API Information tool on GitHub https://github.com/adsabs/adsabs-dev-api#access-settings
\n", - " 2. The benefits of this method are the endless choices to customize your citation output.\n", - " - You can get more information such as... the abstract, copyright, citation count, author affiliation, keywords, publication category and arXiv e-print number, etc.
\n", - " - You can search more than 1 bibcode at a time
\n", - " - You have more output options such as... EndNote, ProCite, RIS (Refman), RefWorks, MEDLARS, AASTeX, Icarus, MNRAS, Solar Physics (SoPh), DC (Dublin Core) XML, REF-XML, REFABS-XML, VOTables and RSS
\n", - " - This notebook does not display examples of all of these output format options, if you are interested in any of these choices or extra features please refer to http://adsabs.github.io/help/actions/export
\n", - " 3. The first option is to retrieve a citation where the output is in JSON format
\n", - " 4. The second option is to retrieve a citation where the output is in html format
\n", - " 6. The third option is to retrieve a citation where the output is in LaTeX format
\n", - " \n", - "*Overall you need to make an account on ADS in order to use this method. *\n", - "\n", - "*If you do not want to make an account then use the BibTeX citation from step 6 and if you want, use steps 4 & 5 to retrieve html and JSON citation formats, in steps 4 & 5 you only need to enter the DOI to retrieve citations *\n", - "\n", - "*However there are many benefits to using the ADS method, your citation output is completely customizable! So if your willing and you have your Bibcode then its recommended to use this method!*" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Below is an example on how to search using the ADS method and get a JSON output" - ] - }, - { - "cell_type": "code", - "execution_count": 168, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': 'H2O-nu-0: Zhang, S. B. and D. L. Yeager, Complex-scaled multireference configuration-interaction method to study Be and Be-like cations\\' (B, C, N, O, Mg) Auger resonances 1s2s22p 1,3Po, Physical Review A, 85, 032515, 2012, DOI}, Bibcode'}\n" - ] - } - ], - "source": [ - "# Before each exporting option it should always start with 'import requests' and 'import json'\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "# This is where the token goes, between the \"\" \n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "\n", - "# In the [] is where the bibcode(s) is/are entered, yes you can enter more than one bibcode at a time using this method\n", - "# If you want to enter more than one bibcode just put a \\ inbetween them to seperate them\n", - "payload = {\"bibcode\":[\"2012PhRvA..85c2515Z\"],\\\n", - " 'format':\\\n", - " 'H2O-nu-0: %I, %T, %J, %V, %p-%P, %Y, DOI}, Bibcode'}\n", - "# Above in payload=, is the code for the format. I will explain what everything means in notes here.\n", - "# At the beginning we give the reference an identifer, here thats H2O-nu-0\n", - "# %I is a custom output for the authors, they generate the authors names as f. i. lastname with commas in between each author\n", - "# %T gives the Title of the article\n", - "# %J this gives the journal name \n", - "# %V this gives the volume number for the article \n", - "# %p-%P this gives the first page to the last page for the article\n", - "# %Y this gives the year of the article\n", - "# hyperlinks only work with the format LINK IDENTIFIER\n", - "# %d in the first hyperlink grabs the DOI for the article, \n", - "# therefore this is in the hyperlink portion so the output is https://doi.org/doi_number (labeled as DOI)\n", - "# %u in the second hyperlink, it grabs the bibcode only(%u), no need to add an https portion, then the identifer is Bibcode\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", - "# above we are requesting ads for permission to access this information, then we ask it to provide an output for our reference\n", - "\n", - "# below we print the reference in json format\n", - "print(r.json())" - ] - }, - { - "cell_type": "code", - "execution_count": 167, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'error': 'Unauthorized'}\n" - ] - } - ], - "source": [ - "# This is a prompt to search using the ADS method and retrieve a JSON output\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "token=\"ENTER TOKEN HERE\"\n", - "\n", - "payload = {\"bibcode\":[\"ENTER BIBCODE HERE\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format':\\\n", - " 'ENTER NOTES OR LABELS HERE: %I, \"%T\", %J, %V, %p-%P, (%Y), DOI, Bibcode'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Below is an example on how to search using the ADS method and get an HTML output" - ] - }, - { - "cell_type": "code", - "execution_count": 166, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': 'H2O-nu-0, Zhang, S. B. and D. L. Yeager, \"Complex-scaled multireference configuration-interaction method to study Be and Be-like cations\\' (B, C, N, O, Mg) Auger resonances 1s2s22p 1,3Po\", Physical Review A, 85, 032515, (2012), DOI, Bibcode'}\n" - ] - } - ], - "source": [ - "# This is an example of using the ADS method to retrieve a citation in HTML format\n", - "# I provided this as a second option, it is exactly the same as the one above, except there is an %Encoding:html

portion\n", - "# this portion converts characters in URLs to hex notation. Outside URLs, the characters “ and \" are converted respectively.\n", - "# in simple terms this helps encode the output to be html formatted\n", - "# I took out the %Z encoding html because the superscripts were not working with that format output.\n", - "# The output without %Z works better\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "payload = {\"bibcode\":[\"2012PhRvA..85c2515Z\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': 'H2O-nu-0, %I, \"%T\", %J, %V, %p-%P, (%Y), DOI, Bibcode'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "code", - "execution_count": 165, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'error': 'Unauthorized'}\n" - ] - } - ], - "source": [ - "# This is a prompt using the ADS method to retrieve a citation in HTML format\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "token=\"ENTER TOKEN HERE\"\n", - "payload = {\"bibcode\":[\"ENTER BIBCODE HERE\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': '%ZEncoding:html

:ENTER NOTES OR LABELS HERE, %I, \"%T\", %J, %V, %p-%P, (%Y), DOI, Bibcode'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Below is an example on how to search using the ADS method and get a LaTeX output" - ] - }, - { - "cell_type": "code", - "execution_count": 164, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': '\\\\bibitem[H2O-nu-0, Zhang, S.~B. and D.~L. Yeager, \"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}$\", \\textit{Physical Review A}, \\textbf{85}, 032515, (2012), {10.1103/PhysRevA.85.032515}, {https://ui.adsabs.harvard.edu/abs/2012PhRvA..85c2515Z}:]'}\n" - ] - } - ], - "source": [ - "# I provided this as a third option, it is exactly the same as the first except there is a %Encoding:latex\\\\item portion \n", - "# The %Encoding:latex converts all special Tex characters into their Tex escape sequences\n", - "# For instance ‘\\’ is converted to ‘$\\backslash $’, ‘$’ is converted into ‘\\$’, ‘^’ is converted into ‘\\^{}’, etc.\n", - "# The format is also latex encoded too, the first change starts with \\textit{%J} which italisizes the journal name\n", - "# \\textbf{%V} bolds the volume number\n", - " \n", - "import requests\n", - "import json\n", - "\n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "payload = {\"bibcode\":[\"2012PhRvA..85c2515Z\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': '%ZEncoding:latex\\\\bibitem[H2O-nu-0, %I, \"%T\", \\textit{%J}, \\textbf{%V}, %p-%P, (%Y), {%d}, {%u}:]'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'error': 'Unauthorized'}\n" - ] - } - ], - "source": [ - "# This is a prompt using the ADS method to retrieve a citation in LaTeX format\n", - "\n", - "import requests\n", - "import json\n", - "\n", - "token=\"ENTER TOKEN HERE\"\n", - "payload = {\"bibcode\":[\"ENTER BIBCODE HERE\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': '%ZEncoding:latex\\\\bibitem[Note: ENTER NOTE OR LABEL HERE, %I, \"%T\", \\textit{%J}, \\textbf{%V}, %p-%P, (%Y), {%d}, {%u}:]'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 4. Urllib method " - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "# This is the code to retrieve the citation. \n", - "# Below this cell is an example of retrieving the citation using an example DOI and a Prompt to Enter your DOI!\n", - "\n", - "import json\n", - "import urllib.request\n", - "from urllib.error import HTTPError\n", - "\n", - "def get_citeproc_authors(cpd_author):\n", - " if cpd_author is None:\n", - " return None\n", - " names = []\n", - " for author in cpd_author:\n", - " try:\n", - " family = author['family'].title()\n", - " except KeyError:\n", - " # Occasionally an author isn't a single person,\n", - " # e.g. \"JET contributors\", so do what we can here:\n", - " name = author['name']\n", - " names.append(name)\n", - " continue\n", - " try:\n", - " given = author['given']\n", - " except KeyError:\n", - " # This author has a first name\n", - " names.append(family)\n", - " continue\n", - " initials = given.split()\n", - " initials[0] = '{}.'.format(initials[0][0])\n", - " 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", - " cpd = json.loads(citeproc_json)\n", - " try:\n", - " if cpd['type'] != 'article-journal':\n", - " 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", - " volume = cpd.get('volume', '')\n", - " page_start, page_end = cpd.get('page', ''), ''\n", - " if page_start and '-' in page_start:\n", - " page_start, page_end = page_start.split('-')\n", - " article_number = cpd.get('article-number', '')\n", - " doi = cpd.get('DOI', '')\n", - " url = cpd.get('URL', '')\n", - " try:\n", - " year = cpd['issued']['date-parts'][0][0]\n", - " except (KeyError, IndexError):\n", - " year = None\n", - "# # =============================================================================\n", - "# # OUTPUT\n", - "# # =============================================================================\n", - " ref = [authors, \n", - " title, \n", - " journal, \n", - " volume,\n", - " year, \n", - " page_start, \n", - " page_end, \n", - " doi,\n", - " url, \n", - " article_number,\n", - " citeproc_json]\n", - "\n", - " # ref = Ref(authors=authors, title=title, journal=journal, volume=volume,\n", - " # year=year, page_start=page_start, page_end=page_end, doi=doi,\n", - " # url=url, article_number=article_number,\n", - " # citeproc_json=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", - " req = urllib.request.Request(url)\n", - " req.add_header('Accept', 'application/citeproc+json')\n", - " try:\n", - " with urllib.request.urlopen(req) as f:\n", - " citeproc_json = f.read().decode()\n", - " except HTTPError as e:\n", - " if e.code == 404:\n", - " 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": 35, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "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 ; p. - ; 10.1103/physreva.85.032515 ; http://dx.doi.org/10.1103/PhysRevA.85.032515\n" - ] - } - ], - "source": [ - "# Example\n", - "\n", - "doi_fetched = get_source_from_doi('10.1103/PhysRevA.85.032515')\n", - "\n", - "print (doi_fetched[0],';',doi_fetched[1],';',doi_fetched[2],';',doi_fetched[3],';',doi_fetched[4],'; p.',doi_fetched[5],'-',doi_fetched[6],';',doi_fetched[7],';', doi_fetched[8])" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": true - }, - "outputs": [ - { - "ename": "HTTPError", - "evalue": "HTTP Error 400: Bad Request", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mHTTPError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Prompt\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mdoi_fetched\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mget_source_from_doi\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'ENTER DOI HERE'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;31m# Below are the parameters for searching your citation, if you would like to add or change anything then refer to the initial code above to make your changes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m\u001b[0m in \u001b[0;36mget_source_from_doi\u001b[1;34m(doi)\u001b[0m\n\u001b[0;32m 91\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 92\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mget_source_from_doi\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdoi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 93\u001b[1;33m \u001b[0mciteproc_json\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mget_citeproc_json_from_doi\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdoi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 94\u001b[0m \u001b[0mref\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mparse_citeproc_json\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mciteproc_json\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mref\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m\u001b[0m in \u001b[0;36mget_citeproc_json_from_doi\u001b[1;34m(doi)\u001b[0m\n\u001b[0;32m 82\u001b[0m \u001b[0mreq\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_header\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Accept'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'application/citeproc+json'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 83\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 84\u001b[1;33m \u001b[1;32mwith\u001b[0m \u001b[0murllib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0murlopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 85\u001b[0m \u001b[0mciteproc_json\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 86\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mHTTPError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\urllib\\request.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(url, data, timeout, cafile, capath, cadefault, context)\u001b[0m\n\u001b[0;32m 220\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 221\u001b[0m \u001b[0mopener\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_opener\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 222\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mopener\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 223\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 224\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0minstall_opener\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mopener\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\urllib\\request.py\u001b[0m in \u001b[0;36mopen\u001b[1;34m(self, fullurl, data, timeout)\u001b[0m\n\u001b[0;32m 529\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mprocessor\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mprocess_response\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprotocol\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 530\u001b[0m \u001b[0mmeth\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprocessor\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 531\u001b[1;33m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmeth\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 532\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 533\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\urllib\\request.py\u001b[0m in \u001b[0;36mhttp_response\u001b[1;34m(self, request, response)\u001b[0m\n\u001b[0;32m 639\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m200\u001b[0m \u001b[1;33m<=\u001b[0m \u001b[0mcode\u001b[0m \u001b[1;33m<\u001b[0m \u001b[1;36m300\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 640\u001b[0m response = self.parent.error(\n\u001b[1;32m--> 641\u001b[1;33m 'http', request, response, code, msg, hdrs)\n\u001b[0m\u001b[0;32m 642\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 643\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\urllib\\request.py\u001b[0m in \u001b[0;36merror\u001b[1;34m(self, proto, *args)\u001b[0m\n\u001b[0;32m 567\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mhttp_err\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 568\u001b[0m \u001b[0margs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'default'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'http_error_default'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0morig_args\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 569\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_chain\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 570\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 571\u001b[0m \u001b[1;31m# XXX probably also want an abstract factory that knows when it makes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\urllib\\request.py\u001b[0m in \u001b[0;36m_call_chain\u001b[1;34m(self, chain, kind, meth_name, *args)\u001b[0m\n\u001b[0;32m 501\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mhandler\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mhandlers\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 502\u001b[0m \u001b[0mfunc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhandler\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 503\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 504\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 505\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\urllib\\request.py\u001b[0m in \u001b[0;36mhttp_error_default\u001b[1;34m(self, req, fp, code, msg, hdrs)\u001b[0m\n\u001b[0;32m 647\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mHTTPDefaultErrorHandler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mBaseHandler\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 648\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mhttp_error_default\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfp\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmsg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhdrs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 649\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfull_url\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmsg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhdrs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfp\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 650\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 651\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mHTTPRedirectHandler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mBaseHandler\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mHTTPError\u001b[0m: HTTP Error 400: Bad Request" - ] - } - ], - "source": [ - "# Prompt\n", - "\n", - "doi_fetched = get_source_from_doi('ENTER DOI HERE')\n", - "\n", - "# Below are the parameters for searching your citation, if you would like to add or change anything then refer to the initial code above to make your changes\n", - "\n", - "print ('Authors:', doi_fetched[0], '')\n", - "print ('Title:', doi_fetched[1], '')\n", - "print ('Journal:', doi_fetched[2], '')\n", - "print ('Volume:', doi_fetched[3], '')\n", - "print ('Year:', doi_fetched[4], '')\n", - "print ('Page Start:', doi_fetched[5], '')\n", - "print ('Page End:', doi_fetched[6], '')\n", - "print ('DOI:', doi_fetched[7], '')\n", - "print ('URL:', doi_fetched[8], '')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 5. Encoding JSON in HTML
" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "''Auger resonances 1s2s&lt;SUP&gt;2&lt;/SUP&gt;2p &lt;SUP&gt;1,3&lt;/SUP&gt;P&lt;SUP&gt;o&lt;/SUP&gt''" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Note: Use the JSON output from urllib\n", - "# Example of encoding the JSON output from Urllib\n", - "\n", - "from html.entities import html5 as _html5\n", - "import html\n", - "\n", - "s = html.escape( \"\"\"& < \" ' >\"\"\" ) # s = '& < " ' >'\n", - "html.escape(s, quote=True)\n", - "html.escape(\"'Auger resonances 1s2s<SUP>2</SUP>2p <SUP>1,3</SUP>P<SUP>o</SUP>'\")" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': 'H2O-nu-0: Kurtz, M. J., G. Eichhorn, A. Accomazzi, C. S. Grant, S. S. Murray, and J. M. Watson, Title:The NASA Astrophysics Data System: Overview, Astronomy and Astrophysics Supplement Series, 143, 41-59, 2000, dx.doi.org\\\\10.1051/aas:2000170, https://ui.adsabs.harvard.edu/abs/2000A&AS..143...41K'}'" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Encoding the JSON output from ADS \n", - "\n", - "# Note:\"DOI}, Bibcode'\"\n", - "# These above url formats produced by ADS will not code correctly and you will receive an error, to fix this change them to...\n", - "# dx.doi.org\\\\10.1051/aas:2000170, https://ui.adsabs.harvard.edu/abs/2000A&AS..143...41K\n", - "\n", - "from html.entities import html5 as _html5\n", - "import html\n", - "\n", - "s = html.escape( \"\"\"& < \" ' >\"\"\" ) # s = '& < " ' >'\n", - "html.escape(s, quote=True)\n", - "html.escape(\"{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': 'H2O-nu-0: Kurtz, M. J., G. Eichhorn, A. Accomazzi, C. S. Grant, S. S. Murray, and J. M. Watson, Title:The NASA Astrophysics Data System: Overview, Astronomy and Astrophysics Supplement Series, 143, 41-59, 2000, dx.doi.org\\\\10.1051/aas:2000170, https://ui.adsabs.harvard.edu/abs/2000A&AS..143...41K'}\")" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'ENTER JSON OUTPUT HERE'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Prompt\n", - "\n", - "from html.entities import html5 as _html5\n", - "import html\n", - "\n", - "s = html.escape( \"\"\"& < \" ' >\"\"\" ) # s = '& < " ' >'\n", - "html.escape(s, quote=True)\n", - "html.escape(\"ENTER JSON OUTPUT HERE\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 6. BibTeX citation" - ] - }, - { - "cell_type": "code", - "execution_count": 156, - "metadata": {}, - "outputs": [], - "source": [ - "# If you have not already recieved the BibTeX citation then it is because your paper is not in ADS\n", - "# Step 1 and 3 both have can give you BibTeX citations but they require that your paper is in ADS\n", - "# This method only uses GScholar and does not utilize ADS, therefore you can retrieve your BibTeX citation here \n", - "# This is the code to retrieve the citation. \n", - "# Below this cell is an example of retrieving the citation using an example DOI and a Prompt to Enter your DOI!\n", - "\n", - "import gscholar \n", - "import urllib\n", - "import bs4\n", - "from gscholar import query\n", - "from urllib import request, parse\n", - "from bs4 import BeautifulSoup \n", - "\n", - "#Class Bibtex\n", - "class Bibtex(object):\n", - " \"\"\" Convert doi number to get bibtex entries.\"\"\"\n", - " def __init__(self, doi=None, title=None):\n", - " \"\"\"Input doi number-- Returns doi, encoded doi, and doi url.\"\"\"\n", - " _base_url = \"http://dx.doi.org/\"\n", - " 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", - "\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)\n", - " return self.soup \n", - "\n", - " def getGScholar(self):\n", - " bibtex = query(self.doi, 4)[0]\n", - " self.bibtex = bibtex\n", - " return self.bibtex" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@article{biennier1998high,\n", - " title={High Resolution Spectrum of the (3--0) Band of theb1$\\Sigma$+ g--X3$\\Sigma$- gRed Atmospheric System of Oxygen},\n", - " author={Biennier, Ludovic and Campargue, Alain},\n", - " journal={Journal of molecular spectroscopy},\n", - " volume={2},\n", - " number={188},\n", - " pages={248--250},\n", - " year={1998}\n", - "}\n", - "\n" - ] - } - ], - "source": [ - "# Example\n", - "doi = \"10.1006/jmsp.1997.7521\"\n", - "bib = Bibtex(doi)\n", - "print(bib.getGScholar())" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@article{prashant2009managing,\n", - " title={Managing strategic alliances: what do we know now, and where do we go from here?},\n", - " author={Prashant, Kale and Harbir, Singh},\n", - " journal={Academy of management perspectives},\n", - " volume={23},\n", - " number={3},\n", - " pages={45--62},\n", - " year={2009},\n", - " publisher={Academy of Management Briarcliff Manor, NY}\n", - "}\n", - "\n" - ] - } - ], - "source": [ - "# Prompt\n", - "# Note this method can either search for DOI, Keywords or Titles\n", - "doi = \"ENTER DOI HERE\"\n", - "bib = Bibtex(doi)\n", - "print(bib.getGScholar())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Getting Titles in All 3 Formats" - ] - }, - { - "cell_type": "code", - "execution_count": 163, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': \"Complex-scaled multireference configuration-interaction method to study Be and Be-like cations' (B, C, N, O, Mg) Auger resonances 1s2s22p 1,3Po\"}\n", - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': '[\"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>\"'}\n", - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': '\\\\bibitem[\"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}$\"]'}\n" - ] - } - ], - "source": [ - "import requests\n", - "import json\n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "# JSON / HTML\n", - "payload = {\"bibcode\":[\"2012PhRvA..85c2515Z\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format':'%T'}\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", - "print(r.json())\n", - "\n", - "# HTML\n", - "payload = {\"bibcode\":[\"2012PhRvA..85c2515Z\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': '%ZEncoding:html[\"%T\"'}\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", - "print(r.json())\n", - "\n", - "# LaTeX\n", - "payload = {\"bibcode\":[\"2012PhRvA..85c2515Z\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format': '%ZEncoding:latex\\\\bibitem[\"%T\"]'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Set Authors to HITRAN Format" - ] - }, - { - "cell_type": "code", - "execution_count": 161, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': 'Zhang, S. B. and D. L. Yeager'}\n" - ] - } - ], - "source": [ - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "\n", - "payload = {\"bibcode\":[\"2012PhRvA..85c2515Z\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format':'%I'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "code", - "execution_count": 105, - "metadata": {}, - "outputs": [], - "source": [ - "#def full_name(name):\n", - "# \"\"\"Changing first name in Authors list.\"\"\"\n", - "# full_name = input(\"Enter your name\\n\")\n", - "# return(\"{} {} {}\".format(full_name.casefold().title().split()[1],full_name.casefold().title().split()[2],full_name.casefold().title().split()[0]))\n", - "# full_name(\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": 96, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "S. B. Zhang,\n" - ] - } - ], - "source": [ - "s = \"Zhang, S. B.\"\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": 99, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "S. B. C. Zhang,\n" - ] - } - ], - "source": [ - "s = \"Zhang, S. B. C.\"\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": 107, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "S. Zhang,\n" - ] - } - ], - "source": [ - "s = \"Zhang, S.\"\n", - "words = s.split(' ') \n", - "string =[] \n", - "for word in words: \n", - " string.insert(-1, word) \n", - "print(\" \".join(string)) " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test Article Numbers" - ] - }, - { - "cell_type": "code", - "execution_count": 155, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'msg': 'Retrieved 1 abstracts, starting with number 1.', 'export': 'e0115434'}\n" - ] - } - ], - "source": [ - "# 10.1371/journal.pone.0115434\n", - "# Their as page numbers\n", - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", - "payload = {\"bibcode\":[\"2015PLoSO..1015434S\"],\\\n", - " \"sort\": \"first_author asc\",\\\n", - " 'format':'%p-%P'}\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", - "print(r.json())" - ] - }, - { - "cell_type": "code", - "execution_count": 158, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@article{cheryan2015cultural,\n", - " title={Cultural stereotypes as gatekeepers: Increasing girls’ interest in computer science and engineering by diversifying stereotypes},\n", - " author={Cheryan, Sapna and Master, Allison and Meltzoff, Andrew N},\n", - " journal={Frontiers in psychology},\n", - " volume={6},\n", - " pages={49},\n", - " year={2015},\n", - " publisher={Frontiers}\n", - "}\n", - "\n" - ] - } - ], - "source": [ - "# 10.3389/fpsyg.2015.00049\n", - "# Example\n", - "doi = \"10.3389/fpsyg.2015.00049\"\n", - "bib = Bibtex(doi)\n", - "print(bib.getGScholar())" - ] - }, - { - "cell_type": "code", - "execution_count": 159, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@article{baud2014genomes,\n", - " title={Genomes and phenomes of a population of outbred rats and its progenitors},\n", - " author={Baud, Amelie and Guryev, Victor and Hummel, Oliver and Johannesson, Martina and Sequencing, The Rat Genome and Hermsen, Roel and Stridh, Pernilla and Graham, Delyth and McBride, Martin W and Foroud, Tatiana and others},\n", - " journal={Scientific data},\n", - " volume={1},\n", - " pages={140011},\n", - " year={2014},\n", - " publisher={Nature Publishing Group}\n", - "}\n", - "\n" - ] - } - ], - "source": [ - "# 10.1038/sdata.2014.11\n", - "doi = \"10.1038/sdata.2014.11\"\n", - "bib = Bibtex(doi)\n", - "print(bib.getGScholar())" - ] - }, - { - "cell_type": "code", - "execution_count": 160, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@article{pasanen2008neuromuscular,\n", - " title={Neuromuscular training and the risk of leg injuries in female floorball players: cluster randomised controlled study},\n", - " author={Pasanen, Kati and Parkkari, Jari and Pasanen, Matti and Hiilloskorpi, Hannele and M{\\\"a}kinen, Tanja and J{\\\"a}rvinen, Markku and Kannus, Pekka},\n", - " journal={Bmj},\n", - " volume={337},\n", - " pages={a295},\n", - " year={2008},\n", - " publisher={British Medical Journal Publishing Group}\n", - "}\n", - "\n" - ] - } - ], - "source": [ - "# 10.1136/bmj.a295\n", - "doi = \"10.1136/bmj.a295\"\n", - "bib = Bibtex(doi)\n", - "print(bib.getGScholar())" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/res/conf-TEMPLATE.py b/res/conf-TEMPLATE.py new file mode 100644 index 0000000..37568a2 --- /dev/null +++ b/res/conf-TEMPLATE.py @@ -0,0 +1,4 @@ +import os +webapp_path = os.path.join('/Users/your_name/name_of_file') + +# enter your main file location that you are using diff --git a/res/frances-tests/test_0.py b/res/frances-tests/test_0.py new file mode 100644 index 0000000..ab58658 --- /dev/null +++ b/res/frances-tests/test_0.py @@ -0,0 +1,65 @@ +import os +import sys +import django +import requests +import json +from urllib import request, parse +from bs4 import BeautifulSoup + +from conf import webapp_path +sys.path.append(webapp_path) + +os.environ['DJANGO_SETTINGS_MODULE'] = 'pyref.settings' + +django.setup() + +from refs.models import Ref, get_ref_from_doi + +class Bibtex(object): + """ Convert doi number to get bibtex entries.""" + def __init__(self, doi=None, title=None): + """Input doi number-- Returns doi, encoded doi, and doi url.""" + _base_url = "http://dx.doi.org/" + self.doi = doi + self.title = title + self.bibtex = None + if doi: + self._edoi = parse.quote(doi) + self.url = _base_url + self._edoi + else: + self.url = None + +# Beautiful Soup is a Python library for pulling data out of HTML and XML files + def _soupfy(self, url): + """Returns a soup object.""" + html = request.urlopen(url).read() + self.soup = BeautifulSoup(html) + return self.soup + +# Get the ADS link for the paper + def getADS(self): + """Get bibtex entry from doi using ADS database.""" + uri = "http://adsabs.harvard.edu/cgi-bin/basic_connect?qsearch=" + url = uri + self._edoi + +# Make Beautiful Soup look for ADS Bibcode (which is necessary for retrieving the ADS link) + soup = self._soupfy(url) + try: + tag = soup.findAll('input', attrs={"name": "bibcode"})[0] + except IndexError: + print("\nADS failed\n") + else: + bibcode = tag.get('value') if tag.get('value') else None + uri = 'http://adsabs.harvard.edu/cgi-bin/nph-bib_query?bibcode=' + end = '&data_type=BIBTEX&db_key=AST%26nocookieset=1' + url = uri + bibcode + end + bib = request.urlopen(url).read().decode('utf-8') + bib = bib.split('\n') + self.bibtex = '\n'.join(bib[5:-1]) + finally: + return self.bibtex + +doi = '10.1103/PhysRevA.85.032515' +bib = Bibtex(doi) +print(bib.getADS()) + diff --git a/res/frances-tests/test_1.py b/res/frances-tests/test_1.py new file mode 100644 index 0000000..f138b75 --- /dev/null +++ b/res/frances-tests/test_1.py @@ -0,0 +1,192 @@ +from django.test import TestCase + +#class DOIResolveTest(TestCase): + + # def test_resolving_doi_populates_add_reference_page(self): + # doi = input("Enter doi Here: ") #10.1103/PhysRevA.85.032515 + # url = '/refs/resolve/?doi=' + doi + # response = self.client.get(url) + + # self.assertContains(response, + # r'',html=True) + +# Create your tests here. +import os +import sys +import django +import requests +import json +import urllib.request +from urllib.error import HTTPError +import html +import re +import logging +from bs4 import BeautifulSoup +from html.entities import name2codepoint +from urllib.request import quote, Request, urlopen + +from conf import webapp_path +sys.path.append(webapp_path) +os.environ['DJANGO_SETTINGS_MODULE'] = 'pyref.settings' +django.setup() + +from refs.models import Ref, get_ref_from_doi + +##########Code from Models####################################################################### +def get_citeproc_authors(cpd_author): + if cpd_author is None: + return None + names = [] + for author in cpd_author: + try: + family = author['family'].title() + except KeyError: + name = author['name'] + names.append(name) + continue + try: + given = author['given'] + except KeyError: + # This author has first name + names.append(family) + continue + initials = given.split() + initials[0] = '{}.'.format(initials[0][0]) + initials = ' '.join(initials) + names.append('{} {}'.format(initials, family)) + return ', '.join(names) + +def parse_citeproc_json(citeproc_json): + """Parse the provided JSON into a Ref object.""" + + cpd = json.loads(citeproc_json) + try: + if cpd['type'] != 'article-journal': + return None + except KeyError: + return None + + authors = get_citeproc_authors(cpd.get('author', '')) + title = cpd.get('title', '').replace('\n', '') + journal = cpd.get('container-title', '') + volume = cpd.get('volume', '') + page_start, page_end = cpd.get('page', ''), '' + if page_start and '-' in page_start: + page_start, page_end = page_start.split('-') + article_number = cpd.get('article-number', '') + doi = cpd.get('DOI', '') + url = cpd.get('URL', '') + try: + year = cpd['issued']['date-parts'][0][0] + except (KeyError, IndexError): + year = None + + try: + bibcode = cpd.get('bibcode', '') + except (KeyError, IndexError): + bibcode = None + +# # ============================================================================= +# # OUTPUT +# # ============================================================================= + ref = [authors, + title, + journal, + volume, + year, + page_start, + page_end, + doi, + url, + article_number, + citeproc_json] + return ref + +def get_citeproc_json_from_doi(doi): + base_url = 'http://dx.doi.org/' + url = base_url + doi + req = urllib.request.Request(url) + req.add_header('Accept', 'application/citeproc+json') + try: + with urllib.request.urlopen(req) as f: + citeproc_json = f.read().decode() + except HTTPError as e: + if e.code == 404: + raise ValueError('DOI not found.') + raise + return citeproc_json + +def get_source_from_doi(doi): + citeproc_json = get_citeproc_json_from_doi(doi) + ref = parse_citeproc_json(citeproc_json) + return ref + + +#########This section will get you the Bibcode for the ADS sections to run properly############### +doi = input("Enter DOI Here: ") +doi_fetched = get_source_from_doi(doi) + +token = ads_token + +rdoi = doi + +rdoi_bs = rdoi.replace("\\", "%2F") # Remove backslash and replace with URL code for backslash +rdoi_fs = rdoi_bs.replace("/", "%2F") # Remove forwardslash and replace with URL code for backslash + +rurl = requests.get("https://api.adsabs.harvard.edu/v1/search/query?q=doi:"+rdoi_fs,\ + params={"q":"*:*", "fl": "*", "rows":2000}, + headers={'Authorization': 'Bearer ' + token}) + +todos = json.loads(rurl.text) +todos_response = todos.get('response', '') + + +Bibcode = (todos_response['docs'][0]['bibcode']) + +print(Bibcode) + +##########################This section uses ADS to get the LaTeX encoded Title########################## +token="gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY" +payload = {"bibcode": ["{}".format(Bibcode)], + "sort": "first_author asc", + "format": + '''{"ref_json": {"encoder": "%ZEncoding:latex\\bibitem", + "title": "%T"}}''' + } +r = requests.post("https://api.adsabs.harvard.edu/v1/export/custom", \ + headers={"Authorization": "Bearer " + token, "Content-type": "application/json"}, \ + data=json.dumps(payload)) +response_json = r.json() +print('-'*72) +print(response_json['export']) +print('-'*72) +ref_json = json.loads(response_json['export'])['ref_json'] + +print('title bibtex:', ref_json['title']) + +####################This section uses ADS to get the html encoded title###################### + +payload = {"bibcode": ["{}".format(Bibcode)], + "sort": "first_author asc", + "format": + '''{"ref_json": {"title": "%T"}}''' + } +r = requests.post("https://api.adsabs.harvard.edu/v1/export/custom", \ + headers={"Authorization": "Bearer " + token, "Content-type": "application/json"}, \ + data=json.dumps(payload)) +response_json = r.json() +ref_json = json.loads(response_json['export'])['ref_json'] + +print('title html:', ref_json['title']) + + + + + + + + + + + + diff --git a/res/frances-tests/test_2.txt b/res/frances-tests/test_2.txt new file mode 100644 index 0000000..ab5eddb --- /dev/null +++ b/res/frances-tests/test_2.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/res/frances-tests/test_3.py b/res/frances-tests/test_3.py new file mode 100644 index 0000000..fa9ebf1 --- /dev/null +++ b/res/frances-tests/test_3.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) diff --git a/notebooks/pyref-test.ipynb b/res/frances-tests/test_4.ipynb similarity index 97% rename from notebooks/pyref-test.ipynb rename to res/frances-tests/test_4.ipynb index dcc7c48..d1fcd93 100644 --- a/notebooks/pyref-test.ipynb +++ b/res/frances-tests/test_4.ipynb @@ -8,7 +8,7 @@ "source": [ "import os\n", "import sys\n", - "#webapp_path = os.path.join('/Users/christian/www/pyref')\n", + "#webapp_path = os.path.join('/Users/name/www/pyref')\n", "webapp_path = os.path.join('../pyref')\n", "sys.path.append(webapp_path)" ] @@ -84,7 +84,7 @@ "metadata": {}, "outputs": [], "source": [ - "token=\"gx43LyUuTTD0zoTWx8qKpWbWi3euTmx7FCM3fJjY\"\n", + "token=\ads_token\n", "payload = {\"bibcode\": [\"2019MNRAS.488.2332L\"],\n", " \"sort\": \"first_author asc\",\n", " \"format\":\n", diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b085fe1 --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +import os +from setuptools import find_packages, setup + +with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme: + README = readme.read() + +# allow setup.py to be run from any path +os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) + + # Project uses reStructuredText, so ensure that the docutils get + # installed or upgraded on the target machine + install_requires=["docutils>=0.3"], + +setup( + name='refs', + version='0.1', + packages=find_packages(), + include_package_data=True, + license='Apache Software Foundation', + description='An automatic referencing system for scientific databases', + long_description=README, + keywords="database, HITRAN, reference, citation", + url='https://github.com/hitranonline', + author='Frances Skinner, Iouli Gordon, Christian Hill, Robert Hargreaves and Kelly Lockhart', + author_email='hitran-admin@cfa.harvard.edu', + classifiers=[ + 'Environment :: Web Environment', + 'Framework :: Django', + 'Framework :: Django :: 1.11.8', + 'Intended Audience :: Developers', + 'License :: Apache License, Version 2.0', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + ], +)