def get(name): if Config._config is None: try: with open(Util.basedir() + '/config.json', 'r') as fp: Config._config = json.load(fp) except: Util.log('json error on config.json') return None if name in Config._config: return Config._config[name] else: return None
now = datetime.now().strftime('%s') pictureDir = Util.basedir() + '/' + Config.get('picture-dir') detectedPicrure = pictureDir + '/preview.jpg' lastmodified = 0 for i in range(0, 30): if os.path.exists(detectedPicrure): stat = os.stat(detectedPicrure) if int(stat.st_mtime) >= int(now): lastmodified = stat.st_mtime break time.sleep(1) if lastmodified == 0: Util.log('file not found') sys.exit() savedPicture = pictureDir + '/' + now + '.jpg' shutil.copy(detectedPicrure, savedPicture) if Config.get('mail-to') == None or Config.get('mail-to') == '': Util.log('no email') sys.exit() message = MIMEMultipart() message['Subject'] = 'motion detected!' message['From'] = Config.get('mail-from') message['To'] = Config.get('mail-to') message.attach(MIMEText('motion detected!'))