Bugfix + timestamp
This commit is contained in:
parent
ec1b9360e0
commit
158881ab9d
1 changed files with 21 additions and 17 deletions
|
|
@ -2,10 +2,11 @@ import tweepy
|
|||
import random
|
||||
import re
|
||||
import requests
|
||||
import time
|
||||
from connector import Connector
|
||||
|
||||
def init_streamobject(conn):
|
||||
print("Loading Stream object...")
|
||||
print(time.time() + ": " + "Loading Stream object...")
|
||||
return BotYamPoster(conn.get_bearer())
|
||||
|
||||
def expand_tco_url(url):
|
||||
|
|
@ -27,8 +28,11 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
|||
text=reply_text,
|
||||
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:
|
||||
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:
|
||||
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
|
||||
|
|
@ -38,11 +42,11 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
|||
)
|
||||
|
||||
response_data = f"RESPONDING: {res.data['text']}"
|
||||
print(response_data)
|
||||
print(time.time() + ": " + response_data)
|
||||
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:
|
||||
print("ERROR: An exception occured. The error: " + str(e))
|
||||
print(time.time() + ": " + "ERROR: An exception occured. The error: " + str(e))
|
||||
postcounter = postcounter + 1
|
||||
return postcounter
|
||||
|
||||
|
|
@ -65,11 +69,11 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
|
||||
# Debug
|
||||
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
|
||||
if tweet.data['text'][:2] == "RT":
|
||||
print("Skipping retweet...")
|
||||
print(time.time() + ": " + "Skipping retweet...")
|
||||
return
|
||||
|
||||
# Run on all gags
|
||||
|
|
@ -95,7 +99,7 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
postcounter)
|
||||
|
||||
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']):
|
||||
postcounter = post_reply(
|
||||
|
|
@ -118,4 +122,4 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
# Define a callback function to handle errors
|
||||
def on_error(self, status_code):
|
||||
# Print the error code
|
||||
print("ERROR: " + status_code)
|
||||
print(time.time() + ": " + "ERROR: " + status_code)
|
||||
|
|
|
|||
Loading…
Reference in a new issue