Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor submission into a function #24

Open
fhdk opened this issue Nov 16, 2024 · 0 comments
Open

Refactor submission into a function #24

fhdk opened this issue Nov 16, 2024 · 0 comments

Comments

@fhdk
Copy link
Member

fhdk commented Nov 16, 2024

This will allow for calling the submit function from a GUI.

diff --git a/mdd.py b/mdd.py
index cb9f3c1..63eaf22 100644
--- a/mdd.py
+++ b/mdd.py
@@ -24,6 +24,22 @@ from dateutil import parser as date_parser
 inxi = None
 
 
+def http_post_info(sys_info) -> bool:
+    try:
+        response = requests.post(
+            "https://metrics-api.manjaro.org/send",
+            json=sys_info,
+            headers={"Content-Type": "application/json"},
+            timeout=2,
+        )
+
+        response.raise_for_status()
+        return True
+    except Exception as e:
+        logging.error(f"submitting telemetry: {e}")
+        return False
+
+
 def json_beaut(input, sort_keys=False):
     return json.dumps(input, indent=4, sort_keys=sort_keys)
 
@@ -826,21 +842,11 @@ def main():
         print("Note: Skipping data submission because of dry run.")
         return
 
-    try:
-        response = requests.post(
-            "https://metrics-api.manjaro.org/send",
-            json=data,
-            headers={"Content-Type": "application/json"},
-            timeout=2,
-        )
-
-        response.raise_for_status()
-    except Exception as e:
-        logging.error(f"submitting telemetry: {e}")
+    if http_post_info(data):
+        print("Succesful sent at", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
+    else:
         exit(1)
 
-    print("Succesful sent at", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
-
 
 if __name__ == "__main__":
     main()

refactor-submission-to-function.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant