Using the Raspberry Pi and a web cam to tweet images

 

 

 

 

 

 

 

 

I managed to get code to work to tweet from the Pi we followed exactly this strategy

The code below

Notes and how to run it (first to tweet from the Pi)

To run

python feyn_tweet.py ‘hello from Aditya’

1) feyn_tweet.py is our program

2) ‘hello from Aditya’ is our tweet

3) Our tweets below(we can tag people)

4) XXXX is twitter keys for you (see the link above for it)

5) Uses a library called [Twython which is on github](https://twython.readthedocs.org/en/latest/)

Our tweets

_@leeomar @tonyfish – tweeting from the RPi very cool!_

_hello @leeomar from Rpi_

_hello from Aditya_

_https://twitter.com/feynlabs_

code below

#!/usr/bin/env python
import sys
from twython import Twython
CONSUMER_KEY = ‘XXXXX’
CONSUMER_SECRET = ‘XXXXX’
ACCESS_KEY = ‘XXXXX’
ACCESS_SECRET = ‘XXXXX’
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
api.update_status(status=sys.argv[1])

Now, the code for the webcam ..
This takes a picture and tweets it
our webcam tweet from the Raspberry Pi  HERE 

To run ..
**python feyn_tweet_camera.py (where feyn_tweet_camera.py is our file which we made into an executable)**

#!/usr/bin/env python
import sys
import os
import pygame
import pygame.camera
from pygame.locals import *

from twython import Twython
CONSUMER_KEY = ‘XXXXX’
CONSUMER_SECRET = ‘XXXXX’
ACCESS_KEY = ‘XXXXX’
ACCESS_SECRET = ‘XXXXX’
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
pygame.init()
pygame.camera.init()
cam = pygame.camera.Camera(“/dev/video0″,(640,480))
cam.start()
image = cam.get_image()
pygame.image.save(image,’webcam.jpg’)
photo = open(‘webcam.jpg’,'rb’)
api.update_status_with_media(media=photo, status=’My RPi be tweeting images now => ‘)