Skip to content

Instantly share code, notes, and snippets.

@uktechreviews
Created August 2, 2017 07:33
Show Gist options
  • Save uktechreviews/b704cc0825f502bd14879b69bd4fd4ae to your computer and use it in GitHub Desktop.
Save uktechreviews/b704cc0825f502bd14879b69bd4fd4ae to your computer and use it in GitHub Desktop.
Spiderman twitter monitor
from twython import Twython, TwythonError
from blinkt import set_pixel, show
import blinkt
import time
import urllib2
APP_KEY = '' #Enter your twitter information here
APP_SECRET = ''
ACCESS_TOKEN= ''
blinkt.set_brightness(1)
blinkt.set_clear_on_exit(True)
blinkt.set_all(255,255,0)
blinkt.show()
time.sleep(2)
twitter = Twython(APP_KEY, access_token=ACCESS_TOKEN)
while True:
try:
search_results = twitter.search(q='', count=1) #Enter search term here
except TwythonError as e:
print e
for tweet in search_results['statuses']:
f = open('status', 'r')
last_tweet = f.read()
f.close()
print tweet['created_at']
print 'Tweet from @%s Date: %s' % (tweet['user']['screen_name'].encode('utf-8'),tweet['created_at'])
print tweet['text'].encode('utf-8'), '\n'
### Compare last saved tweet time stamp with latest tweet time stamp
if last_tweet == tweet['created_at']:
print("No new RT / Mention")
new_tweet=False
else:
print("New RT / Mention")
f = open('status', 'w')
f.write(tweet['created_at'])
f.close()
new_tweet=True
if new_tweet == True:
blinkt.set_all(0,255,0)
speed=3
else:
blinkt.set_all(255,0,0)
speed=1
blinkt.show()
wait=1
brightness = 1
while wait <11:
brightness -=0.1
blinkt.set_brightness(brightness)
wait +=1
blinkt.show()
time.sleep(speed)
@uktechreviews
Copy link
Author

You will need to add your own twitter API information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment