From 48094af97ea317247002ef98eee59da57be2e0b7 Mon Sep 17 00:00:00 2001 From: Jose Gabriel Date: Mon, 15 Feb 2021 00:15:18 -0500 Subject: [PATCH 1/2] ETECSA updated the API, fix error getting the user left time --- nauta.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nauta.py b/nauta.py index 166e9d5..bcf6e10 100755 --- a/nauta.py +++ b/nauta.py @@ -254,7 +254,13 @@ def fetch_expire_date(username, password): def fetch_usertime(username): session = requests.Session() - r = session.get("https://secure.etecsa.net:8443/EtecsaQueryServlet?op=getLeftTime&op1={}".format(username)) + try: + attribute_uuid = open(ATTR_UUID_FILE).read().strip() + except FileNotFoundError: + print("Connection seems to be down. To connect, use 'nauta up'") + return + r = session.get("https://secure.etecsa.net:8443/EtecsaQueryServlet?op=getLeftTime&username={}&ATTRIBUTE_UUID={}" + .format(username, attribute_uuid)) return r.text def time_left(username, fresh=False, cached=False): From 83741929fd7bf160f9d4e1a266fbc426bf7a208c Mon Sep 17 00:00:00 2001 From: Jose Gabriel Date: Wed, 12 May 2021 13:16:20 -0400 Subject: [PATCH 2/2] little fix catching an exception --- .gitignore | 1 + nauta.py | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/nauta.py b/nauta.py index bcf6e10..db0af05 100755 --- a/nauta.py +++ b/nauta.py @@ -265,20 +265,23 @@ def fetch_usertime(username): def time_left(username, fresh=False, cached=False): now = time.time() - with dbm.open(CARDS_DB, "c") as cards_db: - card_info = json.loads(cards_db[username].decode()) - last_update = card_info.get('last_update', 0) - password = card_info['password'] - if not cached: - if (now - last_update > 60) or fresh: - time_left = fetch_usertime(username) - last_update = time.time() - if re.match(r'[0-9:]+', time_left): - card_info['time_left'] = time_left - card_info['last_update'] = last_update - cards_db[username] = json.dumps(card_info) - time_left = card_info.get('time_left', '-') - return time_left + try: + with dbm.open(CARDS_DB, "c") as cards_db: + card_info = json.loads(cards_db[username].decode()) + last_update = card_info.get('last_update', 0) + password = card_info['password'] + if not cached: + if (now - last_update > 60) or fresh: + time_left = fetch_usertime(username) + last_update = time.time() + if re.match(r'[0-9:]+', time_left): + card_info['time_left'] = time_left + card_info['last_update'] = last_update + cards_db[username] = json.dumps(card_info) + time_left = card_info.get('time_left', '-') + return time_left + except: + return '-' def expire_date(username, fresh=False, cached=False): # expire date computation won't depend on last_update