From c880fe27a85d7206da14f7c81a8939becefb934b Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Wed, 23 Dec 2015 23:46:37 +0100 Subject: [PATCH] Move reference fetching code into a sub-library --- .gitmodules | 2 +- README.md | 10 +++++----- main.py => fetch_references.py | 4 ++-- reference_fetcher/__init__.py | 0 arxiv.py => reference_fetcher/arxiv.py | 3 ++- bbl.py => reference_fetcher/bbl.py | 6 +++--- doi.py => reference_fetcher/doi.py | 4 ++-- opendetex => reference_fetcher/opendetex | 0 regex.py => reference_fetcher/regex.py | 0 tools.py => reference_fetcher/tools.py | 0 10 files changed, 15 insertions(+), 14 deletions(-) rename main.py => fetch_references.py (82%) create mode 100644 reference_fetcher/__init__.py rename arxiv.py => reference_fetcher/arxiv.py (98%) rename bbl.py => reference_fetcher/bbl.py (98%) rename doi.py => reference_fetcher/doi.py (98%) rename opendetex => reference_fetcher/opendetex (100%) rename regex.py => reference_fetcher/regex.py (100%) rename tools.py => reference_fetcher/tools.py (100%) diff --git a/.gitmodules b/.gitmodules index cee79a4..257b6a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "opendetex"] - path = opendetex + path = reference_fetcher/opendetex url = https://github.com/Phyks/opendetex diff --git a/README.md b/README.md index 217bd6d..54f14d4 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,19 @@ For building `opendetex` (which is a necessary dependency), you will need * Clone this repository: `git clone https://github.com/Phyks/arxiv_metadata`. * Init submodules (`opendetex`): `git submodule init; git submodule update`. -* Build `opendetex`: `cd opendetex; make`. +* Build `opendetex`: `cd reference_fetcher/opendetex; make`. * You are ready to go. ## Usage -* `./main.py some_file.bbl` to get a list of DOIs associated to each `\bibitem`. -* `./main.py arxiv_eprint_id` to get a list of DOIs associated to each reference from the provided arXiv eprint. +* `./fetch_references.py some_file.bbl` to get a list of DOIs associated to each `\bibitem`. +* `./fetch_references.py arxiv_eprint_id` to get a list of DOIs associated to each reference from the provided arXiv eprint. ## Example ``` -$ ./main.py 1401.2910 +$ ./fetch_references.py 1401.2910 ``` ``` @@ -67,7 +67,7 @@ $ ./main.py 1401.2910 ``` -$ ./main.py /tmp/test.bbl +$ ./fetch_reference.py /tmp/test.bbl ``` ``` diff --git a/main.py b/fetch_references.py similarity index 82% rename from main.py rename to fetch_references.py index dc5721d..7f8e11d 100755 --- a/main.py +++ b/fetch_references.py @@ -3,8 +3,8 @@ import os import sys # Local import -import arxiv -import bbl +from ..reference_fetcher import arxiv +from ..reference_fetcher import bbl if __name__ == "__main__": diff --git a/reference_fetcher/__init__.py b/reference_fetcher/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/arxiv.py b/reference_fetcher/arxiv.py similarity index 98% rename from arxiv.py rename to reference_fetcher/arxiv.py index ab5b563..f323d20 100644 --- a/arxiv.py +++ b/reference_fetcher/arxiv.py @@ -1,11 +1,12 @@ """ This file contains all the arXiv-specific functions. """ -import bbl import io import requests import tarfile +from . import bbl + def sources_from_arxiv(eprint): """ diff --git a/bbl.py b/reference_fetcher/bbl.py similarity index 98% rename from bbl.py rename to reference_fetcher/bbl.py index 63d6e95..fa81022 100644 --- a/bbl.py +++ b/reference_fetcher/bbl.py @@ -1,14 +1,14 @@ """ This files contains all the functions to deal with bbl files. """ -import doi import math import os import requests import subprocess -import regex -import tools +from . import doi +from . import regex +from . import tools def clean_bibitem(bibitem): diff --git a/doi.py b/reference_fetcher/doi.py similarity index 98% rename from doi.py rename to reference_fetcher/doi.py index 46a66ba..415118e 100644 --- a/doi.py +++ b/reference_fetcher/doi.py @@ -3,8 +3,8 @@ This file contains all the DOI-related functions. """ import requests -import regex -import tools +from . import regex +from . import tools def extract_doi_links(urls): diff --git a/opendetex b/reference_fetcher/opendetex similarity index 100% rename from opendetex rename to reference_fetcher/opendetex diff --git a/regex.py b/reference_fetcher/regex.py similarity index 100% rename from regex.py rename to reference_fetcher/regex.py diff --git a/tools.py b/reference_fetcher/tools.py similarity index 100% rename from tools.py rename to reference_fetcher/tools.py