diff --git a/README.md b/README.md index 2cc9c9b..78afd96 100644 --- a/README.md +++ b/README.md @@ -116,10 +116,13 @@ A list of ideas and TODO. Don't hesitate to give feedback on the ones you really 80. Search engine 100. UTF-8 ? 200. Webserver interface ? GUI ? (not likely for now…) +Keep multiple versions of papers +Export of bibtex +Tree à la docear ? ## Issues ? -* Multiplication of {{}} +* Multiplication of {{}} => solved in bibtexparser ## Thanks diff --git a/backend.py b/backend.py index d6c3bcf..0bd0f55 100644 --- a/backend.py +++ b/backend.py @@ -8,6 +8,7 @@ import fetcher import params from bibtexparser.bparser import BibTexParser from bibtexparser.customization import homogeneize_latex_encoding +from codecs import open def getNewName(src, bibtex, tag=''): @@ -69,7 +70,7 @@ def bibtexAppend(data): data is a dict for one entry in bibtex, as the one from bibtexparser output """ try: - with open(params.folder+'index.bib', 'a') as fh: + with open(params.folder+'index.bib', 'a', encoding='utf-8') as fh: fh.write(parsed2Bibtex(data)+"\n") except: tools.warning("Unable to open index file.") @@ -80,7 +81,7 @@ def bibtexEdit(ident, modifs): """Update ident key in bibtex file, modifications are in modifs dict""" try: - with open(params.folder+'index.bib', 'r') as fh: + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: bibtex = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) bibtex = bibtex.get_entry_dict() @@ -102,7 +103,7 @@ def bibtexRewrite(data): for entry in data.keys(): bibtex += parsed2Bibtex(data[entry])+"\n" try: - with open(params.folder+'index.bib', 'w') as fh: + with open(params.folder+'index.bib', 'w', encoding='utf-8') as fh: fh.write(bibtex) except: tools.warning("Unable to open index file.") @@ -112,7 +113,7 @@ def bibtexRewrite(data): def deleteId(ident): """Delete a file based on its id in the bibtex file""" try: - with open(params.folder+'index.bib', 'r') as fh: + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: bibtex = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) bibtex = bibtex.get_entry_dict() @@ -148,7 +149,7 @@ def deleteId(ident): def deleteFile(filename): """Delete a file based on its filename""" try: - with open(params.folder+'index.bib', 'r') as fh: + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: bibtex = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) bibtex = bibtex.get_entry_dict() @@ -192,7 +193,7 @@ def diffFilesIndex(): """ files = tools.listDir(params.folder) try: - with open(params.folder+'index.bib', 'r') as fh: + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: index = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) index_diff = index.get_entry_dict() @@ -219,7 +220,7 @@ def getBibtex(entry, file_id='both'): file_id is file or id or both to search for a file / id / both """ try: - with open(params.folder+'index.bib', 'r') as fh: + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: bibtex = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) bibtex = bibtex.get_entry_dict() @@ -244,7 +245,7 @@ def getBibtex(entry, file_id='both'): def getEntries(): """Returns the list of all entries in the bibtex index""" try: - with open(params.folder+'index.bib', 'r') as fh: + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: bibtex = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) bibtex = bibtex.get_entry_dict() diff --git a/fetcher.py b/fetcher.py index 077ee1b..fee038f 100644 --- a/fetcher.py +++ b/fetcher.py @@ -35,7 +35,7 @@ def download(url): return r.content, contenttype except requests.exceptions.RequestException: - tools.warning("Unable to get "+url+" using roxy "+proxy+". It " + + tools.warning("Unable to get "+url+" using proxy "+proxy+". It " + "may not be available.") continue return False diff --git a/main.py b/main.py index 236a7e8..558423d 100755 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ import tools import params from bibtexparser.bparser import BibTexParser from bibtexparser.customization import homogeneize_latex_encoding +from codecs import open EDITOR = os.environ.get('EDITOR') if os.environ.get('EDITOR') else 'vim' @@ -159,8 +160,11 @@ def addFile(src, filetype, manual): sys.exit("Unable to move file to library dir " + params.folder+".") # Remove first page of IOP papers - if 'IOP' in bibtex['publisher'] and bibtex['type'] == 'article': - tearpages.tearpage(new_name) + try: + if 'IOP' in bibtex['publisher'] and bibtex['type'] == 'article': + tearpages.tearpage(new_name) + except: + pass backend.bibtexAppend(bibtex) return new_name @@ -210,8 +214,8 @@ def editEntry(entry, file_id='both'): os.path.dirname(bibtex['file'])) try: - with open(params.folder+'index.bib', 'r') as fh: - index = BibTexParser(fh.read().encode('utf-8'), + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: + index = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) index = index.get_entry_dict() except: @@ -224,13 +228,15 @@ def editEntry(entry, file_id='both'): def downloadFile(url, filetype, manual): + print('Downloading '+url) dl, contenttype = fetcher.download(url) if dl is not False: + print('Download finished') tmp = tempfile.NamedTemporaryFile(suffix='.'+contenttype) with open(tmp.name, 'w+') as fh: - fh.write(dl.encode('utf-8')) + fh.write(dl) new_name = addFile(tmp.name, filetype, manual) tmp.close() return new_name @@ -241,8 +247,8 @@ def downloadFile(url, filetype, manual): def openFile(ident): try: - with open(params.folder+'index.bib', 'r') as fh: - bibtex = BibTexParser(fh.read().encode('utf-8'), + with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: + bibtex = BibTexParser(fh.read(), customization=homogeneize_latex_encoding) bibtex = bibtex.get_entry_dict() except: