Skip to content

Instantly share code, notes, and snippets.

@acoster
Created December 20, 2022 16:19
Show Gist options
  • Save acoster/7075cb132c317670d4ceee6416310b78 to your computer and use it in GitHub Desktop.
Save acoster/7075cb132c317670d4ceee6416310b78 to your computer and use it in GitHub Desktop.
import pytwitter
import time
import os
import sys
import schedule
from schedule import every, repeat, run_pending
twitter_conn = None
@repeat(every(15).seconds)
def detect_ban():
global twitter_conn
account_name = os.getenv('WATCHED_USER')
try:
twitter_conn.get_user(username=account_name)
except pytwitter.error.PyTwitterError as err:
print("%s: %s has been banned" % (time.asctime(), account_name))
sys.exit(0)
if __name__ == '__main__':
twitter_conn = pytwitter.Api(os.getenv('TWITTER_TOKEN'))
while True:
run_pending()
time.sleep(schedule.idle_seconds())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment