email['Date'] = formatdate(localtime=True)
email.attach(MIMEText(message))
- for f in reversed(files):
+ for name in reversed(files):
part = MIMEBase('image', 'jpeg')
- with open(f, 'rb') as f:
+ with open(name, 'rb') as f:
part.set_payload(f.read())
Encoders.encode_base64(part)
- part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
+ part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(name))
email.attach(part)
if files:
if media_files:
logging.debug('got media files')
- media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < timespan] # filter out non-recent media files
+
+ # filter out non-recent media files
+ media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < timespan]
media_files.sort(key=lambda m: m['timestamp'], reverse=True)
media_files = [os.path.join(camera_config['target_dir'], re.sub('^/', '', m['path'])) for m in media_files]
-
+
logging.debug('selected %d pictures' % len(media_files))
format_dict = {
else:
format_dict['timezone'] = 'local time'
+
+ logging.debug('creating email message')
m = message % format_dict
s = subject % format_dict
m += '\n\n'
m += 'motionEye.'
-
+
callback(s, m, media_files)
if not timespan:
logging.debug('waiting for pictures to be taken')
time.sleep(timespan) # give motion some time to create motion pictures
-
- logging.debug('creating email message')
- mediafiles.list_media(camera_config, media_type='picture', callback=on_media_files)
+
+ prefix = None
+ picture_filename = camera_config.get('picture_filename')
+ snapshot_filename = camera_config.get('snapshot_filename')
+
+ if ((picture_filename or snapshot_filename) and
+ not picture_filename or picture_filename.startswith('%Y-%m-%d/') and
+ not snapshot_filename or snapshot_filename .startswith('%Y-%m-%d/')):
+
+ prefix = moment.strftime('%Y-%m-%d')
+ logging.debug('narrowing down still images path lookup to %s' % prefix)
+
+ mediafiles.list_media(camera_config, media_type='picture', prefix=prefix, callback=on_media_files)
io_loop.start()
def on_message(subject, message, files):
try:
+ logging.info('sending email')
send_mail(options.server, options.port, options.account, options.password,
options.tls, _from, to, subject, message, files or [])
logging.info('email sent')