Skip to content

Commit

Permalink
Checks state of scihub
Browse files Browse the repository at this point in the history
  • Loading branch information
devmessias committed Aug 22, 2017
1 parent b580bf5 commit 69c9568
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
1 change: 1 addition & 0 deletions requeriments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ future
requests
lxml
title2bib
Pillow
2 changes: 2 additions & 0 deletions scihub2pdf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

__version__ = "0.1.0"
20 changes: 17 additions & 3 deletions scihub2pdf/bin/scihub2pdf
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,46 @@ def main():
action="store_true",
help="download from title"
)
parser.add_argument(
"--uselibgen",
dest="uselibgen",
action="store_true",
help="Use libgen.io instead sci-hub. Sci-hub has annoying captcha but is stable. Libgen has no captcha but is unstable."
)
parser.add_argument(
"--location", "-l",
help="folder, ex: -l 'folder/'"
)

parser.set_defaults(title=False)
parser.set_defaults(uselibgen=False)
parser.set_defaults(location="")

args = parser.parse_known_args()
title_search = args[0].title
use_libgen = args[0].uselibgen
inline_search = len(args[1]) > 0
location = args[0].location

if use_libgen:
print("\n\t Using Libgen.\n")
else:
print("\n\t Using Sci-Hub.\n")

if inline_search:
value = " ".join(args[1])
if title_search:
download_from_title(value, location)
download_from_title(value, location, use_libgen)
else:
download_from_doi(value, location)
download_from_doi(value, location, use_libgen)
else:
bibtex = bibtexparser.loads(args[0].input.read())
bibs = bibtex.entries
if len(bibs) == 0:
print("Input File is empty or corrupted.")
sys.exit(1)

download_pdf_from_bibs(bibs, location)
download_pdf_from_bibs(bibs, location, use_libgen)


if __name__ == "__main__":
Expand Down
34 changes: 26 additions & 8 deletions scihub2pdf/scihub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,40 @@
import bibtexparser
from builtins import input
from PIL import Image
from . import __version__
try:
from StringIO import StringIO
except ImportError:
from io import StringIO

headers = {
# "Connection": "close",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
}
url_captcha_scihub = "http://moscow.sci-hub.cc"
url_libgen = "http://libgen.io/scimag/ads.php"
url_scihub = "http://sci-hub.cc/"
xpath_libgen_a = "/html/body/table/tr/td[3]/a"
xpath_scihub_captcha = "//*[@id='captcha']"
xpath_scihub_iframe = "//iframe/@src"
xpath_scihub_pdf = "//*[@id='pdf']"
print("\n\t Checking state of scihub...")
url_state ="https://raw.githubusercontent.com/bibcure/scihub_state/master/state.txt"
try:
r = requests.get(url_state)
state_scihub = [i.split(">>")[1] for i in r.iter_lines()]
url_captcha_scihub = state_scihub[0]
url_libgen = state_scihub[1]
url_scihub = state_scihub[2]
xpath_libgen_a = state_scihub[3]
xpath_scihub_captcha = state_scihub[4]
xpath_scihub_iframe = state_scihub[5]
xpath_scihub_pdf = state_scihub[6]
has_update = state_scihub[7] != __version__
if has_update:
print("\n\t\tWill be better if you upgrade scihub2pdf.")
print("\t\tFor that, just do:\n")
print("\t\t\t sudo pip install scihub2pdf --upgrade\n")
except:
url_captcha_scihub = "http://moscow.sci-hub.cc"
url_libgen = "http://libgen.io/scimag/ads.php"
url_scihub = "http://sci-hub.cc/"
xpath_libgen_a = "/html/body/table/tr/td[3]/a"
xpath_scihub_captcha = "//*[@id='captcha']"
xpath_scihub_iframe = "//iframe/@src"
xpath_scihub_pdf = "//*[@id='pdf']"


def norm_url(url):
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@

setup(
name="scihub2pdf",
version="0.0.3",
version="0.1.0",
packages = find_packages(exclude=["build",]),
# packages = find_packages(),
scripts=["scihub2pdf/bin/scihub2pdf"],
long_description = README_TEXT,
install_requires = ["bibtexparser",
"title2bib",
"future",
"Pillow",
"requests",
"lxml"],
include_package_data=True,
license="GPLv3",
description="Downloads pdfs via a DOI number, article title or a bibtex file, sci-hub",
author="Bruno Messias",
author_email="[email protected]",
download_url="https://github.com/bibcure/scihub2pdf/archive/0.0.3.tar.gz",
download_url="https://github.com/bibcure/scihub2pdf/archive/0.1.0.tar.gz",
keywords=["bibtex", "sci-hub", "libgen", "doi", "science","scientific-journals"],

classifiers=[
Expand Down

0 comments on commit 69c9568

Please sign in to comment.