forked from joshuag/speakerbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speaker_twitter.py
65 lines (46 loc) · 1.72 KB
/
speaker_twitter.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
from random import randrange
from time import sleep
from config import config
from speaker_db import SpeakerDB
from Speakerbot import Speakerbot
from twython import Twython
from twython.exceptions import TwythonError
class SpeakerTwitter(object):
def __init__(self, speakerbot=None):
self.db = SpeakerDB()
self.theme_songs = {}
self.speakerbot = speakerbot
self.config = config["twitter"]
self.twitter = Twython(
self.config["app_key"],
self.config["app_secret"],
self.config["oauth_token"],
self.config["oauth_token_secret"])
def publish_from_queue(self):
forbidden_words = ["nohodo", "vk", "vertical knowledge"]
try:
tweet_record = self.db.execute("select id, tweet_text from publish_queue limit 1").next()
except StopIteration:
tweet_record = False
if tweet_record:
tweet_text = unicode(tweet_record["tweet_text"])
tweet_id = tweet_record["id"]
tweet_this = True
for word in forbidden_words:
if word in tweet_text.lower():
tweet_this = False
if tweet_this:
try:
self.twitter.update_status(status=tweet_text)
except TwythonError as e:
print str(e)
print "---------"
print tweet_text
pass
self.db.execute("delete from publish_queue where id=?", [tweet_id])
if __name__ == "__main__":
sb = Speakerbot()
st = SpeakerTwitter(speakerbot=sb)
while True:
st.publish_from_queue()
sleep(180)