Use $EDITOR
* Use $EDITOR to edit the bibtex entries, as `git commit` or `crontab -e` does. * Bugfixes that prevented the import of an article without associated bibtex entry or without doi.
This commit is contained in:
parent
49df58bf70
commit
872d93c6aa
@ -106,6 +106,7 @@ Here are some sources of inspirations for this project :
|
|||||||
A list of ideas and TODO. Don't hesitate to give feedback on the ones you really want or to propose your owns.
|
A list of ideas and TODO. Don't hesitate to give feedback on the ones you really want or to propose your owns.
|
||||||
|
|
||||||
* Open
|
* Open
|
||||||
|
* Parameter to disable remote search
|
||||||
* Rebuild
|
* Rebuild
|
||||||
* Webserver interface
|
* Webserver interface
|
||||||
* Various re.compile ?
|
* Various re.compile ?
|
||||||
|
43
main.py
43
main.py
@ -22,6 +22,8 @@ from bibtexparser.bparser import BibTexParser
|
|||||||
from termios import tcflush, TCIOFLUSH
|
from termios import tcflush, TCIOFLUSH
|
||||||
import params
|
import params
|
||||||
|
|
||||||
|
EDITOR = os.environ.get('EDITOR') if os.environ.get('EDITOR') else 'vim'
|
||||||
|
|
||||||
|
|
||||||
def rawInput(string):
|
def rawInput(string):
|
||||||
tcflush(sys.stdin, TCIOFLUSH)
|
tcflush(sys.stdin, TCIOFLUSH)
|
||||||
@ -167,11 +169,16 @@ def doi2Bib(doi):
|
|||||||
"""
|
"""
|
||||||
url = "http://dx.doi.org/" + doi
|
url = "http://dx.doi.org/" + doi
|
||||||
headers = {"accept": "application/x-bibtex"}
|
headers = {"accept": "application/x-bibtex"}
|
||||||
|
try:
|
||||||
r = requests.get(url, headers=headers)
|
r = requests.get(url, headers=headers)
|
||||||
|
|
||||||
if r.headers['content-type'] == 'application/x-bibtex':
|
if r.headers['content-type'] == 'application/x-bibtex':
|
||||||
return r.text
|
return r.text
|
||||||
else
|
else:
|
||||||
|
return ''
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
warning('Unable to contact remote server to get the bibtex entry ' +
|
||||||
|
'for doi '+doi)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
@ -207,29 +214,31 @@ def checkBibtex(filename, bibtex):
|
|||||||
bibtex = StringIO(bibtex)
|
bibtex = StringIO(bibtex)
|
||||||
bibtex = BibTexParser(bibtex)
|
bibtex = BibTexParser(bibtex)
|
||||||
bibtex = bibtex.get_entry_dict()
|
bibtex = bibtex.get_entry_dict()
|
||||||
|
if len(bibtex) > 0:
|
||||||
bibtex_name = bibtex.keys()[0]
|
bibtex_name = bibtex.keys()[0]
|
||||||
bibtex = bibtex[bibtex_name]
|
bibtex = bibtex[bibtex_name]
|
||||||
print(parsed2Bibtex(bibtex))
|
bibtex_string = parsed2Bibtex(bibtex)
|
||||||
|
else:
|
||||||
|
bibtex_string = ''
|
||||||
|
print(bibtex_string)
|
||||||
check = rawInput("Is it correct ? [Y/n] ")
|
check = rawInput("Is it correct ? [Y/n] ")
|
||||||
|
|
||||||
while check.lower() == 'n':
|
while check.lower() == 'n':
|
||||||
fields = [u'type', u'id'] + [i for i in sorted(bibtex)
|
with tempfile.NamedTemporaryFile(suffix=".tmp") as tmpfile:
|
||||||
if i not in ['id', 'type']]
|
tmpfile.write(bibtex_string)
|
||||||
|
tmpfile.flush()
|
||||||
for field in fields:
|
subprocess.call([EDITOR, tmpfile.name])
|
||||||
new_value = rawInput(field.capitalize()+" ? ["+bibtex[field]+"] ")
|
bibtex = BibTexParser(StringIO(tmpfile.read()+"\n"))
|
||||||
if new_value != '':
|
|
||||||
bibtex[field] = new_value
|
|
||||||
|
|
||||||
while True:
|
|
||||||
new_field = rawInput("Add a new field (leave empty to skip) ? ")
|
|
||||||
if new_field == '':
|
|
||||||
break
|
|
||||||
new_value = rawInput("Value for field "+new_field+" ? ")
|
|
||||||
bibtex[new_field] = new_value
|
|
||||||
|
|
||||||
|
bibtex = bibtex.get_entry_dict()
|
||||||
|
if len(bibtex) > 0:
|
||||||
|
bibtex_name = bibtex.keys()[0]
|
||||||
|
bibtex = bibtex[bibtex_name]
|
||||||
|
bibtex_string = parsed2Bibtex(bibtex)
|
||||||
|
else:
|
||||||
|
bibtex_string = ''
|
||||||
print("\nThe bibtex entry for "+filename+" is :")
|
print("\nThe bibtex entry for "+filename+" is :")
|
||||||
print(parsed2Bibtex(bibtex))
|
print(bibtex_string)
|
||||||
check = rawInput("Is it correct ? [Y/n] ")
|
check = rawInput("Is it correct ? [Y/n] ")
|
||||||
return bibtex
|
return bibtex
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user