Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add org-ref-zotero #901

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Note many of these have been renamed with an org-ref prefix.
- [[./org-ref-bibtex.el][org-ref-bibtex]] :: Utility functions for bibtex
- [[./org-ref-latex.el][org-ref-latex]] :: org-ref-like features in LaTeX.
- [[./org-ref-arxiv.el][org-ref-arxiv]] :: arxiv links, add bibtex entries from arxiv.org.
- [[./org-ref-zotero.el][org-ref-zotero]] :: add bibtex entries from any website that is supported by [[https://github.com/zotero/translators/][Zotero translators]].
- [[./org-ref-pubmed.el][org-ref-pubmed]] :: pubmed links, add bibtex entries from PMID.
- [[./org-ref-isbn.el][org-ref-isbn]] :: Add bibtex entries from a book ISBN
- [[./org-ref-wos.el][org-ref-wos]] :: WebOfKnowledge links and queries
Expand Down
101 changes: 101 additions & 0 deletions org-ref-zotero.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
;;; org-ref-zotero.el --- Zotero utilities for org-mode -*- lexical-binding: t; -*-

;; Copyright (C) 2015 John Kitchin

;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
;; This file was contributed by Mohammad Pedramfar <https://github.com/mpedramfar>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;; this library provides functions to connect to an instance of the Zotero
;; translation server and get bibtex entries from urls.

;;; Code:
(require 'url)
(require 'org-ref-core)
(require 'f)


(defun zot-translate-get-json (url)
"Get citation data of URL in Zotero JSON format, using Zotero
translation server."
(let*
((url-request-method "POST")
(url-request-extra-headers '(("Content-Type" . "text/plain")))
(url-request-data url)
(response-buffer (url-retrieve-synchronously "http://127.0.0.1:1969/web"))
(output (with-current-buffer response-buffer
(goto-char (point-min))
(search-forward "\n\n")
(delete-region (point-min) (point))
(buffer-string))))
(kill-buffer response-buffer)
(if (equal output "URL not provided")
(user-error "URL not provided")
output)))


(defun zot-translate-get-bibtex-from-json (json)
"Convert Zotero JSON format to bibtex, using Zotero translation
server."
(let*
((url-request-method "POST")
(url-request-extra-headers '(("Content-Type" . "application/json")))
(url-request-data json)
(response-buffer
(url-retrieve-synchronously "http://127.0.0.1:1969/export?format=bibtex"))
(output (with-current-buffer response-buffer
(goto-char (point-min))
(search-forward "\n\n")
(delete-region (point-min) (point))
(buffer-string))))
(kill-buffer response-buffer)
(if (equal output "Bad Request")
(user-error "Bad Request")
output)))


(defun zot-translate-get-bibtex (url)
"Get bibtex data for URL using Zotero translation server."
(zot-translate-get-bibtex-from-json (zot-translate-get-json url)))


(defun zot-translate-add-bibtex-entry (url bibfile)
"Get bibtex entry for URL using Zotero translation server. Then
add it to BIBFILE"
(interactive
(list (read-string
"url: "
(ignore-errors (current-kill 0 t)))
;; now get the bibfile to add it to
(completing-read
"Bibfile: "
(append (f-entries "." (lambda (f) (f-ext? f "bib")))
org-ref-default-bibliography))))
(save-window-excursion
(find-file bibfile)
(goto-char (point-max))
(when (not (looking-at "^")) (insert "\n"))
(insert (zot-translate-get-bibtex url))
(org-ref-clean-bibtex-entry)
(goto-char (point-max))
(when (not (looking-at "^")) (insert "\n"))
(save-buffer)))


;;* The end
(provide 'org-ref-zotero)

;;; org-ref-zotero.el ends here
46 changes: 46 additions & 0 deletions org-ref.org
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,52 @@ This library provides an org-mode link to http://arxiv.org entries: arxiv:cond-
- ~arxiv-add-bibtex-entry~
- ~arxiv-get-pdf~

** org-ref-zotero
index:zotero

This library provides a function to get a bibtex entry for any link that is supported by [[https://github.com/zotero/translators/][Zotero translators]]:

#+BEGIN_SRC emacs-lisp
(require 'org-ref-zotero)
#+END_SRC

#+RESULTS:
: org-ref-zotero

- ~zot-translate-add-bibtex-entry~

This library sends queries to the [[https://github.com/zotero/translation-server/][Zotero translation server]].
The easiest way to run this server, as described in the readme page of the [[https://github.com/zotero/translation-server/][Zotero translation server]] is to install [[https://www.docker.com/][Docker]] and pull the translation server's image by running:

#+begin_src shell
docker pull zotero/translation-server
#+end_src

Then you can run a local instance of the server:

#+begin_src shell
docker run -d -p 1969:1969 --rm --name translation-server zotero/translation-server
#+end_src

If you run the command with the flag `--restart=always', the translation server will automatically run on system startup and you will not need to run it again:

#+begin_src shell
docker run --restart=always -d -p 1969:1969 --name translation-server zotero/translation-server
#+end_src

Note that this library will not work if the server is not running.
You can check if the server is running using:

#+begin_src shell
docker ps
#+end_src

If you want to stop the server, you can simply run:

#+begin_src shell
docker stop translation-server
#+end_src

** org-ref-sci-id
:PROPERTIES:
:ID: AD7C70CF-1BB8-4610-B9AD-580790250459
Expand Down