Skip to content

Commit e1cb9bd

Browse files
authored
Merge pull request #37 from barretobrock/develop
Refactor package to be imported as a single package
2 parents 0221215 + 0fdd0df commit e1cb9bd

35 files changed

+601
-361
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
secrets.cfg
12
# Byte-compiled / optimized / DLL files
23
__pycache__/
34
*.py[cod]

Camera.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

ConfigHandler.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<p align="center">
44
<img alt="Reolink Approval" src="https://img.shields.io/badge/reolink-approved-blue?style=flat-square">
5-
<img alt="GitHub" src="https://img.shields.io/github/license/ReolinkCameraApi/reolink-python-api?style=flat-square">
6-
<img alt="GitHub tag (latest SemVer)" src="https://img.shields.io/github/v/tag/ReolinkCameraApi/reolink-python-api?style=flat-square">
7-
<img alt="PyPI" src="https://img.shields.io/pypi/v/reolink-api?style=flat-square">
5+
<img alt="GitHub" src="https://img.shields.io/github/license/ReolinkCameraAPI/reolinkapipy?style=flat-square">
6+
<img alt="GitHub tag (latest SemVer)" src="https://img.shields.io/github/v/tag/ReolinkCameraAPI/reolinkapipy?style=flat-square">
7+
<img alt="PyPI" src="https://img.shields.io/pypi/v/reolinkapi?style=flat-square">
88
<img alt="Discord" src="https://img.shields.io/discord/773257004911034389?style=flat-square">
99
</p>
1010

api/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

api/recording.py

Lines changed: 0 additions & 111 deletions
This file was deleted.

examples/basic_usage.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import reolinkapi
2+
3+
if __name__ == "__main__":
4+
cam = reolinkapi.Camera("192.168.0.102", defer_login=True)
5+
6+
# must first login since I defer have deferred the login process
7+
cam.login()
8+
9+
dst = cam.get_dst()
10+
ok = cam.add_user("foo", "bar", "admin")
11+
alarm = cam.get_alarm_motion()

examples/download_motions.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Downloads all motion events from camera from the past hour."""
2+
import os
3+
from configparser import RawConfigParser
4+
from datetime import datetime as dt, timedelta
5+
from reolinkapi import Camera
6+
7+
8+
def read_config(props_path: str) -> dict:
9+
"""Reads in a properties file into variables.
10+
11+
NB! this config file is kept out of commits with .gitignore. The structure of this file is such:
12+
# secrets.cfg
13+
[camera]
14+
ip={ip_address}
15+
username={username}
16+
password={password}
17+
"""
18+
config = RawConfigParser()
19+
assert os.path.exists(props_path), f"Path does not exist: {props_path}"
20+
config.read(props_path)
21+
return config
22+
23+
24+
# Read in your ip, username, & password
25+
# (NB! you'll likely have to create this file. See tests/test_camera.py for details on structure)
26+
config = read_config('../secrets.cfg')
27+
28+
ip = config.get('camera', 'ip')
29+
un = config.get('camera', 'username')
30+
pw = config.get('camera', 'password')
31+
32+
# Connect to camera
33+
cam = Camera(ip, un, pw)
34+
35+
start = (dt.now() - timedelta(hours=1))
36+
end = dt.now()
37+
# Collect motion events between these timestamps for substream
38+
processed_motions = cam.get_motion_files(start=start, end=end, streamtype='sub')
39+
40+
dl_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
41+
for i, motion in enumerate(processed_motions):
42+
fname = motion['filename']
43+
# Download the mp4
44+
resp = cam.get_file(fname, output_path=os.path.join(dl_dir, f'motion_event_{i}.mp4'))

examples/streaming_video.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import cv2
2-
3-
from Camera import Camera
2+
from reolinkapi import Camera
43

54

65
def non_blocking():

reolinkapi/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from reolinkapi.handlers.api_handler import APIHandler
2+
from .camera import Camera
3+
4+
__version__ = "0.1.2"

0 commit comments

Comments
 (0)