-
Notifications
You must be signed in to change notification settings - Fork 46
/
tumblr_bot.py
70 lines (59 loc) · 1.82 KB
/
tumblr_bot.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
import random
import os
import ConfigParser
import time
import subprocess
from tumblpy import Tumblpy
from make_gifs import make_gif, check_config
config = ConfigParser.ConfigParser()
config.read("config.cfg")
config.sections()
slugs = check_config("config.cfg")[3]
CONSUMER_KEY = config.get("tumblr", "consumer_key")
CONSUMER_SECRET = config.get("tumblr", "consumer_secret")
OAUTH_TOKEN = config.get("tumblr", "oauth_token")
OAUTH_TOKEN_SECRET = config.get("tumblr", "oauth_token_secret")
t = Tumblpy(
CONSUMER_KEY,
CONSUMER_SECRET,
OAUTH_TOKEN,
OAUTH_TOKEN_SECRET,
)
while True:
# you can set many more options, check the make_gif-function
quote = make_gif(random.choice(slugs), frames=20)
quote = ' '.join(quote)
# reduce amount of colors, because tumblr sucks
subprocess.call(['convert',
'star_wars.gif',
'-layers',
'optimize',
'-colors',
'64',
'-loop',
'0',
'star_wars.gif'])
while(os.path.getsize('star_wars.gif') > 1048576):
subprocess.call(['convert',
'star_wars.gif',
'-resize',
'90%',
'-coalesce',
'-layers',
'optimize',
'-loop',
'0',
'star_wars.gif'])
photo = open('star_wars.gif', 'rb')
post = t.post(
'post',
blog_url='http://starwarsgifsasaservice.tumblr.com',
params={
'type': 'photo',
'caption': quote,
'data': photo,
'tags': 'star wars, gif'}
)
print("sleeping...")
# sleep 12 hours
time.sleep(43200)