Logging and fixing
This commit is contained in:
parent
a6f3773048
commit
d52db1c4c5
4 changed files with 14 additions and 19 deletions
|
|
@ -2,4 +2,4 @@ FROM python:latest
|
||||||
COPY . /etc/botyam
|
COPY . /etc/botyam
|
||||||
WORKDIR /etc/botyam
|
WORKDIR /etc/botyam
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
CMD ["python3", "./src/main.py"]
|
CMD ["python3", "-u ./src/main.py"]
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
import tweepy
|
import tweepy
|
||||||
import os
|
|
||||||
import syslog
|
|
||||||
import random
|
import random
|
||||||
import json
|
|
||||||
from connector import Connector
|
from connector import Connector
|
||||||
|
|
||||||
def init_streamobject(conn):
|
def init_streamobject(conn):
|
||||||
syslog.syslog(syslog.LOG_INFO, "Loading Stream object...")
|
print("Loading Stream object...")
|
||||||
return BotYamPoster(conn.get_bearer())
|
return BotYamPoster(conn.get_bearer())
|
||||||
|
|
||||||
def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
||||||
|
|
@ -21,7 +18,7 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
||||||
in_reply_to_tweet_id=tweet["id"]
|
in_reply_to_tweet_id=tweet["id"]
|
||||||
)
|
)
|
||||||
response_data = f"RESPONDING: {res.data['text']}"
|
response_data = f"RESPONDING: {res.data['text']}"
|
||||||
syslog.syslog(syslog.LOG_INFO, response_data)
|
print(response_data)
|
||||||
return (postcounter + 1)
|
return (postcounter + 1)
|
||||||
|
|
||||||
class BotYamPoster(tweepy.StreamingClient):
|
class BotYamPoster(tweepy.StreamingClient):
|
||||||
|
|
@ -40,15 +37,15 @@ class BotYamPoster(tweepy.StreamingClient):
|
||||||
return
|
return
|
||||||
|
|
||||||
conn = Connector()
|
conn = Connector()
|
||||||
reply_bank = json.loads(conn.dbconn.get_reply_bank())
|
reply_bank = conn.get_reply_bank()
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
tweet_data = f"NEW TWEET from @{conn.api.get_user(id=tweet.data['author_id']).data['username']}: {tweet.data['text']}"
|
tweet_data = f"NEW TWEET from @{conn.api.get_user(id=tweet.data['author_id']).data['username']}: {tweet.data['text']}"
|
||||||
syslog.syslog(syslog.LOG_INFO, tweet_data)
|
print(tweet_data)
|
||||||
|
|
||||||
# Spare me if starts with RT
|
# Spare me if starts with RT
|
||||||
if tweet.data['text'][:2] == "RT":
|
if tweet.data['text'][:2] == "RT":
|
||||||
syslog.syslog(syslog.LOG_INFO, "Skipping retweet...")
|
print("Skipping retweet...")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Run on all gags
|
# Run on all gags
|
||||||
|
|
@ -84,4 +81,4 @@ class BotYamPoster(tweepy.StreamingClient):
|
||||||
# Define a callback function to handle errors
|
# Define a callback function to handle errors
|
||||||
def on_error(self, status_code):
|
def on_error(self, status_code):
|
||||||
# Print the error code
|
# Print the error code
|
||||||
syslog.syslog(syslog.LOG_ERR, status_code)
|
print("ERROR: " + status_code)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
import os
|
import os
|
||||||
import syslog
|
|
||||||
import json
|
|
||||||
import redis
|
import redis
|
||||||
import tweepy
|
import tweepy
|
||||||
|
|
||||||
class Connector():
|
class Connector():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
syslog.syslog(syslog.LOG_INFO, "Loading Consul connector...")
|
print("Loading Redis connector...")
|
||||||
# TODO: Add token
|
# TODO: Add token
|
||||||
self.dbconn = redis.Redis(
|
self.dbconn = redis.Redis(
|
||||||
host=os.getenv("REDIS_HOST"),
|
host=os.getenv("REDIS_HOST"),
|
||||||
|
|
@ -15,10 +13,11 @@ class Connector():
|
||||||
)
|
)
|
||||||
|
|
||||||
self.api = Connector.init_api(self.dbconn)
|
self.api = Connector.init_api(self.dbconn)
|
||||||
|
print("Success loading connectors!")
|
||||||
|
|
||||||
def init_api(dbconn):
|
def init_api(dbconn):
|
||||||
# Syslog report
|
# Syslog report
|
||||||
syslog.syslog(syslog.LOG_INFO, "Loading Twitter API connector...")
|
print("Loading Twitter API connector...")
|
||||||
|
|
||||||
return tweepy.Client(
|
return tweepy.Client(
|
||||||
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
|
import sys
|
||||||
import tweepy
|
import tweepy
|
||||||
import os
|
|
||||||
import syslog
|
|
||||||
from BotYamPoster import BotYamPoster
|
from BotYamPoster import BotYamPoster
|
||||||
from BotYamPoster import init_streamobject
|
from BotYamPoster import init_streamobject
|
||||||
from connector import Connector
|
from connector import Connector
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
syslog.syslog(syslog.LOG_INFO, "BOT-YAM - VERSION 2.1.2 >>>>")
|
print("BOT-YAM - VERSION 2.1.2 >>>>")
|
||||||
conn = Connector()
|
conn = Connector()
|
||||||
stream = init_streamobject(conn)
|
stream = init_streamobject(conn)
|
||||||
syslog.syslog(syslog.LOG_INFO, "Adding stream rules...")
|
print("Adding stream rules...")
|
||||||
stream.add_rules(tweepy.StreamRule(conn.get_victims()['stream_filter']))
|
stream.add_rules(tweepy.StreamRule(conn.get_victims()['stream_filter']))
|
||||||
stream.add_rules(tweepy.StreamRule("@FromBotYam"))
|
stream.add_rules(tweepy.StreamRule("@FromBotYam"))
|
||||||
# Start listening for tweets
|
# Start listening for tweets
|
||||||
syslog.syslog(syslog.LOG_INFO, "Starting Twitter stream!")
|
print("Starting Twitter stream!")
|
||||||
stream.filter(expansions="author_id")
|
stream.filter(expansions="author_id")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue