def submit(): email, action = request.form['email'], request.form['action'] frm = request.form['from'] if len(frm) > 40: flash("From field too long... did you cheat the browser?") return redirect(url_for('welcome')) if len(email) > 60: flash("Destination e-mail field too long... did you cheat the browser?") return redirect(url_for('welcome')) if len(action) > 80: flash("Action field too long... did you cheat the browser?") return redirect(url_for('welcome')) if not email.endswith('@example.com'): if throttleTest(): send_mail(app, email, "{0} has hope".format(frm), body.format(frm = frm, action = action)) c['sent'].insert({ 'from': hashlib.sha1(frm).hexdigest(), 'to': hashlib.sha1(email).hexdigest(), 'msg': action, 'tsSent': datetime.datetime.utcnow() }) else: now = datetime.datetime.utcnow().strftime("%Y%m%d") c['throttling'].update({ '_id': 'throttles-' + now }, { '$inc': { 'count': 1 } }, upsert = True) flash("Failed to send; throttling exceeded") return redirect(url_for('welcome')) flash(email, category = "email") return redirect(url_for('accepted'))
def recog(): visitor=0 known_encoding = face_recognition.face_encodings(known_image)[0] print('known image encodings done') previous_state = False current_state = False while True: previous_state=current_state current_state=GPIO.input(sensor) if(current_state != previous_state): if(current_state): new_state="HIGH" else: new_state="LOW" print("GPIO pin %s is %s" % (sensor,new_state)) if(current_state): print("A photo will be taken in 3 seconds") time.sleep(3) with picamera.PiCamera() as camera: camera.resolution = (340, 220) time.sleep(2) camera.capture('unknown.jpg') unknown_image = face_recognition.load_image_file("/home/pi/Desktop/unknown.jpg") face_locations = face_recognition.face_locations(unknown_image) if(len(face_locations) == 0): print("no face detected") os.remove('unknown.jpg') continue unknown_encoding = face_recognition.face_encodings(unknown_image)[0] print("encodings calculated") results = face_recognition.compare_faces([known_encoding], unknown_encoding) print(results) if results == [True]: GPIO.setup(14, GPIO.OUT) print("person recognised,frank") p = PushBullet("o.a441em4dWH3fzGm1mcURidwfuJ1gG4Jn") #secret key of pushbullet API devices = p.getDevices() p.pushNote(devices[0]["iden"], 'Frank is at the door', 'open the door') os.remove("unknown.jpg") print("message sent") GPIO.cleanup() break else: while(os.path.exists("/home/pi/Desktop/known/"+str(visitor)+".jpg")): visitor=visitor+1 os.rename("/home/pi/Desktop/unknown.jpg","/home/pi/Desktop/"+str(visitor)+".jpg") shutil.move("/home/pi/Desktop/"+str(visitor)+".jpg","/home/pi/Desktop/known") print("unknown person") picname = str(visitor) + ".jpg" visitor=visitor+1 #cv2.imwrite(picname,frame) p = PushBullet("o.a441em4dWH3fzGm1mcURidwfuJ1gG4Jn") #secret key of pushbullet API devices = p.getDevices() p.pushFile(devices[0]["iden"], picname, "unknown person", open("/home/pi/Desktop/known/"+picname, "rb")) print("Sending email") attach=picname #attachments to send with email smail.send_mail(attach) print("email sent") break
def signup_new(request): cursos = Course.objects.filter(activo=True) if request.method == "POST": nombres = request.POST['nombres'] apellidos = request.POST['apellidos'] telefono = request.POST['telefono'] email = request.POST['email'] area_de_trabajo = request.POST['area_de_trabajo'] lugar_de_trabajo = request.POST['lugar_de_trabajo'] asistente, new_asistente = Assistant.objects.update_or_create(nombres=nombres, apellidos=apellidos, telefono=telefono, email=email, area_de_trabajo=area_de_trabajo, lugar_de_trabajo=lugar_de_trabajo) curso = Course.objects.get(id=request.POST['curso_elegido']) inscripcion, new_inscripcion = Inscription.objects.update_or_create(asistente=asistente, curso=curso) send_mail(email) return redirect('signup done') else: return render(request, 'web/index.html', {'cursos': cursos})
elem_curr.click() time.sleep(2) elem_confirm = driver.find_element_by_xpath( '/html/body/div[3]/div/table/tbody/tr[3]/td/div[2]/button[2]') elem_confirm.click() driver.save_screenshot(img1) time.sleep(5) # 检查是否抢占成功 elem_info_center = driver.find_element_by_class_name( 'login-welcome') elem_info_center.click() time.sleep(2) main_window = driver.current_window_handle driver.switch_to.window(driver.window_handles[1]) driver.save_screenshot(img2) info_doc = driver.page_source soup = BeautifulSoup(info_doc, 'lxml') table = soup.find_all('tbody')[0] tr = table.find_all('tr')[0] tds = tr.find_all('td') result = str(tr) if result.__contains__( str(tomorrow)) and result.__contains__('预约成功'): '''发送邮件通知''' print 'alert' smail.send_mail() is_wait = False break driver.close() driver.switch_to.window(main_window)
conn.close() except: values.append(100000) num = int(dt[0]) #导库报警代码 if num >= i[2]: fil = file('/var/www/webot/static/warn/warn.txt', 'r') tim = float(fil.read()) fil.close() if (int(tim) + 300) < int(now): fil = file('/var/www/webot/static/warn/warn.txt', 'w') wri = fil.write(str(now)) fil.close() comment = 'warn: 库ip: %s,类型:%s,时间:%s,导库数量:%s,表现为拥堵!' % ( i[0], i[1], date_time, dt[0]) [smail.send_mail(addr, 'warnning!!!', comment) for addr in to_mail] print comment value = tuple(values) con = MySQLdb.connect(host='localhost', user='******', passwd='', port=3306, db='webot') curs = con.cursor() de = curs.execute('delete from blog_storage_monitor where time<%s', (now - 48 * 3600)) imp = curs.execute( 'insert into blog_storage_monitor(time,news,bbs,blog,mblog,mblogs) values(%s,%s,%s,%s,%s,%s)', value) con.commit() curs.close()
#连接数据库 conn = MySQLdb.connect(host='localhost',user='******',passwd='',db='webot') cur = conn.cursor() #获取时间 now_datetime = str(datetime.now()) now_time = time.time() ago_time = now_time - 1800 #查询各域名半小时内采集数,判断预警 for i in domain_list: count = cur.execute('select sum(count) from blog_redis_count where domain=%s and time>%s',(i,ago_time)) co = str(cur.fetchone()[0]) if co == 'None': co = 0 print i,co if int(co) < val_list[i]: fil = file('/var/www/webot/static/warn/'+i+'.txt','r') history_time = float(fil.read()) fil.close() # print now_time - history_time if int(now_time - history_time) > 1800: content = 'warnning: 域名 '+i+'半小时内采集 '+str(co)+'条数据,预警时间 '+now_datetime [smail.send_mail(addr+to_suffix,'warnning!!!',content) for addr in to_mail] fl = file('/var/www/webot/static/warn/'+i+'.txt','w') wt = fl.write(str(now_time)) fl.close() print now_datetime,content print now_datetime
now_time = time.time() ago_time = now_time - 1800 #查询各域名半小时内采集数,判断预警 for i in domain_list: count = cur.execute( 'select sum(count) from blog_redis_count where domain=%s and time>%s', (i, ago_time)) co = str(cur.fetchone()[0]) if co == 'None': co = 0 print i, co if int(co) < val_list[i]: fil = file('/var/www/webot/static/warn/' + i + '.txt', 'r') history_time = float(fil.read()) fil.close() # print now_time - history_time if int(now_time - history_time) > 1800: content = 'warnning: 域名 ' + i + '半小时内采集 ' + str( co) + '条数据,预警时间 ' + now_datetime [ smail.send_mail(addr + to_suffix, 'warnning!!!', content) for addr in to_mail ] fl = file('/var/www/webot/static/warn/' + i + '.txt', 'w') wt = fl.write(str(now_time)) fl.close() print now_datetime, content print now_datetime