From 0c8e52844ab29bc25d8fe877412be8e5ad2b0fa6 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sat, 26 Apr 2014 18:40:32 +0200 Subject: [PATCH] Bugfix with tempfile --- README.md | 5 +++-- main.py | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 22a54ff..d84f327 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,10 @@ 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. -* if doi not found ? if no doi ? -* store url of articles +* if doi does not exist ? +* download djvu * test file field for bibtex +* No fail if proxy not accessible * Open * Confirmation for deletion * Rebuild diff --git a/main.py b/main.py index 4d5296e..25f410f 100755 --- a/main.py +++ b/main.py @@ -267,6 +267,7 @@ def addFile(src, filetype): else: # Idem bibtex = isbn2Bib(isbn).strip()+"\n" + bibtex = checkBibtex(src, bibtex) authors = re.split(' and ', bibtex['author']) @@ -296,7 +297,7 @@ def addFile(src, filetype): else: new_name = rename bibtex['file'] = new_name - + try: shutil.copy2(src, new_name) except IOError: @@ -352,13 +353,13 @@ def deleteFile(filename): def downloadFile(url, filetype): - pdf = fetcher.download_url(url) + dl = fetcher.download_url(url) - if pdf is not False: - tmp = tempfile.NamedTemporaryFile() + if dl is not False: + tmp = tempfile.NamedTemporaryFile(suffix='.pdf') with open(tmp.name, 'w+') as fh: - fh.write(pdf) + fh.write(dl) new_name = addFile(tmp.name, filetype) tmp.close() return new_name