Bugfix + timestamp

This commit is contained in:
Lucy Joshua 2023-03-22 14:33:43 +02:00 committed by GitHub
parent ec1b9360e0
commit 158881ab9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,10 +2,11 @@ import tweepy
import random import random
import re import re
import requests import requests
import time
from connector import Connector from connector import Connector
def init_streamobject(conn): def init_streamobject(conn):
print("Loading Stream object...") print(time.time() + ": " + "Loading Stream object...")
return BotYamPoster(conn.get_bearer()) return BotYamPoster(conn.get_bearer())
def expand_tco_url(url): def expand_tco_url(url):
@ -27,8 +28,11 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
text=reply_text, text=reply_text,
in_reply_to_tweet_id=tweet["id"] in_reply_to_tweet_id=tweet["id"]
) )
response_data = f"RESPONDING: {res.data['text']}"
print(time.time() + ": " + response_data)
except tweepy.errors.TwitterServerError as e: except tweepy.errors.TwitterServerError as e:
print("ERROR: An error occured, we'll try again in a few minutes. The error: " + str(e)) print(time.time() + ": " + "ERROR: An error occured, we'll try again in a few minutes. The error: " + str(e))
time.sleep(5)
try: try:
if tweet.data['author_id'] in victim_bank['author_id'] and not "@FromBotYam" in tweet.data['text']: if tweet.data['author_id'] in victim_bank['author_id'] and not "@FromBotYam" in tweet.data['text']:
reply_text = victim_bank['reply'][random.randint(0,2)] + "\nו" + reply_text reply_text = victim_bank['reply'][random.randint(0,2)] + "\nו" + reply_text
@ -38,11 +42,11 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
) )
response_data = f"RESPONDING: {res.data['text']}" response_data = f"RESPONDING: {res.data['text']}"
print(response_data) print(time.time() + ": " + response_data)
except Exception as e: except Exception as e:
print("ERROR: An exception occured. The error: " + str(e)) print(time.time() + ": " + "ERROR: An exception occured. The error: " + str(e))
except Exception as e: except Exception as e:
print("ERROR: An exception occured. The error: " + str(e)) print(time.time() + ": " + "ERROR: An exception occured. The error: " + str(e))
postcounter = postcounter + 1 postcounter = postcounter + 1
return postcounter return postcounter
@ -65,11 +69,11 @@ class BotYamPoster(tweepy.StreamingClient):
# 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']}"
print(tweet_data) print(time.time() + ": " + 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":
print("Skipping retweet...") print(time.time() + ": " + "Skipping retweet...")
return return
# Run on all gags # Run on all gags
@ -95,7 +99,7 @@ class BotYamPoster(tweepy.StreamingClient):
postcounter) postcounter)
if (postcounter == 0 and "@FromBotYam" in tweet.data['text']): if (postcounter == 0 and "@FromBotYam" in tweet.data['text']):
print("Post counter for this tweet: 0! Posting tilt.") print(time.time() + ": " + "Post counter for this tweet: 0! Posting tilt.")
if any(tilter in tweet.data['text'] for tilter in reply_bank['special_gags']['tilt']['keywords']): if any(tilter in tweet.data['text'] for tilter in reply_bank['special_gags']['tilt']['keywords']):
postcounter = post_reply( postcounter = post_reply(
@ -118,4 +122,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
print("ERROR: " + status_code) print(time.time() + ": " + "ERROR: " + status_code)