forked from tdamdouni/Raspberry-Pi-DIY-Projects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConvert Tweet to Binary.py
97 lines (79 loc) · 2.66 KB
/
Convert Tweet to Binary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import time
import time
import sys, subprocess, urllib, time, tweepy
import binascii
from sense_hat import SenseHat
sense = SenseHat()
# == OAuth Authentication ==###############
#
# This mode of authentication is the new preferred way
# of authenticating with Twitter.
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key= 'xxxQ'
consumer_secret= 'xxxxxxxx'
# The access tokens can be found on your applications's Details
# page located at https://dev.twitter.com/apps (located
# under "Your access token")
access_token= 'xxxxxxxxxx'
access_token_secret= 'xxxxxxxxx'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
###Number one###
X = [0, 0, 0]
Y = [255, 255, 255]
number_one = [
X, X, X, Y, Y, X, X, X,
X, X, Y, Y, Y, X, X, X,
X, Y, Y, Y, Y, X, X, X,
X, X, X, Y, Y, X, X, X,
X, X, X, Y, Y, X, X, X,
X, X, X, Y, Y, X, X, X,
X, Y, Y, Y, Y, Y, Y, X,
X, Y, Y, Y, Y, Y, Y, X
]
sense.set_pixels(number_one)
###CODE TO GET TWITTER TO LISTEN FOR KEYWORD###
class My_Tweets(tweepy.StreamListener):
def on_status(self, tweet):
###ASCII Dictionary###
try:
print tweet.user.screen_name
print tweet.text
Tweet = str(tweet.text.lower())
print type(Tweet)
print ""
time.sleep(1)
"""Converts the letter to a Binary Value"""
word = bin(int(binascii.hexlify(Tweet), 16))
print word
'''Reads out the Binary Digit'''
for i in word:
if i == '1':
sense.set_pixels(number_one)
time.sleep(0.2)
sense.clear()
elif i == '0':
X = [0, 255, 0]
Y = [0, 0, 0]
number_zero = [
Y, X, X, X, X, X, X, Y,
Y, X, X, X, X, X, X, Y,
Y, X, X, Y, Y, X, X, Y,
Y, X, X, Y, Y, X, X, Y,
Y, X, X, Y, Y, X, X, Y,
Y, X, X, Y, Y, X, X, Y,
Y, X, X, X, X, X, X, Y,
Y, X, X, X, X, X, X, Y
]
sense.set_pixels(number_zero)
time.sleep(0.2)
sense.clear()
else:
print "Nil"
except:
print "Could not decode, probably had an emoji"
stream = tweepy.Stream(auth, My_Tweets())
while(True):
stream.userstream()