Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond LeClair committed Jul 14, 2023
1 parent 3be9290 commit 28b649d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 27 deletions.
66 changes: 39 additions & 27 deletions axis-ptz-controller/camera_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ class CameraConfiguration(vapix_config.CameraConfiguration):
https://github.com/smartsenselab/sensecam-control.
"""

def get_jpeg_request(self, resolution: str = None, camera: str = None,
square_pixel: int = None, compression: int = None,
clock: int = None, date: int = None, text: int = None,
text_string: str = None, text_color: str = None,
text_background_color: str = None, rotation: int = None,
text_position: str = None, overlay_image: int = None,
overlay_position: str = None): # 5.2.4.1
def get_jpeg_request(
self,
resolution: str = None,
camera: str = None,
square_pixel: int = None,
compression: int = None,
clock: int = None,
date: int = None,
text: int = None,
text_string: str = None,
text_color: str = None,
text_background_color: str = None,
rotation: int = None,
text_position: str = None,
overlay_image: int = None,
overlay_position: str = None,
): # 5.2.4.1
"""
The requests specified in the JPEG/MJPG section are supported by those video products
that use JPEG and MJPG encoding.
Expand Down Expand Up @@ -68,31 +78,33 @@ def get_jpeg_request(self, resolution: str = None, camera: str = None,
"""
payload = {
'resolution': resolution,
'camera': camera,
'square_pixel': square_pixel,
'compression': compression,
'clock': clock,
'date': date,
'text': text,
'text_string': text_string,
'text_color': text_color,
'text_background_color': text_background_color,
'rotation': rotation,
'text_position': text_position,
'overlay_image': overlay_image,
'overlay_position': overlay_position
"resolution": resolution,
"camera": camera,
"square_pixel": square_pixel,
"compression": compression,
"clock": clock,
"date": date,
"text": text,
"text_string": text_string,
"text_color": text_color,
"text_background_color": text_background_color,
"rotation": rotation,
"text_position": text_position,
"overlay_image": overlay_image,
"overlay_position": overlay_position,
}
url = 'http://' + self.cam_ip + '/axis-cgi/jpg/image.cgi'
logging.info(f"url: {url}")
resp = requests.get(url, auth=HTTPDigestAuth(self.cam_user, self.cam_password),
params=payload)
url = "http://" + self.cam_ip + "/axis-cgi/jpg/image.cgi"
logging.debug(f"url: {url}")
logging.debug(f"payload: {payload}")
resp = requests.get(
url, auth=HTTPDigestAuth(self.cam_user, self.cam_password), params=payload
)

if resp.status_code == 200:
now = datetime.datetime.now()
with open(str(now.strftime("%d-%m-%Y_%Hh%Mm%Ss")) + ".jpg", 'wb') as var:
with open(str(now.strftime("%d-%m-%Y_%Hh%Mm%Ss")) + ".jpg", "wb") as var:
var.write(resp.content)
return str('Image saved')
return str("Image saved")

text = str(resp)
text += str(resp.text)
Expand Down
22 changes: 22 additions & 0 deletions axis-ptz-controller/camera_control.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import coloredlogs
import logging

from sensecam_control import vapix_control
from typing import Tuple, Union

STYLES = {
"critical": {"bold": True, "color": "red"},
"debug": {"color": "green"},
"error": {"color": "red"},
"info": {"color": "white"},
"notice": {"color": "magenta"},
"spam": {"color": "green", "faint": True},
"success": {"bold": True, "color": "green"},
"verbose": {"color": "blue"},
"warning": {"color": "yellow"},
}
coloredlogs.install(
level=logging.INFO,
fmt="%(asctime)s.%(msecs)03d \033[0;90m%(levelname)-8s "
""
"\033[0;36m%(filename)-18s%(lineno)3d\033[00m "
"%(message)s",
level_styles=STYLES,
)

class CameraControl(vapix_control.CameraControl):
"""
Expand Down

0 comments on commit 28b649d

Please sign in to comment.