diff options
author | U-ACORNSYS\pwang <pwang@pwang01.acornsys.com> | 2013-07-09 18:39:30 -0500 |
---|---|---|
committer | U-ACORNSYS\pwang <pwang@pwang01.acornsys.com> | 2013-07-09 18:39:30 -0500 |
commit | 3e4754e68b0efd19fb0bb959f027d865596c6eee (patch) | |
tree | d687250d0244abcf2fce20010e4fe4c5e899b1f9 | |
parent | 13a4599a81293c0deaaff0f6512663aaebf61f10 (diff) | |
parent | a62f60c8272926b1c3e7062b421c305ef0c1948f (diff) | |
download | paperbot-3e4754e6.tar.gz paperbot-3e4754e6.zip |
Merge branch 'master' of https://github.com/rcallahan/paperbot
-rw-r--r-- | modules/papers.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/modules/papers.py b/modules/papers.py index 09017ce..8117463 100644 --- a/modules/papers.py +++ b/modules/papers.py @@ -13,10 +13,16 @@ import urllib import pdfparanoia +logchannel = os.environ.get("LOGGING", None) + def download(phenny, input, verbose=True): """ Downloads a paper. """ + if logchannel: + _log = lambda x: phenny.msg("#%s" % logchannel, x) + else: + _log = lambda x: None # only accept requests in a channel if not input.sender.startswith('#'): # unless the user is an admin, of course @@ -46,6 +52,9 @@ def download(phenny, input, verbose=True): if len(line) < 5 or (not "http://" in line and not "https://" in line) or not line.startswith("http"): return for line in re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', line): + # fix an UnboundLocalError problem + shurl = None + line = filter_fix(line) # fix for login.jsp links to ieee xplore @@ -74,6 +83,7 @@ def download(phenny, input, verbose=True): title = item["title"] if item.has_key("DOI"): + _log("Translator DOI") lgre = requests.post("http://libgen.org/scimag/librarian/form.php", data={"doi":item["DOI"]}) tree = parse_html(lgre.content) if tree.xpath("//h1")[0].text != "No file selected": @@ -146,20 +156,26 @@ def download(phenny, input, verbose=True): phenny.say(url) continue elif verbose and explicit: + _log("Translation server PDF fail") shurl, doi = modules.scihub.scihubber(line) continue elif verbose and explicit: + _log("Translation server PDF fail") shurl, doi = modules.scihub.scihubber(line) phenny.say(download_url(line)) continue elif verbose and explicit: + _log("Translation server fail") shurl, doi = modules.scihub.scihubber(line) + _log("Scihubber -> (%s, %s)" % (shurl, doi)) if shurl: if "pdfcache" in shurl: if doi: phenny.say(modules.scihub.libgen(modules.scihub.scihub_dl(shurl), doi)) else: phenny.say(download_url(shurl, cookies=modules.scihub.shcookie)) else: phenny.say(shurl) - else: phenny.say(download_url(line)) + elif verbose and explicit: + _log("All approaches failed") + phenny.say(download_url(line)) return download.commands = ["fetch", "get", "download"] |