From 5d3ab5cb99d40202ed56418b17bf6f7d4fb372c4 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 20 Dec 2015 18:26:58 +0200 Subject: [PATCH] fixed wrong camera/thread_id association when sending emails --- motioneye/motionctl.py | 3 ++- motioneye/sendmail.py | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/motioneye/motionctl.py b/motioneye/motionctl.py index 82f4f7e..741294a 100644 --- a/motioneye/motionctl.py +++ b/motioneye/motionctl.py @@ -293,6 +293,7 @@ def camera_id_to_thread_id(camera_id): # (which can be different from camera_id) camera_ids = config.get_camera_ids() thread_id = 0 + camera_id = int(camera_id) for cid in camera_ids: camera_config = config.get_camera(cid) if utils.local_motion_camera(camera_config): @@ -309,7 +310,7 @@ def thread_id_to_camera_id(thread_id): threads = main_config.get('thread', '') try: - return int(re.search('thread-(\d+).conf', threads[thread_id - 1]).group(1)) + return int(re.search('thread-(\d+).conf', threads[int(thread_id) - 1]).group(1)) except IndexError: return None diff --git a/motioneye/sendmail.py b/motioneye/sendmail.py index 19c3a69..59efe64 100644 --- a/motioneye/sendmail.py +++ b/motioneye/sendmail.py @@ -35,6 +35,7 @@ import settings import config import mediafiles +import motionctl import tzctl @@ -140,7 +141,7 @@ def parse_options(parser, args): parser.add_argument('tls', help='"true" to use TLS') parser.add_argument('to', help='the email recipient(s)') parser.add_argument('msg_id', help='the identifier of the message') - parser.add_argument('camera_id', help='the id of the camera') + parser.add_argument('thread_id', help='the id of the motion thread') parser.add_argument('moment', help='the moment in ISO-8601 format') parser.add_argument('timespan', help='picture collection time span') @@ -172,6 +173,8 @@ def main(parser, args): # email notifications are critical settings.LIST_MEDIA_TIMEOUT = 10 + camera_id = motionctl.thread_id_to_camera_id(options.thread_id) + logging.debug('server = %s' % options.server) logging.debug('port = %s' % options.port) logging.debug('account = %s' % options.account) @@ -180,7 +183,8 @@ def main(parser, args): logging.debug('tls = %s' % str(options.tls).lower()) logging.debug('to = %s' % options.to) logging.debug('msg_id = %s' % options.msg_id) - logging.debug('camera_id = %s' % options.camera_id) + logging.debug('thread_id = %s' % options.thread_id) + logging.debug('camera_id = %s' % camera_id) logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S')) logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT) logging.debug('timespan = %d' % options.timespan) @@ -199,4 +203,4 @@ def main(parser, args): logging.debug('bye!') - make_message(subject, message, options.camera_id, options.moment, options.timespan, on_message) + make_message(subject, message, camera_id, options.moment, options.timespan, on_message) -- 2.39.5