Skip to content

Instantly share code, notes, and snippets.

Created October 13, 2013 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/204f4bfe8ee5dec91eb1 to your computer and use it in GitHub Desktop.
Save anonymous/204f4bfe8ee5dec91eb1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import twitter
import time ## Import 'time' library. Allows us to use 'sleep'
#My app keys and secrets
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_SECRET = ''
FILTER_TAG = u'art' # Can also be just text, like u'idol', but expect a lot more results!
# We want a continuous stream of events which match a given tag, so we need to use the streaming API.
twitter_stream = twitter.TwitterStream(auth=twitter.OAuth(OAUTH_TOKEN,OAUTH_SECRET,CONSUMER_KEY,CONSUMER_SECRET))
# Now, we don't want every single tweet from the stream, so we'll filter to include only specific text, or a specific tag.
iterator = twitter_stream.statuses.filter(track = FILTER_TAG)
# Now, iterator is a generator which yields a new tweet whenever it sees one. We need to loop over it forever.
for tweet in iterator:
print (tweet.get(u'user', {}).get(u'name')), (tweet.get(u'text'))
print (tweet.get(u'user').get(u'location'))
if "hate" in tweet.get(u'text', u'fake_text_that_never_matches'): # Now, you need to light up the light for 5 seconds, then shut it off.
myfile = open('results.txt', 'a')
myfile.write(tweet.get(u'user').get(u'name').encode('ascii', 'ignore'))
myfile.write('\n')
myfile.write(tweet.get(u'text').encode('ascii', 'ignore'))
myfile.write('\n\n')
myfile.close()
from subprocess import call
photofile = "/dropbox-Uploader/dropbox_uploader.sh upload /Users/tristankirkpatrick/RaspberryPi/home/pi/results.txt"
call ([photofile], shell=True)
photofile = "/Users/tristankirkpatrick/RaspberryPi/Dropbox-Uploader/dropbox_uploader.sh upload /home/pi/photo00001.jpg"
call ([u'profile_image_url_https'], shell=True)
from subprocess import call
photofile = "/Users/tristankirkpatrick/RaspberryPi/Dropbox-Uploader/dropbox_uploader.sh upload /Users/tristankirkpatrick/RaspberryPi/home/pi/profilepics.txt"
call ([photofile], shell=True)
print ("Switch turned ON!")
print "----------------------------------------------------------------------------------------------------------------------------------------------------"
#Example tweet object below
"""
u'favorited': False,
u'contributors': None,
u'truncated': False,
u'text': u'New nail art. Simple but effective #nailart #nails #manicure #hand #mobile http://t.co/6nqhx2jlWc',
u'possibly_sensitive': False,
u'in_reply_to_status_id': None,
u'user': {
u'follow_request_sent': None,
u'profile_use_background_image': True,
u'default_profile_image': False,
u'id': 588466978,
u'verified': False,
u'profile_image_url_https': u'https://si0.twimg.com/profile_images/378800000279283526/0a0078d4a907846f1f218d8699f3162d_normal.jpeg',
u'profile_sidebar_fill_color': u'DDEEF6',
u'profile_text_color': u'333333',
u'followers_count': 248,
u'profile_sidebar_border_color': u'C0DEED',
u'id_str': u'588466978',
u'profile_background_color': u'C0DEED',
u'listed_count': 2,
u'profile_background_image_url_https': u'https://si0.twimg.com/profile_background_images/559841831/540590_3227081838031_1296102119_32368916_760747967_n.jpg',
u'utc_offset': None,
u'statuses_count': 4233,
u'description': u"Today is a good day to be a good day :D \r\nI'm 18, from Barcelona. :D *neon skulls* If you DARE TO DREAM never stop doing it. :D *5SOSfam*directioner*",
u'friends_count': 474,
u'location': u'Barcelona, Espa\xf1a',
u'profile_link_color': u'0084B4',
u'profile_image_url': u'http://a0.twimg.com/profile_images/378800000279283526/0a0078d4a907846f1f218d8699f3162d_normal.jpeg',
u'following': None,
u'geo_enabled': True,
u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/588466978/1367709089',
u'profile_background_image_url': u'http://a0.twimg.com/profile_background_images/559841831/540590_3227081838031_1296102119_32368916_760747967_n.jpg',
u'name': u'MiiRee Mochol\xed ',
u'lang': u'es',
u'profile_background_tile': True,
u'favourites_count': 20125,
u'screen_name': u'MiiReee3',
u'notifications': None,
u'url': u'http://squitx.tumblr.com',
u'created_at': u'Wed May 23 17:56:47 +0000 2012',
u'contributors_enabled': False,
u'time_zone': None,
u'protected': False,
u'default_profile': False,
u'is_translator': False
},
u'filter_level': u'medium',
u'geo': None,
u'id': 386836657619890176,
u'favorite_count': 0,
u'lang': u'en',
u'entities': {
u'symbols': [],
u'user_mentions': [],
u'hashtags': [
{
u'indices': [35, 43],
u'text': u'nailart'
},
{
u'indices': [44, 50],
u'text': u'nails'
},
],
u'urls': [{
u'url': u'http://t.co/6nqhx2jlWc',
u'indices': [75, 97],
u'expanded_url': u'http://instagram.com/p/fIGldtELjU/',
u'display_url': u'instagram.com/p/fIGldtELjU/'}]},
u'created_at': u'Sun Oct 06 12:53:40 +0000 2013',
u'retweeted': False,
u'coordinates': None,
u'in_reply_to_user_id_str': None,
u'source': u'<a href="http://instagram.com" rel="nofollow">Instagram</a>',
u'in_reply_to_status_id_str': None,
u'in_reply_to_screen_name': None,
u'id_str': u'386836657619890176',
u'place': None,
u'retweet_count': 0,
u'in_reply_to_user_id': None
}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment