refactor(memobird): improve portability with dependency checks and error handling
This commit is contained in:
parent
9af18e5879
commit
64137350b4
|
|
@ -7,6 +7,16 @@ description: Print text, images, and notes directly to the Memobird thermal prin
|
||||||
|
|
||||||
Direct printing to the Memobird thermal printer on the local network.
|
Direct printing to the Memobird thermal printer on the local network.
|
||||||
|
|
||||||
|
## 📦 Installation
|
||||||
|
|
||||||
|
This skill requires Python 3 and several libraries. Install them using:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
*Note: Depends on `requests` and `Pillow`.*
|
||||||
|
|
||||||
## 🚀 Usage
|
## 🚀 Usage
|
||||||
|
|
||||||
Use the `scripts/memobird_print.py` tool. By default, it targets the static IP `192.168.10.165`.
|
Use the `scripts/memobird_print.py` tool. By default, it targets the static IP `192.168.10.165`.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
requests
|
||||||
|
Pillow
|
||||||
|
|
@ -1,14 +1,28 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from random import randint
|
from random import randint
|
||||||
from PIL import Image as PILImg, ImageOps
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
# Dependency Check
|
||||||
|
MISSING_DEPS = []
|
||||||
|
try:
|
||||||
|
import requests
|
||||||
|
except ImportError:
|
||||||
|
MISSING_DEPS.append("requests")
|
||||||
|
try:
|
||||||
|
from PIL import Image as PILImg, ImageOps
|
||||||
|
except ImportError:
|
||||||
|
MISSING_DEPS.append("Pillow (PIL)")
|
||||||
|
|
||||||
|
if MISSING_DEPS:
|
||||||
|
print(f"Error: Missing dependencies: {', '.join(MISSING_DEPS)}")
|
||||||
|
print("Please install them using: pip install " + " ".join(["requests", "Pillow"]))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Default IP for Moritz's Memobird
|
# Default IP for Moritz's Memobird
|
||||||
DEFAULT_HOST = "192.168.10.165"
|
DEFAULT_HOST = "192.168.10.165"
|
||||||
|
|
||||||
|
|
@ -48,6 +62,14 @@ class MemobirdSender:
|
||||||
resp = requests.post(self.uri, json=payload, timeout=10)
|
resp = requests.post(self.uri, json=payload, timeout=10)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return resp.status_code
|
return resp.status_code
|
||||||
|
except requests.exceptions.ConnectTimeout:
|
||||||
|
print(f"Error: Connection to Memobird at {self.host} timed out.")
|
||||||
|
print("Check if the printer is powered on and on the same network.")
|
||||||
|
sys.exit(1)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
print(f"Error: Could not connect to Memobird at {self.host}.")
|
||||||
|
print("Verify the IP address and network connectivity.")
|
||||||
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error sending to Memobird: {e}")
|
print(f"Error sending to Memobird: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue