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
|
||||
WORKDIR /etc/botyam
|
||||
RUN pip install -r requirements.txt
|
||||
CMD ["python3", "./src/main.py"]
|
||||
CMD ["python3", "-u ./src/main.py"]
|
||||
|
|
@ -1,12 +1,9 @@
|
|||
import tweepy
|
||||
import os
|
||||
import syslog
|
||||
import random
|
||||
import json
|
||||
from connector import Connector
|
||||
|
||||
def init_streamobject(conn):
|
||||
syslog.syslog(syslog.LOG_INFO, "Loading Stream object...")
|
||||
print("Loading Stream object...")
|
||||
return BotYamPoster(conn.get_bearer())
|
||||
|
||||
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"]
|
||||
)
|
||||
response_data = f"RESPONDING: {res.data['text']}"
|
||||
syslog.syslog(syslog.LOG_INFO, response_data)
|
||||
print(response_data)
|
||||
return (postcounter + 1)
|
||||
|
||||
class BotYamPoster(tweepy.StreamingClient):
|
||||
|
|
@ -40,15 +37,15 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
return
|
||||
|
||||
conn = Connector()
|
||||
reply_bank = json.loads(conn.dbconn.get_reply_bank())
|
||||
reply_bank = conn.get_reply_bank()
|
||||
|
||||
# Debug
|
||||
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
|
||||
if tweet.data['text'][:2] == "RT":
|
||||
syslog.syslog(syslog.LOG_INFO, "Skipping retweet...")
|
||||
print("Skipping retweet...")
|
||||
return
|
||||
|
||||
# Run on all gags
|
||||
|
|
@ -84,4 +81,4 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
# Define a callback function to handle errors
|
||||
def on_error(self, status_code):
|
||||
# Print the error code
|
||||
syslog.syslog(syslog.LOG_ERR, status_code)
|
||||
print("ERROR: " + status_code)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import os
|
||||
import syslog
|
||||
import json
|
||||
import redis
|
||||
import tweepy
|
||||
|
||||
class Connector():
|
||||
def __init__(self):
|
||||
syslog.syslog(syslog.LOG_INFO, "Loading Consul connector...")
|
||||
print("Loading Redis connector...")
|
||||
# TODO: Add token
|
||||
self.dbconn = redis.Redis(
|
||||
host=os.getenv("REDIS_HOST"),
|
||||
|
|
@ -15,10 +13,11 @@ class Connector():
|
|||
)
|
||||
|
||||
self.api = Connector.init_api(self.dbconn)
|
||||
print("Success loading connectors!")
|
||||
|
||||
def init_api(dbconn):
|
||||
# Syslog report
|
||||
syslog.syslog(syslog.LOG_INFO, "Loading Twitter API connector...")
|
||||
print("Loading Twitter API connector...")
|
||||
|
||||
return tweepy.Client(
|
||||
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
import sys
|
||||
import tweepy
|
||||
import os
|
||||
import syslog
|
||||
from BotYamPoster import BotYamPoster
|
||||
from BotYamPoster import init_streamobject
|
||||
from connector import Connector
|
||||
|
||||
def main():
|
||||
syslog.syslog(syslog.LOG_INFO, "BOT-YAM - VERSION 2.1.2 >>>>")
|
||||
print("BOT-YAM - VERSION 2.1.2 >>>>")
|
||||
conn = Connector()
|
||||
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("@FromBotYam"))
|
||||
# Start listening for tweets
|
||||
syslog.syslog(syslog.LOG_INFO, "Starting Twitter stream!")
|
||||
print("Starting Twitter stream!")
|
||||
stream.filter(expansions="author_id")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue