#!/usr/bin/python
import tweepy
import glob
import random
import os

folder_path = '/Users/ashish/Documents/MotionDetector/'
log_file = folder_path + 'upload_twitter.log'
# Consumer keys and access tokens, used for OAuth
consumer_key = 'your_twitter_consumer_key'
consumer_secret = 'your_twitter_consumer_secret'
access_token = 'your_twitter_access_token'
access_token_secret = 'your_twitter_access_token_secret'

# 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)

# List of png files in current directory
files = glob.glob(folder_path + '*.png')

# List of files that have already been uploaded
if os.path.exists(log_file):
    uploaded_files = open(log_file).read()
else:
    f = file(log_file, 'w')
    uploaded_files = ''

log = open(log_file, 'a')

# List of status messages for twitter
messages = ['Another victim!', 'Sprayed!', 'Gotcha!']

for f in files:
      if f not in uploaded_files:
          # Add file to log
          log.write(f)
          log.write('\n')

          # Upload to twitter
          msg = messages[random.randint(0,len(messages)-1)]
          api.update_with_media(f,msg)
