-
Notifications
You must be signed in to change notification settings - Fork 0
/
llama.py
59 lines (46 loc) · 1.64 KB
/
llama.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
import json
import time
import twitter
import emoji
from emoji.unicode_codes.en import EMOJI_UNICODE_ENGLISH # to get all the emojis we can use
import random
def loadkeys() -> dict:
with open('keys.json', 'r') as infile:
keys = json.load(infile)
return {
'consumer_key': keys['apiKey'],
'consumer_secret': keys['apiSecretKey'],
'access_token_key': keys['accessToken'],
'access_token_secret': keys['accessTokenSecret'],
}
def load_llama() -> str:
with open('llama.txt', 'r') as infile:
return infile.read()
def load_emojis() -> list:
# returns all emojis that are able to be a length of 1
return [emoji.emojize(k) for k in EMOJI_UNICODE_ENGLISH.keys() if len(emoji.emojize(k)) == 1]
def post_llamas():
emojis = load_emojis()
llama = load_llama()
api = twitter.Api(**loadkeys())
# keep posting llamas until we have released all the llamas
while 0 < len(emojis):
selected_emoji = emojis.pop(random.randrange(0, len(emojis)))
status = api.PostUpdate(llama.replace('?', selected_emoji))
print(status.text)
# the llama should sleep before posting again
ONE_HOUR = 3600
ONE_DAY = ONE_HOUR * 24
time.sleep(random.randrange(ONE_HOUR, ONE_DAY))
print('enough llamas')
if __name__ == '__main__':
"""
api = twitter.Api(**loadkeys())
status = api.PostUpdate('I AM AN EMOJI LLAMA POSTING FROM THE CODE!!!!')
print(status.text)
"""
'''
for emoji_code in load_emojis():
print(f'{emoji_code} => {emoji.emojize(emoji_code)}\tlength: {len(emoji.emojize(emoji_code))}')
'''
post_llamas()