#!/usr/bin/env python3 import urllib.request from os import path, sep class API: """ Creation of a request to the camera API based on the prepared template. """ def __init__(self, host: str, user: str, password: str, template: str, protocol: str = 'http', port: int = 80, channel: int = 101, vid: int = 1, x: int = 0, y: int = 0, z: int = 0, speed: int = 1, time: int = 100000, text: str = None, enabled: str = 'true'): """ Object constructor :param host: hostname or ip address :param user: valid user :param password: valid password :param template: the name of an existing template :param protocol: http, https, etc. :param port: port number :param channel: ptz channel number :param vid: video channel id :param x: horizontal positioning: azimuth, pan :param y: vertical positioning: elevation, tilt :param z: zoom direction, absolute zoom :param speed: positioning speed: from 1 to 7 :param time: momentary duration, max 100000ms :param text: overlay text content :param enabled: enabled (true) or disabled (false) overlay text """ self._host = host self._user = user self._pswd = password self._temp = path.dirname(path.abspath(__file__)) + sep + 'templates' + sep + template self._protocol = protocol self._port = port self._channel = channel self._id = vid self._x = x self._y = y self._z = z self._speed = speed self._time = time self._message = text self._enabledMessage = enabled self._data = '' self._type = '' self._url = self._protocol + '://' + self._host + ':' + str(self._port) self._method = '' with open(self._temp) as file: content = file.read() \ .replace('@CHANNEL@', str(self._channel)) \ .replace('@ID@', str(self._id)) \ .replace('@XXXX@', str(self._x)) \ .replace('@YYYY@', str(self._y)) \ .replace('@ZZZZ@', str(self._z)) \ .replace('@TTTT@', str(self._time)) \ .replace('@SSSS@', str(self._speed)) \ .replace('@MSG@', str(self._message)) \ .replace('@ENABLED@', str(self._enabledMessage)) for line in content.splitlines(): if not ('