Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main.py #16

Merged
merged 3 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pdf2bib/bibtex_makers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ def make_bibtex(metadata):
id = id.lower()
id = remove_latex_codes(id)
id = unidecode(id) #This makes sure that the id of the bibtex entry is only made out of ascii characters (i.e. no accents, tildes, etc.)
id = re.sub('-|,', '', id) #Make sure to remove any possible hyphen and comma
id = re.sub(
"-|,|:|'|\\n", "", id
) # Make sure to remove any possible hyphen, comma, colon, single quote, and newline.
if id == '':
id = 'NoValidID'

Expand Down Expand Up @@ -215,4 +217,4 @@ def remove_latex_codes(text):
#This regex looks for any substring that matches the pattern "{\string1{string2}}" where string1 can be anything,
#and it replaces the whole substring by string2
text_sanitized = re.sub(r"{\\[^\{]+{([\w]+)}}", r"\1",text)
return text_sanitized
return text_sanitized
18 changes: 15 additions & 3 deletions pdf2bib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def pdf2bib(target):
# Setup logging
logger = logging.getLogger("pdf2bib")

# Make sure the path is a string in case a Pathlib object is provided
target = str(target)

#Check if path is valid
if not(path.exists(target)):
logger.error(f"{target} is not a valid path to a file or a directory.")
Expand Down Expand Up @@ -135,9 +138,18 @@ def pdf2bib_singlefile(filename):

logger.info(f"pdf2doi found a valid identifier for this paper.")

if result['identifier_type'] in ['arxiv ID','arxiv DOI']:
if result["identifier_type"] == "arxiv ID":
logger.info(f"Parsing the info returned by export.arxiv.org...")
metadata = bibtex_makers.parse_bib_from_exportarxivorg(
result["validation_info"]
)
elif result["identifier_type"] == "arxiv DOI":
if "arxiv_doi" not in result["validation_info"]:
result["validation_info"]["arxiv_doi"] = result["identifier"]
logger.info(f"Parsing the info returned by export.arxiv.org...")
metadata = bibtex_makers.parse_bib_from_exportarxivorg(result['validation_info'])
metadata = bibtex_makers.parse_bib_from_exportarxivorg(
result["validation_info"]
)
elif result['identifier_type'] == 'DOI':
logger.info(f"Parsing the info returned by dx.doi.org...")
metadata = bibtex_makers.parse_bib_from_dxdoiorg(result['validation_info'], method=pdf2doi.config.get('method_dxdoiorg'))
Expand Down Expand Up @@ -303,4 +315,4 @@ def main():
return

if __name__ == '__main__':
main()
main()