forked from TheJeme/hexbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (29 loc) · 1.23 KB
/
main.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
import tweepy
import redis
import time
import urllib.request
import os
auth = tweepy.OAuthHandler(os.environ["CONSUMER_TOKEN"], os.environ["CONSUMER_SECRET"]) # Place consumer_token and consumer_secret
auth.set_access_token(os.environ["ACCESS_TOKEN"], os.environ["ACCESS_TOKEN_SECRET"]) # Place access_token and access_token_secret
api = tweepy.API(auth)
r = redis.Redis(
host=os.environ["HOST"],
port=7839,
password=os.environ["PASSWORD"])
def main():
global color_number
while color_number < 16777216: # Till last possible hex number
hex_number = str(hex(color_number))[2:]
format_length = 6 - len(hex_number)
for i in range(format_length): #Adds 0 if needed
hex_number = "0" + hex_number
media_url = f"http://www.singlecolorimage.com/get/{hex_number}/500x500.png" # Path to image
urllib.request.urlretrieve(media_url, "temp_image.jpg")
api.update_with_media("temp_image.jpg", status="#" + hex_number)
print(media_url)
r.incr('num')
color_number = int(r.get("num"))
time.sleep(15 * 60) # Posts every 15 minutes
if __name__ == "__main__":
color_number = int(r.get("num"))
main()