]> Nutra Git (v1) - nutratech/cli.git/commitdiff
keep chugging on bugs
authorShane Jaroch <chown_tee@proton.me>
Wed, 14 Feb 2024 20:57:47 +0000 (15:57 -0500)
committerShane Jaroch <chown_tee@proton.me>
Wed, 14 Feb 2024 20:59:32 +0000 (15:59 -0500)
ntclient/argparser/funcs.py
ntclient/services/api/__init__.py
ntclient/services/bugs.py

index 9b0b77e044504597c1136960a1ef76aaf9a69d5e..d63a2f1deb9283350056d7bf831a1d623405720d 100644 (file)
@@ -342,12 +342,16 @@ def bugs_list(args: argparse.Namespace) -> tuple:
     """List bug reports that have een saved"""
     _bugs_list = ntclient.services.bugs.list_bugs()
 
-    print(f"You have {len(_bugs_list)} unique bugs to report/submit!  Good job.")
+    print(f"You have: {len(_bugs_list)} total bugs amassed in your journey.")
+    print(
+        f"Of these, {len([x for x in _bugs_list if not bool(x[-1])])} "
+        f"require submission/reporting."
+    )
     print()
 
     for bug in _bugs_list:
         # Skip submitted bugs by default
-        if bug[-1] != 0 and not args.all:
+        if bool(bug[-1]) and not args.all:
             continue
         # Print all (except noisy stacktrace)
         print(", ".join(str(x) for x in bug if "\n" not in str(x)))
index 7135c9d1c2c950017438d591cb67ac7f6ac9a771..0b1e89a191d398b075031ef7cb311a3a28b8e222 100644 (file)
@@ -5,6 +5,8 @@ Created on Tue Feb 13 14:28:20 2024
 
 @author: shane
 """
+import sqlite3
+
 import requests
 
 URL_API = "https://api.nutra.tk"
@@ -27,26 +29,26 @@ class ApiClient:
     ):
         self.host = host
 
-    def get(self, path: str) -> dict:
+    def get(self, path: str) -> requests.Response:
         """Get data from the API."""
-        req = requests.get(
+        _res = requests.get(
             f"{self.host}/{path}",
             timeout=(REQUEST_CONNECT_TIMEOUT, REQUEST_READ_TIMEOUT),
         )
-        req.raise_for_status()
-        return dict(req.json())
+        _res.raise_for_status()
+        return _res
 
-    def post(self, path: str, data: dict) -> dict:
+    def post(self, path: str, data: dict) -> requests.Response:
         """Post data to the API."""
-        req = requests.post(
+        _res = requests.post(
             f"{self.host}/{path}",
             json=data,
             timeout=(REQUEST_CONNECT_TIMEOUT, REQUEST_READ_TIMEOUT),
         )
-        req.raise_for_status()
-        return dict(req.json())
+        _res.raise_for_status()
+        return _res
 
     # TODO: move this outside class; support with host iteration helper method
-    def post_bug(self, bug: tuple) -> None:
+    def post_bug(self, bug: sqlite3.Row) -> requests.Response:
         """Post a bug report to the developer."""
-        self.post("bug", dict(bug))
+        return self.post("bug", dict(bug))
index 75e047d8a81a1b1e118d6c575eb27351a82f79be..28d1e84fb64eed0b1cbb94a0984cd9e7967cd8b3 100644 (file)
@@ -46,7 +46,7 @@ INSERT INTO bug
 
 def list_bugs() -> list:
     """List all bugs."""
-    sql_bugs = sql_nt("SELECT * FROM bug WHERE submitted = 0")
+    sql_bugs = sql_nt("SELECT * FROM bug")
     return sql_bugs
 
 
@@ -58,12 +58,19 @@ def submit_bugs() -> int:
     n_submitted = 0
     print(f"submitting {len(sql_bugs)} bug reports...")
     print("_" * len(sql_bugs))
+
     for bug in sql_bugs:
+        _res = api_client.post_bug(bug)
+
+        # Differentially store unique vs. duplicate bugs (someone else submitted)
+        if _res.status_code == 201:
+            sql_nt("UPDATE bug SET submitted = 1 WHERE id = %s", bug.id)
+        elif _res.status_code in {200, 204}:
+            sql_nt("UPDATE bug SET submitted = 2 WHERE id = %s", bug.id)
+
         print(".", end="", flush=True)
-        api_client.post_bug(bug)
         n_submitted += 1
+
     print()
-    # 1 / 0  # force exception
-    # raise Exception("submitting bug reports failed")
 
     return n_submitted