Skip to content

Commit

Permalink
bug fix and update
Browse files Browse the repository at this point in the history
  • Loading branch information
Koushikphy committed Nov 24, 2022
1 parent 7661dbe commit 2f8847d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
30 changes: 15 additions & 15 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
[![Alt text](https://img.shields.io/pypi/status/kbib.svg)](https://pypi.org/project/kbib/)
[![Alt text](https://github.com/koushikphy/kbib/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Koushikphy/kbib/releases/latest)



### ⚡ Features
1. Get bibtex entry from DOI.
3. Get bibtex entry from article pdf.
2. Get full list of references of an article as bibtex entries.


### 🐱‍🏍 Installation
Download and install the latest package from the [release section](https://github.com/Koushikphy/kbib/releases/latest) or directly by pip
```bash
pip install kbib
```
For paring bibtex information from PDF files, optional dependencies need to be installed
For parsing bibtex information from PDF files, optional dependencies need to be installed

```bash
pip install kbib['pdf']
```



### ⚡ Features
1. Get bibtex entry from DOI.
3. Get bibtex entry from article pdf.
2. Get full list of references of an article as bibtex entries.



### 🚀 Usage
Use the command line tool `kbib` as
```bash
Expand All @@ -39,23 +39,23 @@ kbib [-h] [-bib DOI] [-ref DOI] [-pdf [PDF [PDF ...]]] [-o DOI]
| `-pdf` | PDF file name(s) to get DOI |
| `-o` | Output bib file |
1. Get bibtex from a DOI
* Get bibtex from a DOI
```bash
kbib -bib https://doi.org/10xxxxxx
```
1. Get bibtex from a DOI and store in a file 'ref.bib'
* Get bibtex from a DOI and store in a file 'ref.bib'
```bash
kbib -bib https://doi.org/10xxxxxx -o ref.bib
```
1. Get the full reference list of an article as bibtex entries and save as ref.bib
* Get the full reference list of an article as bibtex entries and save as ref.bib
```bash
kbib -ref https://doi.org/10xxxxxx -o ref.bib
```
1. Get bibtex from a PDF named article.pdf
* Get bibtex from a PDF named article.pdf
```bash
kbib -pdf article.pdf
```
1. Get bibtex from all pdf in the current folder
* Get bibtex from all pdf in the current folder
```bash
kbib -pdf *.pdf
```
Expand All @@ -68,4 +68,4 @@ Currently it parses DOI information from [Crossref API](https://github.com/Cross
#### ⚒ Work-in-Progress:
1. Concurrent API calls for faster parsing of bibtex information.
2. Set bibtex entry keys in a predefined format.
3. Ise abbreviated journal names.
3. Use abbreviated journal names.
44 changes: 30 additions & 14 deletions kbib/parseRefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import bibtexparser
import pkg_resources
import requests_cache
from rich.progress import track
from rich.progress import *
from datetime import timedelta
# import urllib,json

Expand All @@ -13,6 +13,16 @@
version = '0.1.0'
version= pkg_resources.require('kbib')[0].version

progress = Progress(
TextColumn("[progress.description]{task.description}"),
SpinnerColumn(),
TimeElapsedColumn(),
BarColumn(),
MofNCompleteColumn(),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
" ETA:",
TimeRemainingColumn(),
)


session = requests_cache.CachedSession('doi_cache',
Expand All @@ -28,7 +38,7 @@ def get_bib(doi):
url = "{}works/{}/transform/application/x-bibtex".format(BARE_URL, doi)
r = session.get(url)
# r =requests.get(doi, headers={'Accept':'application/x-bibtex'})
found = r.status_code != 200
found = r.status_code == 200
bib = str(r.content, "utf-8")
return found, bib

Expand All @@ -51,11 +61,12 @@ def getFullRefList(doi):
print("DOIs not found for {} references.".format(refNotFound))
fullRef = []
# for ref in tqdm(refDOIs,desc='Parsing bibtex entries from reference list'):
for ref in track(refDOIs,description='[green bold]Parsing bibtex entries from reference list...'):

f, refVal = get_bib(ref['DOI'])
if f:
fullRef.append(refVal)
with progress:
for ref in progress.track(refDOIs,description='[green bold]Parsing bibtex entries from reference list...'):

f, refVal = get_bib(ref['DOI'])
if f:
fullRef.append(refVal)
return '\n\n\n'.join(fullRef)
else:
raise Exception("Unable to parse reference list.")
Expand Down Expand Up @@ -146,6 +157,7 @@ def main():

if args.bib:
f,bib = get_bib(args.bib)
# print(f,bib)
if f:
writeBib(bib,args.o)
else:
Expand All @@ -166,18 +178,22 @@ def main():
# print(args.pdf)
def getbibfrompdf(file):
doi = pdf2doi.pdf2doi(file)['identifier']
f,bib = get_bib(doi)
return f,bib
return get_bib(doi)

pdfs = args.pdf
if len(pdfs)==1:
writeBib(getbibfrompdf(pdfs[0]),args.o)
f, bib = getbibfrompdf(pdfs[0])
if f:
writeBib(bib,args.o)
else:
print("Unable to parse bibtex information.")
else:
fullRef = []
for pdf in track(pdfs,description='Parsing bibtex entries from reference list'):
f,bib = getbibfrompdf(pdf)
if f:
fullRef.append(bib)
with progress:
for pdf in progress.track(pdfs,description='[green bold]Parsing bibtex for files...'):
f,bib = getbibfrompdf(pdf)
if f:
fullRef.append(bib)
writeBib(removeDupEntries('\n\n\n'.join(fullRef)),args.o)

except ImportError:
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
txt = f.read()

setup(name='kbib',
version='0.1.2',
version='0.1.3',
description='A tool to get bibtex entries from DOIs or PDFs',
long_description=txt,
long_description_content_type='text/markdown',
Expand All @@ -13,15 +13,16 @@
license="MIT",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console', 'Intended Audience :: Science/Research',
'Environment :: Console',
'Intended Audience :: Science/Research',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: 3.6',
'Topic :: System :: Shells'
],
keywords='File Operations',
keywords='bibtex references doi crossref',
project_urls={'Source Code': 'https://github.com/Koushikphy/kbib'},
zip_safe=True,
python_requires='>=3.6',
Expand Down

0 comments on commit 2f8847d

Please sign in to comment.