Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.75 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: latin-1 -*-
  3. import sys
  4. import os
  5. import time
  6. import random
  7. import datetime
  8. import telepot
  9. import picamera
  10. import RPi.GPIO as GPIO
  11. from time import sleep
  12. from fractions import Fraction
  13. GPIO.setmode(GPIO.BOARD)
  14. GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  15.  
  16.  
  17. """
  18. Skript
  19. """
  20.  
  21. def handle(msg):
  22.     chat_id = msg['chat']['id']
  23.     command = msg['text']
  24.  
  25.     print 'Got command: %s' % command
  26.  
  27.     if command == '/photo':
  28.         with picamera.PiCamera() as camera:
  29.             camera.start_preview()
  30.             time.sleep(5)
  31.             camera.resolution = (1024, 768)
  32.             camera.capture('/opt/bewegung/dateien/BEWEGUNG.jpg')
  33.             camera.stop_preview()
  34.         bot.sendPhoto(-116762447, photo=open('dateien/BEWEGUNG.jpg', 'rb'), caption='Foto hochgeladen. Resolution: 1024x768')
  35.        
  36.        
  37.  
  38.     elif command == '/photo hd':
  39.         with picamera.PiCamera() as camera:
  40.             camera.start_preview()
  41.             time.sleep(5)
  42.             camera.resolution = (1920, 1080)
  43.             camera.capture('/opt/bewegung/dateien/BEWEGUNG.jpg')
  44.             camera.stop_preview()
  45.         bot.sendPhoto(-116762447, photo=open('dateien/BEWEGUNG.jpg', 'rb'), caption='Foto hochgeladen. Resolution: 1920x1080')
  46.        
  47.     elif command == '/photo dunkel':
  48.         with picamera.PiCamera() as camera:
  49.             camera.start_preview()
  50.             time.sleep(5)
  51.             camera.resolution = (1920, 1080)
  52.     # Set a framerate of 1/6fps, then set shutter
  53.     # speed to 6s and ISO to 800
  54.             camera.framerate = Fraction(1, 6)
  55.             camera.shutter_speed = 6000000
  56.             camera.exposure_mode = 'off'
  57.             camera.iso = 800
  58.     # Give the camera a good long time to measure AWB
  59.     # (you may wish to use fixed AWB instead)
  60.             sleep(10)
  61.     # Finally, capture an image with a 6s exposure. Due
  62.     # to mode switching on the still port, this will take
  63.     # longer than 6 seconds
  64.             camera.capture('/opt/bewegung/dateien/dark.jpg')
  65.             camera.stop_preview()
  66.         bot.sendPhoto(-116762447, photo=open('dateien/dark.jpg', 'rb'), caption='Foto hochgeladen. Shutter: 6s | ISO: 800 | Resolution: 1920x1080')
  67.  
  68.     elif command == '/video 5':
  69.         with picamera.PiCamera() as camera:
  70.                 camera.resolution = (640, 480)
  71.                 camera.start_recording('dateien/video.h264')   
  72.                 camera.wait_recording(5)
  73.                 camera.stop_recording()
  74.                 os.system('avconv -y -i "dateien/video.h264" -c:v copy "dateien/video.mp4"')
  75.                 sleep(5)
  76.                 bot.sendVideo(-116762447, open('dateien/video.mp4', 'rb'), caption='Video hochgeladen. Resolution: 640x480 | Dauer 5s', duration='5')
  77.  
  78. bot = telepot.Bot('')
  79. bot.notifyOnMessage(handle)
  80. print 'I am listening ...'
  81.  
  82. while 1:
  83.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement