Twitter

English

During our time doing the project we thought it would be a great idea for us to create a twitter page for our robotic arm to keep people updated.  The main idea for us to do the robot we to get something to trigger the robot to move so we thought twitter would be the ideal thing to use because it’s so easy to use and millions are daily users. So our original idea was for someone too tweet #30PI and the arm would then move in the same sequence every tweet. But then we thought of a better idea to add a camera too the arm. But there is a twist with our twitter account, if anyone who is a twitter user hash tags ‘#SayRaspberry’, the camera will automatically take a picture if that hash tag is sent out by tweet, our program would search twitter for #SayRaspberry and then the camera would activate and take a photo instantly and upload it as a tweet. We originally used #30PI for testing purposes.

Follow us on Twitter @PiRobotic

Cymraeg

Yn ystod ein hamser yn gwneud y project yr roedden ni wedi meddwl byddaf yn syniad gwych i ni greu tudalen twitter ar gyfer yr fraich robotic i gweddaru pobl. Y prif syniad i ni oedd i wneud y robot oedd i gael rhywbeth i sbarduno'r robot i symyd, felly rydyn yn meddwl y byddai twitter yn y peth delfrydol iw defnyddion am ei fod more hawdd iw defnyddio and mae yna miliynau o defnyddwir pob dydd. Felly mae ein syniad gwreiddiol oedd i rywun yn anfon tweet #30PI a byddai'r fraich wedyn yn symyd yn yr un drefn bob tweet. On yna rydym yn meddwl am syniad gwell i ychwanegu camra hefyd i'r fraich. Ond mae yna twist gyda eub cyfrif twitter, os oed unrhyw un sy'n defnyddio'r hashtag #SayRaspberry, byddai ein rhaglen yn chwilio twitter ar gyfer #SayRaspberry a yna byddair camera activate a chymrud llun yn syth a llwytho fel tweet. Rydym yn wreiddiol a defnyddio #30PI am ddibenion profi.

Twitter Code/ Cod Twitter
#!/usr python
from twython import Twython
from picamera import PiCamera
from time import sleep
from datetime import datetime
from datetime import datetime
from twython import TwythonStreamer
import time
import RPi.GPIO as GPIO

# GPIO pin number of LED
LED = 22
# Twitter word search
TERMS = '**insert hashtag here**’

# setup GPIO as output
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED,GPIO.OUT)
GPIO.output(LED,GPIO.OUT)

#phils keys
#APP_KEY = '**insert app key here**'
#APP_SECRET = '**insert app key here**'
#OAUTH_TOKEN = ‘**insert app key here**’
#OAUTH_TOKEN_SECRET ='**insert app key here**'

#calums keys
APP_KEY = '**insert app key here**'
APP_SECRET = '**insert app key here**'
OAUTH_TOKEN = ‘**insert app key here**’
OAUTH_TOKEN_SECRET = '**insert app key here**'


# Twitter test camera coding
#with PiCamera() as camera:
#    camera.start_preview()
#    sleep(3)
#    camera.capture('/home/pi/downloads/image.jpg')
#   camera.stop_preview()

twitter = Twython(APP_KEY,APP_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET)


# Setup callbacks from Twython Streamer
class BlinkyStreamer(TwythonStreamer):
        def on_success(self,data):
                if 'text' in data:
                        print data['text'].encode('utf-8')
                        print
                        GPIO.output(LED, GPIO.HIGH)
                        time.sleep(10.0)
                        GPIO.output(LED, GPIO.LOW)
                        with PiCamera() as camera:

                                camera.start_preview()
                                timestamp = datetime.now().isoformat()
                                photo_path = '/home/pi/downloads/photos/%s.jpg' % timestamp
                                sleep(6)
                                camera.capture(photo_path)
                                camera.stop_preview()
                                message = 'Hi,Camera retweeted image today at '
                                with open(photo_path, 'rb') as photo:
                                        twitter.update_status_with_media(status=message+timestamp, media=photo)

# create streamer
try:
        stream=BlinkyStreamer( APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
        stream.statuses.filter(track=TERMS)
except KeyboardInterrupt:
        GPIO.cleanup()




#twitter = Twython(APP_KEY,APP_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET)
#twitter.update_status(status = 'Picture taken with picamera')

# message = 'Hi, 2nd picture picamera'

#with open('/home/pi/downloads/image.jpg', 'rb') as photo:
#    twitter.update_status_with_media(status=message, media=photo)
    

No comments:

Post a Comment