| author | rcallahan <rcallahan@eurekagenomics.com> | 2013-07-06 22:02:38 (GMT) |
|---|---|---|
| committer | rcallahan <rcallahan@eurekagenomics.com> | 2013-07-06 22:02:38 (GMT) |
| commit | daffd43c08622b655ea5e02b8baa627fa04e9e1b (patch) (side-by-side diff) | |
| tree | a811b7352746a3bd7c39207b3af3870c6ed55b85 | |
| parent | aab9aa3fcf2d06a6f4723544c078e567df07a3fd (diff) | |
| download | paperbot-daffd43c.zip paperbot-daffd43c.tar.gz | |
Update scihub.py
kwargs don't work the way i thought
| -rw-r--r-- | modules/scihub.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/modules/scihub.py b/modules/scihub.py index f29bba4..d4424e2 100644 --- a/modules/scihub.py +++ b/modules/scihub.py @@ -12,14 +12,17 @@ import urllib import base64 import os -scihub_cookie = os.environ.get("SCIHUB_PASSWORD", None) -if scihub_cookie: - defcookie = {scihub_cookie: ""} -else - raise Exception("need SCIHUB_PASSWORD set") -def libgen(url, doi, cookies = defcookie, **kwargs): +def cookie(fn): + scihub_cookie = os.environ.get("SCIHUB_PASSWORD", None) + if scihub_cookie: + return lambda: fn(cookies = {scihub_cookie: ""}) + else: + raise Exception("need SCIHUB_PASSWORD set") + +@cookie +def libgen(url, doi, **kwargs): auth_ = requests.auth.HTTPBasicAuth("genesis", "upload") re = requests.get(url, **kwargs) re = requests.post("http://libgen.org/scimag/librarian/form.php", auth = auth_, @@ -29,7 +32,8 @@ def libgen(url, doi, cookies = defcookie, **kwargs): re = requests.get("http://libgen.org/scimag/librarian/register.php", data = formp, auth = auth_) return "http://libgen.org/scimag5/" + doi -def scihubber(url, cookies = defcookie, **kwargs): +@cookie +def scihubber(url, **kwargs): """ Takes user url and traverses sci-hub proxy system until pdf is found. When successful, returns either sci-hub pdfcache or libgen pdf url |
