Code Monkey home page Code Monkey logo

ads2bibdesk's Introduction

ADS to BibDesk API edition (ads2bibdesk)

ads2bibdesk helps you add astrophysics articles listed on NASA/ADS to your BibDesk database using the new ADS Developer API.

The program is loosely based on the original ads_bibdesk from J. Sick et al. However, the query is handled with a python client for the ADS API (ads, maintained by A. Casey). Obsolete codes are replaced in favor of newer built-in Python modules with a simplified code structure. The macOS workflow building process have been updated. The project packaging now follows the new PyPA guideline.

Due to the API usage, ads2bibdesk requires the user to specify a personal API key, per the new NASA/ADS policy. The instruction on how to obtain a key can be found on this official github repo: adsabs-dev-api. In short, to obtain access to the ADS Developer API, one must do two things:

The API key can be written into your ads2bibdesk preference file ~/.ads/ads2bibdesk.cfg (see the template). Following the Python/ads package's instruction, one can also save the key to ~/.ads/dev_key or as an environment variable named ADS_DEV_KEY.

Credit to the contributors of the original ads_bibdesk @jonathansick @RuiPereira @keflavich for their initial implementation.

Quickstart

Installation

The command line script can be installed via:

pip install --user git+https://github.com/r-xue/ads2bibdesk.git # from GitHub
pip install --user ads2bibdesk                                  # from PyPI (likely behind the GitHub version)
pip install --user .                                            # from a local copy

To build the macOS app and service workflow, you need to further run:

pip install --user -U --no-deps --force-reinstall --install-option="--service" ads2bibdesk     # from PyPI

The option "--service" will create two files Add to BibDesk.workflow and Add to BibDesk.app in ~/Downloads/. To install the service, click Add to BibDesk.workflow and it will be moved to ~/Library/Services/. For the app, just drag and drop it to any preferred location.

Note:

  • Only Python >=3.7 is supported (see below).
  • With the "--user" option, you must add the user-level bin directory (e.g., ~/Library/Python/3.X/bin) to your PATH environment variable in order to launch ads2bibdesk.
  • Both the macOS service and app are based on the Automator workflow). They simply wrap around the command line program and serve as its shortcuts.
  • The service shortcut will not work within some applications (e.g., Safari) on macOS >=10.14 due to new privacy and security features built in macOS (see this issue)

Usage

From the Command line

Add or update a new article from ADS:

ads2bibdesk "1807.04291"
ads2bibdesk "2018ApJ...864L..11X"
ads2bibdesk "2013ARA&A..51..105C"
ads2bibdesk "10.3847/2041-8213/aaf872"

ads2bibdesk accepts three kinds of article identifier at this moment

  • ADS bibcode (e.g. 1998ApJ...500..525S, 2019arXiv190404507R)
  • arXiv id (e.g. 0911.4956).
  • doi (e.g. 10.3847/1538-4357/aafd37)

A full summary of ads2bibdesk commands is available via:

ads2bibdesk --help

From the macOS app

  1. Copy the article identifider to the clipboard, in any application
  2. launch Add to BibDesk.app

From the macOS service

  1. Highligh and right-click on the article identifider
  2. Choose 'Services > Add to Bibdesk' from the right-click menu

Compatibility and Dependency

I've only tested the program on the following macOS setup:

  • macOS (>=10.14)
  • Python (>=3.7.3)
  • BibDesk (>=1.7.1)

While the program likely works on slightly older software versions, I don't focus on the backward compatibility. On my working machine (Catalina), I set Python 3.8 from MacPorts as default:

sudo port install python38 py38-pip py38-ipython
sudo port select python python38
sudo port select ipython py38-ipython
sudo port select pip pip38

Status

The following functions have already been implemented in the package:

  • query the article metadata (title, abstract, BibTeX, etc.) with the new API by article identifiers (no more in-house ADS/arxiv HTML parsing functions)
  • download article PDFs using the ADS gateway links
  • use an authorized on-campus ssh proxy machine (with your public key) to download PDFs behind the journal paywall
  • add/update the BibDesk database and attach downloaded PDFs (largely borrowing the AppleScript method from the original ads_bibdesk)

Other changes from the original ads_bibdesk include:

  • clean up the dependency requirements
  • replace obsolete Python syntax/functions/modules with newer ones, e.g. optparser->argparser, f-string formatting, and use configparser()
  • The macOS Automator workflow is running the installed console script rather than an embedded Python program

Some less-used features from the original ads_bibdesk are gone: notably, the "ingest" and "preprint-update" modes. But I plan to at least add back the "preprint-update" option, by scanning/updating article_bibcode associated with arXiv). My improvement proposal can be found here.

ads2bibdesk's People

Contributors

ebellm avatar morisset avatar r-xue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ads2bibdesk's Issues

Long author list is truncated

ads2bibdesk 2023APh...15002850A

The above command imports the paper information as expected but its author list is truncated and and et al. is added. Changing the ADS code to DOI 10.1016/j.astropartphys.2023.102850 does not help.

Workflow not working

Thank you for this nice tool. While the command line works in the terminal, this is not the case for the workflow. As it never worked for me (using the new version since about 1 year or more maybe), I thought some may have the same issue so I decided to post the error. When I click to "add to bibdesk", I have the following error:

L’action « Exécuter un script Shell » a rencontré une erreur : « Starting ADS to BibDesk
Traceback (most recent call last):
File "/Users/agallenn/.local/bin/ads2bibdesk", line 33, in
sys.exit(load_entry_point('ads2bibdesk==0.2.dev3', 'console_scripts', 'ads2bibdesk')())
File "/Users/agallenn/.local/lib/python3.8/site-packages/ads2bibdesk/ads2bibdesk.py", line 111, in main
article_status = process_article(args, prefs)
File "/Users/agallenn/.local/lib/python3.8/site-packages/ads2bibdesk/ads2bibdesk.py", line 141, in process_article
bibdesk = BibDesk()
File "/Users/agallenn/.local/lib/python3.8/site-packages/ads2bibdesk/bibdesk.py", line 19, in init
self.refresh()
File "/Users/agallenn/.local/lib/python3.8/site-packages/ads2bibdesk/bibdesk.py", line 53, in refresh
self.titles = self('return title of publications', strlist=True)
File "/Users/agallenn/.local/lib/python3.8/site-packages/ads2bibdesk/bibdesk.py", line 44, in call
for i in range(output.numberOfItems())]
AttributeError: 'NoneType' object has no attribute 'numberOfItems' »

Note that I always had the same error since I installed your version.

Info system: MacOS 10.15.7, Python 3.8.10, Bibdesk 1.8.3

ads2bibdesk not working after latest bibdesk update 1st April 2020

Dear r-xue,

I am a big fan of this code and use it all the time. However, yesterday I updated bibdesk and it appeared to stop working. The error message was as follows:

Starting ADS to BibDesk
Traceback (most recent call last):
File "/Users/hamish/.local/bin/ads2bibdesk", line 10, in
sys.exit(main())
File "/Users/hamish/.local/lib/python3.7/site-packages/ads2bibdesk.py", line 90, in main
article_status=process_article(args ,prefs)
File "/Users/hamish/.local/lib/python3.7/site-packages/ads2bibdesk.py", line 99, in process_article
article_status=process_token(args.article_identifier, prefs, bibdesk)
File "/Users/hamish/.local/lib/python3.7/site-packages/ads2bibdesk.py", line 234, in process_token
pub = pub.descriptorAtIndex_(1).descriptorAtIndex_(3).stringValue()
AttributeError: 'NoneType' object has no attribute 'descriptorAtIndex_'

Can you please help

EDIT: I just saw your post about not updating to 1.7.5. I have gone back to 1.7.4. Thanks again for all your effort with this program!

arXiv PDF is downloaded instead of published PDF

ads2bibdesk 10.3847/2041-8213/acdac6

downloads the paper PDF from arXiv instead of retrieving the final published PDF from ApJL.

Similar papers are downloaded as expected.

ads2bibdesk 10.3847/2041-8213/acda88
ads2bibdesk 10.3847/2041-8213/acda9a

Suggestion - Rename PDF files by first author and year

Dear r-xue,

This is an enhancement suggestion.

Is it possible for ads2bibdesk to name the downloaded PDFs using the first author name and the date. So your paper this year might be named Xue2020.pdf. And your second paper this year could be Xue2020b.pdf (etc etc).

Currently the papers that ads2bibdesk downloads for me have names like tmpav9l1brw.pdf

Kind regards

AttributeError: 'NoneType' object has no attribute 'deliverNotification_'

When running ads2bibdesk on the key ADS '1976JAtS...33.2049A', I get the following error:

Starting ADS to BibDesk
Traceback (most recent call last):
File "/Users/townsend/.local/lib/python3.7/site-packages/ads2bibdesk/ads2bibdesk.py", line 523, in notify
center.deliverNotification_(notification)
AttributeError: 'NoneType' object has no attribute 'deliverNotification_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/townsend/bin/ads2bibdesk", line 10, in
sys.exit(main())
File "/Users/townsend/.local/lib/python3.7/site-packages/ads2bibdesk/ads2bibdesk.py", line 110, in main
article_status = process_article(args, prefs)
File "/Users/townsend/.local/lib/python3.7/site-packages/ads2bibdesk/ads2bibdesk.py", line 142, in process_article
article_status = process_token(args.article_identifier, prefs, bibdesk)
File "/Users/townsend/.local/lib/python3.7/site-packages/ads2bibdesk/ads2bibdesk.py", line 269, in process_token
bibdesk('cite key', pid).stringValue(), ads_article.title[0], alert_sound=alert_sound)
File "/Users/townsend/.local/lib/python3.7/site-packages/ads2bibdesk/ads2bibdesk.py", line 526, in notify
except ExplicitException:
NameError: name 'ExplicitException' is not defined

Hoping for a quick fix!

Import fails with empty abstract

If there is no abstract the import will fail with

AttributeError: 'NoneType' object has no attribute 'replace'
> /Users/ebellm/Eric/Archive/Projects/ads2bibdesk/ads2bibdesk.py(240)process_token()
    238
    239     # abstract
--> 240     ads_abstract_clean=ads_article.abstract.replace('\\', r'\\').replace('"', r'\"').replace('}', ' ').replace('{', ' ')
    241     bibdesk(f'set abstract to "{ads_abstract_clean}"', pub)
    242

notifications break

Hi,

I'm running python 3.6, on 10.12. The code works well so far, with one exception - notify module results in error.

objc.lookUpClass('NSUserNotificationCenter').\

AttributeError: 'NoneType' object has no attribute 'scheduleNotification_'

During handling of the above exception, another exception occurred:

growl_notify(title, desc, sticky)

NameError: name 'growl_notify' is not defined

Commenting out the last line has fixed it, resulting in a successful download.

Please introduce the configuration file ads2bibdesk.cfg in the README (or did I miss it?)

For a long time I have been trying to find a way to disable downloading PDF automatically but failed. After digging into the code I realized there is a configuration file ~/.ads/ads2bibdesk.cfg in which you can set download_pdf=False. I know you have

The API key can be written into your ads2bibdesk preference file ~/.ads/ads2bibdesk.cfg (see the template)

in your README, but without a care read of the template, I didn't know there is a configuration file at all. I would be helpful to the readers if you could mention there is a configuration file where you can configure download_pdf, ssh_user, etc.

Big Sur

Hi, after updating to Big Sur I can't make it to work. I get the error message below. Any advice appreciated.
Thanks,
Dimitris

Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/bin/ads2bibdesk", line 33, in
sys.exit(load_entry_point('ads2bibdesk==0.2.dev3', 'console_scripts', 'ads2bibdesk')())
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/bin/ads2bibdesk", line 25, in importlib_load_entry_point
return next(matches).load()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 790, in exec_module
File "", line 228, in _call_with_frames_removed
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ads2bibdesk/ads2bibdesk.py", line 22, in
from .bibdesk import BibDesk
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ads2bibdesk/bibdesk.py", line 5, in
import AppKit # from pyobjc-framework-Cocoa
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/AppKit/init.py", line 10, in
import Foundation
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Foundation/init.py", line 9, in
import CoreFoundation
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/CoreFoundation/init.py", line 9, in
import objc
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/objc/init.py", line 6, in
from . import _objc
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/objc/_objc.cpython-39-darwin.so, 2): Symbol not found: _ffi_find_closure_for_code_np
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/objc/_objc.cpython-39-darwin.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/objc/_objc.cpython-39-darwin.so

--install-option was deprecated in pip v22.3 and has been removed completely in v23.1.

When I tried to run pip install --user -U --no-deps --force-reinstall --install-option="--service" ads2bibdesk under Mac OS 14 with pip 23.1.2, I got an error no such option: --install-option

So following this discussion:

--install-option was deprecated in pip v22.3 and has been removed completely in v23.1.

I ran python -m pip install pip==22.2.1 and I was able to build the service.

Hopefully this is helpful and looking forward to an update addressing this issue.

Won't work with BibDesk v1.7.5

One will get an error message from the AppleScript call of adding new BibTeX entries.

BibDesk got an error: document 1 doesn’t understand the “import” message.

temporary workaround: just don't upgrade to BibDesk v1.7.5 util the change is clarified.

update: reported the bug to the BibDesk developers and it will be fixed in their next release.

articles without the PDF gateway links

For some articles, the direct publisher PDF links are not available on ADS (e.g. 2014PhR...541...45C, 2011Natur.470..233C, 2015Sci...348..779H). Therefore, the ArXiv-version PDFs were downloaded, instead of publisher-versions. Some last code changes in the forked ads_bibdesk could be borrowed to help resolve the issue, by guessing the PDF direct link from the HTML link/content.

Problems running on Catalina

I recently updated from macOS High Sierra to Catalina. ads2bibdesk was working fine on High Sierra but now gives errors (see below). I'm trying to run this in python 3.7.9 managed with conda. Does this need a different version of ImageMagick? Are there other tricks or suggestions? Thanks.
ads2bibdesk_errors.txt

App problem finding bibcodes

I am getting the following error message in the log, and nothing happens.

2021-06-17 11:48:14 ads2bibdesk.ads2bibdesk.main [INFO] : Starting ADS to BibDesk
2021-06-17 11:48:25 ads2bibdesk.ads2bibdesk.process_token [INFO] : Found Zero or Multiple ADS antries for [valid API key]
2021-06-17 11:48:25 ads2bibdesk.ads2bibdesk.process_token [INFO] : No update in BibDesk

I just created the .ads directory (so no pre-existing files present) and added my brand new API key from ADS to ads2bibdesk.cfg, but still got this error.

the "preprint-update" option

We can restore the "preprint-update" option from the original ads_bibdesk, by scanning/updating BibDesk entries with article_bibcode in the arXiv style (something like 2019arXiv1234.5678).

Found Zero or Multiple ADS antries for ...

I am trying to use ads2bibdesk from the commandline. It worked fine until maybe a week ago when I used it last time. I have not used this for a week and have not updated the OS or python.

Now I get this "zero or multiple entries" error for basically any arXiv number I feed ...

Starting ADS to BibDesk
Found Zero or Multiple ADS antries for 2209.09905

am I the only one seeing this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.