Started the main code

This commit is contained in:
Phyks 2014-04-24 00:18:49 +02:00
parent 052f39b6f2
commit 93d1fefa26
3 changed files with 82 additions and 2 deletions

View File

@ -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/)

View File

@ -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]

78
main.py Executable file
View File

@ -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')