-
Notifications
You must be signed in to change notification settings - Fork 1
/
piIntegration.py
57 lines (49 loc) · 1.85 KB
/
piIntegration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import requests
import time
from datetime import datetime
import math
import tweepy
import os
try:
import picamera
camera = picamera.PiCamera()
camera.resolution =(1920,7080)
except:
print "PiCamera not found"
''' Take an image and save it with whatever name you would like, this is not required. Time interval decides how long the shutter stays open for '''
def captureImage(intitialName,finalName,timeInterval):
camera.capture(intitialName+'.jpg')
time.sleep(timeInterval)
finalName(intitialName+'.jpg',finalName)
'''Consumer Keys and Access tokens for Twitter '''
consumer_key = configValues.Akeys['cKey']
consumer_secret = configValues.Akeys['cSec']
access_token = configValues.Atoken['atoken']
access_token_secret = configValues.Atoken['aSec']
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# Creation of the actual interface, using authentication
api = tweepy.API(auth)
def Tweet():
status = "Test for twitter updates on #chennai floods at #rhok @rhok_bang"
fn = os.path.abspath('image_stream.jpg')
api.update_with_media(fn,status=status)
print "tweet sent"
def restart():
command ="/usr/bin/sudo /sbin/reboot"
import subprocess
process = subprocess.Popen(coommand.split(),stdout=subprocess.PIPE)
output = process.communicate()[0]
print "reboot"
before_tweet = datetime.strptime(datetime.strftime(datetime.now(),'%H:%M:%S'),'%H:%M:%S')
before_reboot = datetime.strptime(datetime.strftime(datetime.now(),'%H:%M:%S'),'%H:%M:%S')
while True:
try:
captureImage("Rishi","image_stream",60)
after = datetime.strptime(datetime.strftime(datetime.now(),'%H:%M:%S'),'%H:%M:%S')
if (((after-before_tweet).seconds)/3600)==6:
before_tweet = datetime.strptime(datetime.strftime(datetime.now(),'%H:%M:%S'),'%H:%M:%S')
Tweet()
except Exception,e:
restart()