diff --git a/bmc.py b/bmc.py index 1935632..970f063 100755 --- a/bmc.py +++ b/bmc.py @@ -50,11 +50,11 @@ def checkBibtex(filename, bibtex_string): while check.lower() == 'n': with tempfile.NamedTemporaryFile(suffix=".tmp") as tmpfile: - tmpfile.write(bibtex_string) + tmpfile.write(bibtex_string.encode('utf-8')) tmpfile.flush() subprocess.call([EDITOR, tmpfile.name]) tmpfile.seek(0) - bibtex = BibTexParser(tmpfile.read()+"\n") + bibtex = BibTexParser(tmpfile.read().decode('utf-8')+"\n") bibtex = bibtex.get_entry_dict() try: @@ -176,7 +176,7 @@ def addFile(src, filetype, manual, autoconfirm, tag): bibtex = BibTexParser(bibtex) bibtex = bibtex.get_entry_dict() if len(bibtex) > 0: - bibtex_name = list(bibtex.keys()[0] + bibtex_name = list(bibtex.keys())[0] bibtex = bibtex[bibtex_name] bibtex_string = tools.parsed2Bibtex(bibtex) else: @@ -214,7 +214,7 @@ def addFile(src, filetype, manual, autoconfirm, tag): # Remove first page of IOP papers try: if 'IOP' in bibtex['publisher'] and bibtex['type'] == 'article': - tearpages.main(new_name) + tearpages.tearpage(new_name) except (KeyError, shutil.Error, IOError): pass @@ -288,7 +288,7 @@ def downloadFile(url, filetype, manual, autoconfirm, tag): print('Download finished') tmp = tempfile.NamedTemporaryFile(suffix='.'+contenttype) - with open(tmp.name, 'w+') as fh: + with open(tmp.name, 'w+', encoding='utf-8') as fh: fh.write(dl) new_name = addFile(tmp.name, filetype, manual, autoconfirm, tag) if new_name is False: diff --git a/libbmc/fetcher.py b/libbmc/fetcher.py index 2045e40..863fc4a 100644 --- a/libbmc/fetcher.py +++ b/libbmc/fetcher.py @@ -75,7 +75,7 @@ def download(url): try: size = int(dict(r.info())['Content-Length'].strip()) except KeyError: - size = 1 + size = 0 dl = b"" dl_size = 0 while True: @@ -83,10 +83,11 @@ def download(url): if buf: dl += buf dl_size += len(buf) - done = int(50 * dl_size / size) - sys.stdout.write("\r[%s%s]" % ('='*done, ' '*(50-done))) - sys.stdout.write(" "+str(int(float(done)/52*100))+"%") - sys.stdout.flush() + if size != 0: + done = int(50 * dl_size / size) + sys.stdout.write("\r[%s%s]" % ('='*done, ' '*(50-done))) + sys.stdout.write(" "+str(int(float(done)/52*100))+"%") + sys.stdout.flush() else: break contenttype = False diff --git a/libbmc/tools.py b/libbmc/tools.py index 68cd012..539d726 100644 --- a/libbmc/tools.py +++ b/libbmc/tools.py @@ -16,6 +16,11 @@ import re import sys from termios import tcflush, TCIOFLUSH +try: + input = raw_input +except NameError: + pass + _slugify_strip_re = re.compile(r'[^\w\s-]') _slugify_hyphenate_re = re.compile(r'[\s]+') @@ -63,11 +68,7 @@ def replaceAll(text, dic): def rawInput(string): """Flush stdin and then prompt the user for something""" tcflush(sys.stdin, TCIOFLUSH) - try: - input = raw_input - except NameError: - pass - return input(string).decode('utf-8') + return input(string) def warning(*objs):