import RPi.GPIO as GPIO import picamera import os import time import random from twython import Twython, TwythonError from datetime import timedelta GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) #Red LED GPIO.setup(19, GPIO.OUT) #Yellow LED GPIO.setup(26, GPIO.OUT) #Setting these as variables will make them easier for future edits app_key = "[YOUR APP KEY]" app_secret = "[YOUR APP SECRET]" oauth_token = "[YOUR OAUTH TOKEN]" oauth_token_secret = "[YOUR OAUTH TOKEN SECRET]" # Return CPU temperature as a character string def getCPUtemperature(): res = os.popen('vcgencmd measure_temp').readline() return(res.replace("temp=","").replace("'C\n","")) # CPU informatiom CPU_temp = getCPUtemperature() GPIO.output(26, 1) print ("Data retrieved.......") time.sleep(2) GPIO.output(26, 0) # Get current uptime and format with open('/proc/uptime', 'r') as f: uptime_seconds = float(f.readline().split()[0]) uptime_string = str(timedelta(seconds = uptime_seconds)) print (("Uptime:") + (uptime_string)) print (("CPU Temp:") + (CPU_temp) + ("C")) camera = picamera.PiCamera() camera.capture('/var/www/twittercam.jpg') photo = open('/var/www/twittercam.jpg', 'rb') GPIO.output(19, 1) print ("Twitter Post in progress") time.sleep(2) #Prepare your twitter, you will need it for everything twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret) #The above should just be a single line, without the break #The obligatory first status update to test post= ("RPi Uptime: ")+ (uptime_string)+ (" ") + ("CPU Temp:") + (CPU_temp)+ ("C") + (" #WeatherPiStatus") print (post) image_ids = twitter.upload_media(media=photo) twitter.update_status(status=post, media_ids= image_ids['media_id']) print ("Operation Complete.....") time.sleep(2) GPIO.output(19, 0)