-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
43 lines (38 loc) · 1.11 KB
/
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
#!/usr/bin/python
import tweepy
import markovify
import sys
import threading
import os
import datetime
from keys import keys
from autoresponder import AutoResponder
def init_twitter():
consumer_key = keys['consumer_key']
consumer_secret = keys['consumer_secret']
access_token = keys['access_token']
access_token_secret = keys['access_token_secret']
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
return tweepy.API(auth)
def init_model():
filename = "tweetdb"
dbfile = open("/usr/local/autoresponder/tweetdb")
db = dbfile.read()
model = markovify.NewlineText(db)
return model
def main():
print "Starting bot"
api = init_twitter()
model = init_model()
accountname = keys['accountname']
print "loaded settings"
bot = AutoResponder(model,api, False, "/usr/local/autoresponder/imagedb", accountname)
print "loaded bot"
bot.respond_to_tweet()
now = datetime.datetime.now()
if now.hour % 2 == 0:
bot.new_tweet()
bot.save_responses()
if __name__ == "__main__":
main()