Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. from flask import Flask, render_template, Response
  3.  
  4. from camera import Camera
  5.  
  6. import serial
  7. from flask import Flask, render_template, Response
  8.  
  9. from camera import Camera
  10.  
  11. import serial
  12.  
  13. import subprocess
  14.  
  15.  
  16.  
  17. arduino = serial.Serial('/dev/ttyACM0', 9600)
  18.  
  19. app = Flask(__name__)
  20.  
  21.  
  22.  
  23. @app.route('/')
  24.  
  25. def index():
  26.  
  27. return render_template('index.html')
  28.  
  29.  
  30. def gen(camera):
  31.  
  32. while True:
  33.  
  34. frame = camera.get_frame()
  35.  
  36. yield (b'--frame\r\n'
  37.  
  38. b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
  39.  
  40.  
  41.  
  42. @app.route('/video_feed')
  43.  
  44. def video_feed():
  45.  
  46. return Response(gen(Camera()),
  47.  
  48. mimetype='multipart/x-mixed-replace; boundary=frame')
  49.  
  50.  
  51. @app.route("/feed")
  52.  
  53. def feed():
  54.  
  55. try:
  56.  
  57. arduino.write('a')
  58.  
  59. return "1"
  60.  
  61. except:
  62.  
  63. pass
  64.  
  65.  
  66. return "0"
  67.  
  68.  
  69. def sendAutostartMail():
  70.  
  71. import smtplib
  72.  
  73. import string
  74.  
  75. USER='wnsrud6839@gamil.com'
  76.  
  77. PASS='pjkrud6839'
  78.  
  79. TO='wnsrud0111@naver.com'
  80.  
  81. SUBJECT='Feed!!!!'
  82.  
  83.  
  84. ip = subprocess.check_output("hostname -I", shell= True)
  85.  
  86. TEXT = 'your RPs IP addess is %s.\n Please connect here and click Feed' %ip
  87.  
  88.  
  89.  
  90. FROM = USER
  91.  
  92. HOST = 'smtp.gmail.com:587'
  93.  
  94. BODY = string.join((
  95.  
  96. 'From: %s' %FROM,
  97.  
  98. 'To: %s' %TO,
  99.  
  100. 'Subject: %s' %SUBJECT,
  101.  
  102. '\r\n',
  103.  
  104. TEXT,
  105.  
  106. ), '\r\n')
  107.  
  108.  
  109.  
  110. server=smtplib.SMTP(HOST)
  111.  
  112. server.starttls()
  113.  
  114. server.login(USER, PASS)
  115.  
  116. server.sendmail(FROM, TO, BODY)
  117.  
  118. server.quit()
  119.  
  120.  
  121. return null;
  122.  
  123.  
  124.  
  125.  
  126. if __name__ == '__main__':
  127.  
  128. app.run(host='0.0.0.0', debug=True, threaded=True)
  129.  
  130. sendAutostartMail()
  131.  
  132.  
  133. import subprocess
  134.  
  135.  
  136.  
  137. arduino = serial.Serial('/dev/ttyACM0', 9600)
  138.  
  139. app = Flask(__name__)
  140.  
  141.  
  142.  
  143. @app.route('/')
  144.  
  145. def index():
  146.  
  147. return render_template('index.html')
  148.  
  149.  
  150. def gen(camera):
  151.  
  152. while True:
  153.  
  154. frame = camera.get_frame()
  155.  
  156. yield (b'--frame\r\n'
  157.  
  158. b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
  159.  
  160.  
  161.  
  162. @app.route('/video_feed')
  163.  
  164. def video_feed():
  165.  
  166. return Response(gen(Camera()),
  167.  
  168. mimetype='multipart/x-mixed-replace; boundary=frame')
  169.  
  170.  
  171. @app.route("/feed")
  172.  
  173. def feed():
  174.  
  175. try:
  176.  
  177. arduino.write('a')
  178.  
  179. return "1"
  180.  
  181. except:
  182.  
  183. pass
  184.  
  185.  
  186. return "0"
  187.  
  188.  
  189. def sendAutostartMail():
  190.  
  191. import smtplib
  192.  
  193. import string
  194.  
  195. USER='wnsrud6839@gamil.com'
  196.  
  197. PASS='pjkrud6839'
  198.  
  199. TO='wnsrud0111@naver.com'
  200.  
  201. SUBJECT='Feed!!!!'
  202.  
  203.  
  204. ip = subprocess.check_output("hostname -I", shell= True)
  205.  
  206. TEXT = 'your RPs IP addess is %s.\n Please connect here and click Feed' %ip
  207.  
  208.  
  209.  
  210. FROM = USER
  211.  
  212. HOST = 'smtp.gmail.com:587'
  213.  
  214. BODY = string.join((
  215.  
  216. 'From: %s' %FROM,
  217.  
  218. 'To: %s' %TO,
  219.  
  220. 'Subject: %s' %SUBJECT,
  221.  
  222. '\r\n',
  223.  
  224. TEXT,
  225.  
  226. ), '\r\n')
  227.  
  228.  
  229.  
  230. server=smtplib.SMTP(HOST)
  231.  
  232. server.starttls()
  233.  
  234. server.login(USER, PASS)
  235.  
  236. server.sendmail(FROM, TO, BODY)
  237.  
  238. server.quit()
  239.  
  240.  
  241. return null;
  242.  
  243.  
  244.  
  245.  
  246. if __name__ == '__main__':
  247.  
  248. app.run(host='0.0.0.0', debug=True, threaded=True)
  249.  
  250. sendAutostartMail()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement