From c2d280726fa53b21b0a7e4c099e3c8031a11d8f2 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 19 Feb 2017 13:18:07 -0800 Subject: [PATCH] automatic version upgrade --- anki_connect.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/anki_connect.py b/anki_connect.py index 5e950a7..c36b813 100644 --- a/anki_connect.py +++ b/anki_connect.py @@ -230,7 +230,7 @@ class AjaxServer: def handlerWrapper(self, req): if len(req.body) == 0: - body = 'AnkiConnect v.{}'.format(API_VERSION) + body = makeBytes('AnkiConnect v.{}'.format(API_VERSION)) else: try: params = json.loads(makeStr(req.body)) @@ -502,10 +502,12 @@ class AnkiConnect: if response == QMessageBox.Yes: data = download(URL_UPGRADE) if data is None: - QMessageBox.critical(self.anki.window, 'AnkiConnect', 'Failed to download latest version') + QMessageBox.critical(self.anki.window, 'AnkiConnect', 'Failed to download latest version.') else: - with open(__file__, 'w') as fp: - fp.write(data) + path = os.path.splitext(__file__)[0] + '.py' + with open(path, 'w') as fp: + fp.write(makeStr(data)) + QMessageBox.information(self.anki.window(), 'AnkiConnect', 'Upgraded to the latest version.') def api_version(self):