-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusk_twitter.py
79 lines (61 loc) · 2.48 KB
/
musk_twitter.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
'''
Script which turns Phillips Hue lights on and off
if @elonmusk tweets!
You need to create a Twitter Developer account to pass the authentication!
'''
from phue import Bridge
import time
from variables import BRIDGE_IP, API_KEY, API_KEY_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
import tweepy
def accessing_lights():
global b
b = Bridge(BRIDGE_IP)
light_names = b.get_light_objects('name')
return light_names
# Function that will turn lights on and off
def twitter_lights():
lights = accessing_lights() # Accesing Hue Bridge
for light in lights:
if b.get_light(light, 'on') == True:
lights_on = True # If light ON
for light in lights:
lights[light].on = False
time.sleep(5) # Change value depending on how long you want light to be off
for light in lights:
lights[light].on = True
lights[light].hue = 15000
lights[light].saturation = 100
elif b.get_light(light, 'on') == False: # If light OFF
lights_on = False
for light in lights:
lights[light].on = True
lights[light].hue = 15000
lights[light].saturation = 100
time.sleep(5) # Change value depending on how long you want light to be on
for light in lights:
lights[light].on = False
if lights_on == True:
api.update_status(status="@ElonMusk I'm a bot and you just turned my creators lights off :( Contact me!")
if lights_on == False:
api.update_status(status="@ElonMusk you just turned my lights on :) Contact me!")
# Authenticating Tweepy
auth = tweepy.OAuthHandler(API_KEY, API_KEY_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
first = True
while True:
if first == True:
tweet = api.user_timeline(user_id='44196397', count=1, exclude_replies=True, include_rts=False)
first = False
continue
previous_tweet = tweet
time.sleep(5) # Change frequency of when code checks Twitter for updates
# Loading in latest Tweets from @ElonMusk twitter page
tweet = api.user_timeline(user_id='44196397', count=1, exclude_replies=True, include_rts=False) # Elon Musk user_id, could also use screen_name = 'elonmusk'
if previous_tweet == tweet:
print('Same Tweet!')
continue
elif previous_tweet != tweet:
print('Not the same Tweet!')
twitter_lights()
continue