-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3f7adc
commit 8a499f1
Showing
7 changed files
with
525 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Examples | ||
|
||
**Ready to run** examples showing how to use **orcidpyclient** Python package. | ||
|
||
#### Script to extract BibTeX from the ORCID | ||
|
||
* Script extracts bibtex from the ORCID: [extracting_bibtex.py](examples/extracting_bibtex.py) | ||
|
||
#### Script to convert BibTeX from the ORCID to HTML | ||
|
||
* Script to convert BibTeX from the ORCID to HTML: [orcid_bibtex_to_html.py](examples/orcid_bibtex_to_html.py) | ||
* Additional information | ||
+ iterates through the list or ID's, extracts ORCID, creates bat file to compile bibtex into HTMLs with help of JabRef | ||
- List should be in the python dict format, here is the example (I created file 'orcid-list.json') | ||
``` | ||
[ | ||
{ 'John Wilbanks' : '0000-0002-4510-0385'}, | ||
] | ||
``` | ||
+ **NOTE**: To make in run on Mac OS, it's better if you will copy JabRef into the 'generated' folder directly | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#extentions | ||
*.pyc | ||
*.txt | ||
*.json | ||
*.log | ||
|
||
# folders | ||
*generated/ | ||
|
||
# files | ||
vlbalist.py | ||
orcid-log.log | ||
output.txt | ||
README.html | ||
orcid-list.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import codecs | ||
import logging | ||
import os | ||
|
||
import orcidpyclient as orcid | ||
|
||
logging.getLogger(__name__).setLevel(logging.INFO) | ||
|
||
# retrieve a profile from his ORCID | ||
me = orcid.get("0000-0001-5661-4587") | ||
|
||
TARGET_FODLER = "generated" | ||
|
||
|
||
def print_keyword(obj): | ||
"""Printing author keywords""" | ||
|
||
print("[i] printing author keywords") | ||
for key_word in obj.keywords: | ||
print(key_word) | ||
|
||
|
||
def print_publications(obj): | ||
"""Printing author publications""" | ||
|
||
print("[i] printing author publications") | ||
for value in obj.publications: | ||
print(value) | ||
|
||
|
||
def save_bibtex(bibtex, file_name="orcid-bibtex-output.bib", encoding="utf-8"): | ||
""" | ||
(dict, str, str) -> None | ||
Saves BibTeX into the file, grouping them by year. | ||
""" | ||
|
||
file_name = "{0}/{1}".format(TARGET_FODLER, file_name) | ||
|
||
_file = codecs.open(file_name, "w", encoding) | ||
|
||
for key in bibtex: | ||
_file.write("%%%%%%%%%%%%%%%% \n%% %s \n%%%%%%%%%%%%%%%%\n\n" % key) | ||
bibtex_group = "" | ||
for value in bibtex[key]: | ||
bibtex_group += value + "\n\n" | ||
_file.write(bibtex_group) | ||
|
||
_file.close() | ||
|
||
print("[i] bibtex was created, check following file: {0}".format(file_name)) | ||
|
||
|
||
def save_nocite(bibtex, file_name="orcid-nocite-output.tex", encoding="utf-8"): | ||
""" | ||
(dict, str, str) -> None | ||
Saves BibTeX to the file with "nocite" command, grouped by year. | ||
""" | ||
|
||
def extract_bibtex_id(s): | ||
start = s.find("{") + 1 | ||
end = s.find(",", start) | ||
return s[start:end] | ||
|
||
file_name = "{0}/{1}".format(TARGET_FODLER, file_name) | ||
|
||
_file = codecs.open(file_name, "w", encoding) | ||
|
||
for key in bibtex: | ||
_file.write("%%%%%%%%%%%%%%%% \n%% %s \n%%%%%%%%%%%%%%%%\n\n" % key) | ||
nocite_group = "" | ||
for value in bibtex[key]: | ||
nocite_group += "\\nocite{" + extract_bibtex_id(value) + "}" + "\n" | ||
_file.write(nocite_group) | ||
|
||
_file.close() | ||
|
||
print("[i] tex with \\nocite was created, check following file: {0}".format(file_name)) | ||
|
||
|
||
def extract_bibtex(obj): | ||
""" | ||
(Class) -> dict() | ||
Takes an object with all publications from ORCID as the input and forms dict out of it. | ||
""" | ||
|
||
bibtex = {} | ||
for value in obj.publications: | ||
if value.citation_type == "BIBTEX": | ||
if value.publicationyear not in bibtex: | ||
bibtex[value.publicationyear] = list() | ||
bibtex[value.publicationyear].append(value.citation_value) | ||
else: | ||
bibtex[value.publicationyear].append(value.citation_value) | ||
else: | ||
print("[i] this publications is having no BIBTEX {0}".format(value)) | ||
|
||
return bibtex | ||
|
||
|
||
def orcid_bibtex(obj): | ||
""" | ||
(Class) -> None | ||
Extracts BibTeX from ORCID, saves it into the file | ||
""" | ||
|
||
if not os.path.exists(TARGET_FODLER): | ||
os.makedirs(TARGET_FODLER) | ||
|
||
# extracting bibtex | ||
orcid_bibtex = extract_bibtex(me) | ||
|
||
# saving bibtex to file | ||
save_bibtex(orcid_bibtex) | ||
|
||
# citing extracted bibtex | ||
save_nocite(orcid_bibtex) | ||
|
||
|
||
# print_keyword(me) | ||
# print_publications(me) | ||
orcid_bibtex(me) |
Oops, something went wrong.