#!/usr/bin/python from TwitterAPI import TwitterAPI import datetime, time import os, sys, subprocess #import random CONSUMER_KEY = 'XXXXXXXXXXXXXXXXXXXXXX' CONSUMER_SECRET = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' ACCESS_TOKEN_KEY = 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ' ACCESS_TOKEN_SECRET = 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV' interval = 300 # 300s = 5m #interval = 6 counter = 11 # how many per hour counterstart = counter #eggs = "/home/gartim/pics/easter_egg/" #eggpics = os.listdir( eggs ) #picount = len(eggpics) api = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET) # testing - r = api.request('search/tweets', {'q':'pizza'}) # testing - print r.status_code while ( 1 ): # ran_num = random.randrange(0,11) DATETIME=datetime.datetime.now().strftime("%Y_%m_%d-%X") #print "counter: %s ran_num: %i DateTime: %s" % (counter, ran_num, DATETIME) print "counter: %s DateTime: %s" % (counter, DATETIME) #if ran_num == counter: # if ran_num > 9: ran_num = ran_num - 2 # filename = "/home/gartim/pics/easter_egg/" + eggpics[ran_num] # print('Got an EasterEGG!') #else: # create image filename= "/home/pi/pics/academy_" + DATETIME + ".jpg" subprocess.call(["./step_moto.sh"," /dev/ttyACM0", "0"]) subprocess.call(["raspistill","-n", "-o", filename, "-w", "1040", "-h","680"]) photo = open(filename, 'rb') data = photo.read() r = api.request('media/upload', None, {'media': data}) print('Upload media successful' if r.status_code == 200 else 'UPLOAD MEDIA FAILURE') # STEP 2 - post tweet with reference to uploaded image if r.status_code == 200: media_id = r.json()['media_id'] r = api.request('statuses/update', {'status':'photowatch: 2016_Academys', 'media_ids':media_id}) print('Update status successful' if r.status_code == 200 else 'UPDATE STATUS FAILURE') counter = counter - 1 if counter < 0: counter = counterstart time.sleep( interval )