Refactor submission into a function
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 16
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/user-attachments/files/17783884/refactor-submission-to-function.txt)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in mdd.py by reading main() and the existing requests.post submission block. Extract that submission into the proposed http_post_info function, preserve its success and failure behavior, and confirm that main() calls it with the collected data and handles the result as shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, cli
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100