def upload_video(file_name, title, description='', keywords='rats', category='15', privacyStatus='unlisted', log=log): options = { 'file': file_name, 'title': title, 'description': description, 'keywords': keywords, 'category': category, 'privacyStatus': privacyStatus, } youtube = get_authenticated_service() try: yt_id = initialize_upload(youtube, options) rat.post_log("https://www.youtube.com/watch?v={0}".format(yt_id)) if yt_id: os.remove(file_name) return yt_id except HttpError, e: log("An HTTP error %d occurred:\n%s" % (e.resp.status, e.content))
import wiringpi2 as wiringpi import RPi.GPIO as GPIO import subprocess from server import sun import rat import time time.sleep(10) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) Pi_rev = wiringpi.piBoardRev() wiringpi.wiringPiSetupGpio() wiringpi.pinMode(18,2) rat.post_log("Light Control Started") last_status = None while True: settings = rat.get_settings() # only turn LEDs on if its getting dark, and recording enabled if settings: if sun.is_it_dark() and GPIO.input(24)==0 and int(settings['disable_recording'])==0: ir_led = float(settings['ir_led'])/100.0 if last_status!='night': rat.post_log("It's night. Set LEDs to: {0}%".format(ir_led)) last_status = 'night' wiringpi.pwmWrite(18, int(1024*ir_led)) elif GPIO.input(24)==0 and int(settings['disable_recording'])==0: ir_led = float(settings['ir_led_day'])/100.0
def log(msg): #print msg rat.post_log(msg)
'description': description, 'keywords': keywords, 'category': category, 'privacyStatus': privacyStatus, } youtube = get_authenticated_service() try: yt_id = initialize_upload(youtube, options) rat.post_log("https://www.youtube.com/watch?v={0}".format(yt_id)) if yt_id: os.remove(file_name) return yt_id except HttpError, e: log("An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)) if __name__ == '__main__': for i in xrange(0, 3): if len(sys.argv)>=2: try: log("try to upload {1} video, attemp: {0}".format(i, sys.argv[1])) upload_video(sys.argv[1],sys.argv[2]) except: rat.post_log(str(traceback.format_exc())) exit(0) else: try: get_authenticated_service() except: rat.post_log(str(traceback.format_exc())) exit(0) time.sleep(10)
import RPi.GPIO as GPIO import time import subprocess import sys import rat time.sleep(5) GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) RED_LED = True pressed = False rat.post_log("Shutdown Button Started") while True: if not pressed and GPIO.input(17)==0: pressed = time.time() elif pressed and GPIO.input(17)==0: #print "pressed for {0}".format(time.time()-pressed) counter = int((time.time()-pressed)*10) inv_counter = 50-counter if inv_counter>=10: if counter%(inv_counter/10) == 0: RED_LED = not RED_LED rat.set_red_led(RED_LED) elif inv_counter<10: RED_LED = True rat.set_red_led(RED_LED)
while True: time.sleep(60) watch = { 'light_control.py': False, 'shutdown_button.py': False, 'uploader.py': False, 'camera.py': False, } # http://stackoverflow.com/questions/2703640/process-list-on-linux-via-python pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] for pid in pids: try: process = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read() for w in watch.keys(): if w in process: watch[w] = True except IOError: # proc has already terminated continue for w in watch.keys(): if not watch[w]: try: m = "Process {0} not running. REBOOT!".format(w) print m rat.post_log(m) except: pass p = subprocess.Popen("reboot", shell=True)
format='h264', splitter_port=1, resize=None, profile='high', inline_headers=True, bitrate=17000000, intra_period = 1, quality=20) camera.start_recording('/dev/null', format='h264', motion_output=md, splitter_port=2, intra_period = 0, resize=(640, 480)) pt.start() rat.post_log("Camera Started") while True: try: (part1, part2, done) = RECORDED_VIDEOS_FIFO.get(False) if part1 and part2 and done: #executionString = "avconv -loglevel quiet -y -r {0} -i /tmp/{1}.h264 -vcodec copy -r 30 /tmp/{1}.mp4 && rm /tmp/{1}.h264".format(__FPS, videoIDlist.pop(0)) executionString = "avconv -loglevel panic -y -r {3} -i concat:/tmp/{0}\|/tmp/{1} -c copy -r {3} /tmp/_{2} && rm /tmp/{0} /tmp/{1} && mv /tmp/_{2} /tmp/{2}".format(part1, part2, done, FPS) #executionString = "avconv -loglevel quiet -y -r {3} -i concat:/tmp/{0}\|/tmp/{1} -c copy -r {3} /tmp/_{2}".format(part1, part2, done, FPS) log(executionString) subprocess.Popen(executionString, shell=True) except Queue.Empty: pass if GPIO.input(17)==0 or int(time.time())%120==0: rat.post_log("update camera settings") rat.set_green_led(True)