|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -from typing import Collection, Dict |
| 15 | +from typing import Collection, Dict, List |
16 | 16 |
|
17 | 17 | import requests
|
18 | 18 |
|
|
25 | 25 | FILTERS_URL = f'{API_BASE}/api/v3/photo/filters'
|
26 | 26 |
|
27 | 27 |
|
28 |
| -class Camera: |
29 |
| - def __init__(self, id, **kwargs): # noqa |
30 |
| - for k, v in kwargs.items(): |
| 28 | +class _AttrDict: |
| 29 | + def __init__(self, d): # noqa |
| 30 | + for k, v in d.items(): |
| 31 | + if isinstance(v, Dict): |
| 32 | + v = _AttrDict(v) |
| 33 | + elif isinstance(v, List): |
| 34 | + v_new = list() |
| 35 | + for v_sub in v: |
| 36 | + if isinstance(v_sub, dict): |
| 37 | + v_new.append(_AttrDict(v_sub)) |
| 38 | + else: |
| 39 | + v_new.append(v_sub) |
| 40 | + v = tuple(v_new) |
31 | 41 | if k and k[0] != '_':
|
32 | 42 | setattr(self, k, v)
|
| 43 | + |
| 44 | + |
| 45 | +class Camera(_AttrDict): |
| 46 | + def __init__(self, id, **kwargs): # noqa |
| 47 | + super(Camera, self).__init__(kwargs) |
33 | 48 | self.id = id
|
34 | 49 |
|
35 | 50 | def __repr__(self):
|
36 | 51 | return f'Camera({self.id})'
|
37 | 52 |
|
38 | 53 |
|
39 |
| -class Photo: |
| 54 | +class Photo(_AttrDict): |
40 | 55 | def __init__(self, **kwargs):
|
41 |
| - for k, v in kwargs.items(): |
42 |
| - if k and k[0] != '_': |
43 |
| - setattr(self, k, v) |
| 56 | + super(Photo, self).__init__(kwargs) |
44 | 57 |
|
45 | 58 | def __repr__(self):
|
46 | 59 | return f'Photo({self.id})' # noqa
|
47 | 60 |
|
48 | 61 | def url(self, size='large'):
|
49 |
| - section = getattr(self, size) |
50 |
| - return f'https://{section.get("host")}/{section.get("path")}' |
| 62 | + section = getattr(self, size, dict()) |
| 63 | + return f'https://{getattr(section, "host")}/{getattr(section, "path")}' |
51 | 64 |
|
52 | 65 |
|
53 | 66 | class Client:
|
|
1 commit comments
rambis1991 commentedon Apr 29, 2024
Sorry I’m not a developer but I do like to Splunk most all of my IOT data. Haven’t used this script yet to pull SPYPOINT pic URLs, but would definitely like to have power / cell signal / firmware status info on my cameras pulled on an hourly basis. Any chance you or the team could tweak the script to pull that data?