Skip to content

Commit

Permalink
Add fetched bibtex to output
Browse files Browse the repository at this point in the history
  • Loading branch information
teddygroves committed Dec 2, 2024
1 parent 0502ba0 commit 7b7a98e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import streamlit as st

from refcheck.doi import get_dois
from refcheck.doi import get_dois, doi_to_url
from refcheck.bibtex import fetch_bibtex

DOI_REGEX = "10.\\d{4,9}/[-._;()/:a-z0-9A-Z]+"
FORMAT_TO_EXT = {
Expand All @@ -28,7 +29,10 @@
with open(path, "wb") as f:
f.write(uploaded_file.getvalue())
results = get_dois(path, format)
urls = [doi_to_url(doi) for doi in results]
bibtexes = [fetch_bibtex(url) for url in urls]

st.write("Here are the dois in your document. Please check if they are correct!")
for result in results:
st.write(f"[{result}](https://doi.org/{result})")
for doi, url, bibtex in zip(results, urls, bibtexes):
st.write(f"[**{doi}**]({url}):", bibtex)
st.write("")
7 changes: 7 additions & 0 deletions src/refcheck/bibtex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import requests


def fetch_bibtex(doi_url: str) -> str | None:
headers = {"accept": "application/x-bibtex"}
r = requests.get(doi_url, headers=headers)
return r.text if r is not None else None
4 changes: 4 additions & 0 deletions src/refcheck/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ def get_dois(path: Path, format) -> list[str]:
txt = pypandoc.convert_file(path, "plain", format=format)
matches = re.findall(DOI_REGEX, txt)
return [r if not r.endswith(".") else r[:-1] for r in matches]


def doi_to_url(doi: str) -> str:
return "http://dx.doi.org/" + doi

0 comments on commit 7b7a98e

Please sign in to comment.