From 93d1fefa26962da43839794ce483616a3f1ec9c1 Mon Sep 17 00:00:00 2001 From: Phyks Date: Thu, 24 Apr 2014 00:18:49 +0200 Subject: [PATCH] Started the main code --- README.md | 4 +++ papers.py => fetcher.py | 2 -- main.py | 78 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) rename papers.py => fetcher.py (99%) create mode 100755 main.py diff --git a/README.md b/README.md index aa9e4b6..8be5d27 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,7 @@ Paperbot can try multiple instances of translation-server (configured to use dif ## License TODO + +## Inspiration + +* [Bibsoup](http://openbiblio.net/2012/02/09/bibsoup-beta-released/) diff --git a/papers.py b/fetcher.py similarity index 99% rename from papers.py rename to fetcher.py index 6fc5b46..b5ae66e 100755 --- a/papers.py +++ b/fetcher.py @@ -451,8 +451,6 @@ if __name__ == '__main__': l = sys.stdin.readline() if not l: break - if l.startswith("help") or l.startswith("HELP"): - print params.help reqs.append(time()) if len(reqs) > params.thresh: delay = time() - reqs[len(reqs) - params.thresh + 1] diff --git a/main.py b/main.py new file mode 100755 index 0000000..18761c2 --- /dev/null +++ b/main.py @@ -0,0 +1,78 @@ +#!/usr/bin/python2 -u +# coding=utf8 +""" +Main app +""" + +import sys +import shutil +import requests +from bibtexparser.bparser import BibTexParser +import params + + +def bibtex_append(data): + """ + Append data to the main bibtex file + """ + bibtex = '' + for field, value in data: + bibtex += "\n" + field + ": " + value + "," + + # TODO : Write + + +def add_file(src, doi): + """ + Add a file to the library + """ + new_name = folder+"/"+doi + + try: + shutil.copy2(src, new_name) + except IOError: + sys.exit("Unable to move file to library dir " + folder) + + data = {"file": new_name} + + bibtex_append(data) + + print("File " + src + " successfully imported.") + + +def doi2bib(doi): + """ + Return a bibTeX string of metadata for a given DOI. + From : https://gist.github.com/jrsmith3/5513926 + """ + + url = "http://dx.doi.org/" + doi + + headers = {"accept": "application/x-bibtex"} + r = requests.get(url, headers = headers) + + return r.text + + +if __name__ == '__main__': + if len(sys.argv) < 2: + sys.exit("Usage : TODO") + + + if sys.argv[1] == 'download': + raise Exception('TODO') + + if sys.argv[1] == 'import': + if len(sys.argv) < 3: + sys.exit("Usage : " + sys.argv[0] + " import FILE") + + doi = raw_input('DOI ? ') + # TODO : Get DOI automagically + add_file(sys.argv[2], doi) + sys.exit() + + elif sys.argv[1] == 'list': + raise Exception('TODO') + + elif sys.argv[1] == 'search': + raise Exception('TODO')