-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (51 loc) · 1.76 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
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
# Bot that generates Danny Phantom lines based on the show's transcript
# Gets smarter with each run (runs a pass-through with each run
from textgenrnn import textgenrnn
import oauth2
from urllib import parse
import pytumblr
import sys
import io
CHARACTER = 'Danny Fenton'
REQUEST_TOKEN_URL = 'http://www.tumblr.com/oauth/request_token'
AUTHORIZATION_URL = 'http://www.tumblr.com/oauth/authorize'
ACCESS_TOKEN_URL = 'http://www.tumblr.com/oauth/access_token'
CONSUMER_KEY = 'x'
CONSUMER_SECRET = 'x'
OAUTH_TOKEN = 'x'
OAUTH_SECRET = 'x'
BLOG_NAME = 'dannyphantombot'
TAGS = ['danny phantom', 'AI-generated quote', 'machine learning', 'danny fenton']
def setup_model():
textgen = textgenrnn(CHARACTER + '_weights.hdf5')
textgen.train_from_file(CHARACTER + '.txt', num_epochs=1)
return textgen
def generate_quote(textgen):
generated_quote = 'did not work'
old_stdout = sys.stdout
new_stdout = io.StringIO()
sys.stdout = new_stdout
textgen.generate(temperature=0.3)
generated_quote = new_stdout.getvalue()
sys.stdout = old_stdout
print(generated_quote.split('\n')[0])
return generated_quote.split('\n')[0]
def post_quote(generated_quote):
client = pytumblr.TumblrRestClient(
CONSUMER_KEY,
CONSUMER_SECRET,
OAUTH_TOKEN,
OAUTH_SECRET,
)
# Creating a text post
client.create_text(BLOG_NAME, state="queue", body=generated_quote, tags=TAGS)
def setup():
textgen = setup_model()
for x in range(30):
generated_quote = generate_quote(textgen)
post_quote(generated_quote)
print('Posts successfully queued')
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
setup()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/