Skip to content

Commit

Permalink
tweaking orcid search (#48)
Browse files Browse the repository at this point in the history
* not allowing orcid search without first and last name, and adding other-names to search
* moving reference to no longer used token
* adding basic tests for orcid
* removing parameters from search, worksbetter without
Co-authored-by: Yaroslav Halchenko <debian@onerussian.com>
Signed-off-by: vsoch <vsochat@stanford.edu>
Co-authored-by: Yaroslav Halchenko <debian@onerussian.com>
  • Loading branch information
vsoch committed Aug 6, 2020
1 parent e532d4c commit 6bc1abd
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 96 deletions.
5 changes: 2 additions & 3 deletions .tributors
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"yarikoptic": {
"name": "Yaroslav Halchenko",
"blog": "www.onerussian.com",
"email": "debian@onerussian.com",
"bio": "Cheers!",
"orcid": "0000-0003-3456-2493",
"affiliation": "Dartmouth College"
"affiliation": "Dartmouth College",
"bio": "Cheers!"
},
"vsoch": {
"name": "Vanessasaurus",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip.

## [0.0.x](https://github.com/con/tributors/tree/master) (0.0.x)
- searching orcid for other-names as final resort, requiring first/last (0.0.19)
- searching for last, first and reverse for orcid lookup (0.0.18)
- unicode characters allowed, and dont update users with orcids (0.0.17)
- should allow for repository names with .git extension (0.0.15)
Expand Down
68 changes: 31 additions & 37 deletions docs/_docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,12 @@ pip install tributors

### 2. Environment

Especially if you need orcid ids in your metadata, for a first time go you
should export an id and secret to interact with the Orcid API. It'a also recommended
to export a GitHub token to increase your API limit:
It's recommended to export a GitHub token to increase your API limit:

```bash
export ORCID_ID=APP-XXXXXXX
export ORCID_SECRET=12345678910111213141516171819202122
export GITHUB_TOKEN=XXXXXXXXXXXXXXX
```

Once you generate an orcid token, it will be written to a temporary file,
and you can read the file and export the variable for later discovery (and you'll
no longer need the ID and secret):

```bash
export ORCID_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXX
```

### 3. Update Lookups

Before you update your contribution files, you probably want to update your .tributors
Expand Down Expand Up @@ -153,6 +141,36 @@ $ tributors update zenodo
$ tributors update codemeta
```

If the client finds more than one orcid identifier for a name, you'll be prompted
to run in `--interactive` mode. Running in interactive mode will allow you
to choose a number for each one:

```bash
$ tributors update zenodo --interactive
INFO: zenodo:Updating .zenodo.json
INFO: zenodo:Updating .tributors cache from .zenodo.json

Meyer, Kyle
======================================================
[1]
Name: Meyer, Kyle
Orcid: 0000-0002-1933-2908
Institutions: University of California Davis, University of Michigan, University of Texas at Austin

[2]
Name: Meyer, Kyle
Orcid: 0000-0001-8632-4425
Institutions: Kroger Co, Northeastern Ohio Medical University, University of Toledo, University of Toledo Medical Center

[3]
Name: Meyer, Kyle
Orcid: 0000-0001-8846-7411
Institutions: University of Auckland, University of Oregon, University of Wisconsin Milwaukee

Please enter a choice, or s to skip.
[1:3 or s to skip] :
```

### 3. Init
You can also create empty files if you don't have them yet:

Expand Down Expand Up @@ -411,30 +429,6 @@ export ZENODO_TOKEN=xxxxxx
export GITHUB_TOKEN=xxxxxx
```

If you want to link emails with Orcid id's, it is suggested to generate and export an `ORCID_TOKEN` to ensure that you can look up these identifiers based on email addresses.
However to disable this, simply export the token as "disabled"

```bash
export ORCID_TOKEN=disabled
```

In order to generate this token
for the first time, you should export an `ORCID_ID` and `ORCID_SECRET` that you need to
generate in the [developer tools](https://orcid.org/developer-tools). The callback
uri can be either one of the defaults that they provide (we don't use it).
Once you have your id and secret, export them to the environment.

```bash
export ORCID_ID=xxxxxxxx
export ORCID_SECRET=xxxxx
```

The `ORCID_TOKEN` and `ORCID_REFRESH_TOKEN` will be written to a temporary file,
and you can export these in the future to be discovered by the tributors client.
Subsequent requests use the token to interact with the [public search API](https://members.orcid.org/api/tutorial/search-orcid-registry). Note that we haven't
yet implemented using the refresh token to request a new one, so if you
hit this use case, please [open an issue](https://github.com/con/tributors/issues).

### 2. Generate

Generate means that you don't have a particular metadata file for a service,
Expand Down
43 changes: 43 additions & 0 deletions tests/test_orcid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
"""
Copyright (C) 2020 Vanessa Sochat.
This Source Code Form is subject to the terms of the
Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""

import os
import pytest


def test_queries(tmp_path):
"""test that changing order of First Last and Last, First returns same result
"""
from tributors.main.orcid import get_orcid, record_search

orcid_id = "0000-0003-3456-2493"

# Test different orders of name
result = get_orcid(email=None, name="Yaroslav Halchenko")
assert result == orcid_id
result = get_orcid(email=None, name="Halchenko, Yaroslav")
assert result == orcid_id

# Test lookup by email
result = get_orcid(email="debian@onerussian.com")
assert result == orcid_id

# Test search for other name
result = get_orcid(email=None, name="Ярослав Олеговіч Гальченко")
assert result == orcid_id

# Test returning None
result = get_orcid(email=None, name="Zumbudda")
assert not result

# Test find by other-names (can't do because more than one result)
result = get_orcid(email=None, name="Horea Christian")
assert result == "0000-0001-7037-2449"
7 changes: 7 additions & 0 deletions tributors/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def get_parser():
)

for command in [update, init]:
command.add_argument(
"--interactive",
dest="interactive",
help="Allow interactive selection of orcid ids.",
default=False,
action="store_true",
)
command.add_argument(
"parsers",
help="Metadata file parsers to update or initialize.",
Expand Down
1 change: 1 addition & 0 deletions tributors/client/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def main(args, extra):

# Parse extra arguments
extra = parse_extra(extra)
extra["--interactive"] = args.interactive

# Skip users, if a space separated list is defined
skip_users = []
Expand Down
1 change: 1 addition & 0 deletions tributors/client/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def main(args, extra):

# Parse extra arguments
extra = parse_extra(extra)
extra["--interactive"] = args.interactive

# Start with user provided parsers
parsers = args.parsers
Expand Down
4 changes: 1 addition & 3 deletions tributors/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from tributors.main.parsers import get_named_parser
from tributors.utils.file import write_json, read_json
from .orcid import get_orcid_token
from .github import GitHubRepository
import logging
import os
Expand Down Expand Up @@ -114,18 +113,17 @@ def update(
from GitHub or a cache.
"""
parsers = parsers or []
self.orcid_token = get_orcid_token()

# Generate a shared repository object
repo = GitHubRepository(repo, skip_users=skip_users)
bot.debug(f"Found repository {repo}")

# Get resource lookup ids (emails, orcids, logins)
resources = self.get_resource_lookups(from_resources, params)

# Update each metadata file via its parser
for parser in parsers:
client = get_named_parser(name=parser, repo=repo, params=params)
client.orcid_token = self.orcid_token
client.cache = self.cache
client.update(thresh=thresh, from_resources=resources)
self.cache.update(client.cache)
Expand Down

0 comments on commit 6bc1abd

Please sign in to comment.