def main(): camera = picamera.PiCamera() image_pth = 'image{}.jpg' img_proc = image_processor.image_processor() counter = 0 try: while True: occupied = False send_to_aws = False counter_itter = counter%4 camera.capture(image_pth.format(counter_itter)) print('Taking picture number', counter_itter, 'at', time.gmtime().tm_min) img_proc.add_image(image_pth.format(counter_itter)) if counter%5 == 0: send_to_aws = img_proc.make_decision() print('Should I send this to aws?', send_to_aws) if send_to_aws: print('Sending to aws') occupied = aws_rek.check_human(image_pth.format(0)) print('Is it occupied?', occupied) if not occupied: print('Sending out text') send_sms.send() counter += 1 time.sleep(1) except KeyboardInterrupt: print('interrupted!')
def forward_message(twilio_client, to_number, twilio_number, twilio_request): # format_incoming_sms_request(twilio_request) log_string = format_incoming_sms_request(twilio_request) logger.info(log_string) from_number = twilio_request.values.get('From', None) body = twilio_request.values.get('Body', None) person = get_person_by_phone_number(from_number, people) title = person.title first_name = person.first_name message = f"Message from {title} {first_name}: \n\n{body}" send(twilio_client, to_number, twilio_number, message)
def analyze(t): contenu = 0 try: fm = open(fnlow, 'r') try: contenu = fm.read() print('contenu du fichier ' + fnlow + ' : ' + contenu) except: contenu = 0 print('erreur de lecture du fichier ' + fnlow + ' => contenu = 0') finally: fm.close() except: contenu = 0 print('fichier ' + fnlow + ' inexistant => contenu = 0') contenu = float(contenu) if t < 15: now = time.time() ecoule = (now - float(contenu)) / 3600 h = int(time.strftime('%H')) print('now=' + str(now) + ', ecoule=' + str(ecoule) + ', h=' + str(h)) if ecoule > 8 and h <= 22 and h >= 6: msg = "Temperature\%20basse\%20:\%20" + str(t) print('msg to send: ' + msg) # os.system('curl ' + url + msg) send_sms.send(msg) fm = open(fnlow, 'w') fm.write(str(now)) fm.close() if t > 18 and contenu > 0: msg = "Temperature\%20revenue\%20correcte\%20:\%20" + str(t) print('msg to send: ' + msg) # os.system('curl ' + url + msg) send_sms.send(msg) os.remove(fnlow) return
def server_check(web_service, notify_number, frequency): log_format = '%(levelname)s %(asctime)s %(message)s' log_filename = os.path.join(os.path.dirname(__file__),'log_server_check.log') logging.basicConfig(filename=log_filename, level=logging.INFO, format=log_format) logging.info('Application launched') while True: request_header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} r = requests.get(web_service, headers = request_header) if r.status_code == 200: message = f"Hey! the site {web_service} isn\'t working." send_sms.send(notify_number, message) logging.info('Service is not available') else: logging.info('Service is available') time.sleep(frequency)
#!/usr/bin/python import os, sys sys.path.append(os.path.dirname(__file__) + "/../Lib") import send_sms send_sms.send("bonjour a tous")
def handler_listen(channel): if GPIO.input(pin): print('Movement!') email = send_mail.send(cfg) message = send_sms.send(cfg) handler_reponses(email, message)
topics_dict["created"].append(submission.created) topics_dict["body"].append( (submission.selftext).replace(",", " ").replace("\n", " ").replace("'", "''")) dataframe = pd.DataFrame(topics_dict) table_made = True if not table_made: make_table(connection) # Inserting each row into db for i in dataframe.index: if not post_exists(connection, dataframe['id'][i]): print("New entry: Adding %s db" % (dataframe['id'][i])) query = """ INSERT INTO posts(id, url, title, score, comms_num, created, body) VALUES('%s','%s','%s',%s,%s,%s,'%s'); """ % (dataframe['id'][i], dataframe['url'][i], dataframe['title'][i], dataframe['score'][i], dataframe['comms_num'][i], dataframe['created'][i], dataframe['body'][i]) single_insert(connection, query) print("Texting about new post") send_sms.send("New post: %s" % (dataframe['url'][i])) else: print("Entry exists in db, skipping") # Close the connection connection.close()
fm = open(fnIPaddr, 'r') contenu = fm.read() fm.close() if debug: print("contenu du fichier {0:s}: >{1:s}<".format(fnIPaddr, contenu)) except: contenu = 0 if debug: print("fichier {0:s} inexistant => contenu = 0".format(fnIPaddr)) if sortie != contenu: # write last IP addr in a file if debug: print('Nouvelle adresse IP => write to file and send sms') fo = open(fnIPaddr, 'w') fo.write(sortie) fo.close() send_sms.send('Nouvelle adresse IP externe : ' + sortie) else: dat = os.path.getmtime(fnIPaddr) past = ( datetime.now() - timedelta(days=30) - datetime(1970,1,1) ).total_seconds() if debug: print("dat: {0:f}, past: {1:f}".format(dat, past)) if dat < past: if debug: print('Adresse IP externe inchangee depuis un mois : ' + sortie) send_sms.send('Adresse IP externe inchangee depuis un mois : ' + sortie)