-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included code for image notifications!
- Loading branch information
Showing
7 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ coloredlogs==15.0.1 | |
requests==2.26.0 | ||
websockets==10.1 | ||
pytz==2022.7.1 | ||
tzlocal==4.3 | ||
tzlocal==4.3 | ||
Pillow==9.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from io import BytesIO | ||
import logging | ||
from PIL import Image | ||
from typing import List, Optional | ||
|
||
import requests | ||
|
||
|
||
class SnapshotClient: | ||
def __init__( | ||
self, | ||
uri: str, | ||
rotation: int = 0 | ||
) -> None: | ||
super().__init__() | ||
self.uri: str = uri | ||
self.rotation: int = rotation | ||
self.logger = logging.getLogger('mobileraker.cam') | ||
|
||
def takeSnapshot(self,) -> Optional[bytes]: | ||
|
||
self.logger.info( | ||
f"Trying to take a snapshot from URI: {self.uri}") | ||
try: | ||
res = requests.get(self.uri, timeout=5) | ||
res.raise_for_status() | ||
self.logger.info( | ||
f"Took webcam snapshot! Converting using {self.rotation}") | ||
image = Image.open(BytesIO(res.content)).convert("RGB") | ||
image = image.rotate(self.rotation) | ||
buffered = BytesIO() | ||
image.save(buffered, format="JPEG") | ||
|
||
return buffered.getvalue() | ||
except requests.exceptions.ConnectionError as err: | ||
self.logger.error("Could not connect to webcam!") | ||
except: | ||
self.logger.error("Unable to process take snapshot request") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters