Ahoy
I am trying to set up a twitter birdbox camera. I currently have 3 scripts, everything functions okay apart from if birdhousereply.py is running birdhousehourly.py won’t work, I guess this is a limitation with the camera and python. is there a way i can combine birdhousereply.py and birdhousehourly.py so i can tweet every hour and reply to incoming tweets? i have taken the code from the tweeting babbage tutorial on the raspberry pi site,
auth.py (censored my actual twitter keys)
consumer_key = '123456789'
consumer_secret = '123456789'
access_token = '123456789'
access_token_secret = '123456789'
birdhousereply.py (scans twitter for a mention and sends a reply with a picture)
from twython import Twython
from twython import TwythonStreamer
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.resolution = (1920, 1080)
camera.rotation = 180
from auth import (
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
class MyStreamer(TwythonStreamer):
def on_success(self, data):
if 'text' in data:
username = data['user']['screen_name']
tweet = data['text']
twitter_id = data['id_str']
print("@%s: %s: %s" % (username, tweet, twitter_id))
sleep(5)
camera.capture('/home/pi/reply.jpg')
sleep(1)
message = "@%s here is your picture" % (username)
with open('/home/pi/reply.jpg', 'rb') as photo:
twitter.update_status_with_media(status=message, in_reply_to_status_id=twitter_id, media=photo)
print("Tweeted: %s" % message)
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
stream = MyStreamer(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
stream.statuses.filter(track='@pibirdhouse')
birdhousehourly.py (run as an hourly crontab job, takes a picture and tweets it with a random message)
from twython import Twython
from twython import TwythonStreamer
from picamera import PiCamera
from time import sleep
import random
camera = PiCamera()
camera.resolution = (1920, 1080)
camera.rotation = 180
from auth import (
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
messages = [
"Hello world",
"Hi there",
"My name is Babbage",
"What's up?",
"How's it going?",
"Have you been here before?",
"Get a hair cut!",
]
message = random.choice(messages)
sleep(3)
camera.capture('/home/pi/reply.jpg')
sleep(1)
with open('/home/pi/reply.jpg', 'rb') as photo:
twitter.update_status_with_media(status=message, media=photo)
print("Tweeted: %s" % message)