Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/prinewgirl/bot-followers
Browse files Browse the repository at this point in the history
…into prinewgirl-master
  • Loading branch information
cuducos committed Mar 13, 2020
2 parents 13b514a + 6bb5e07 commit 32c5c30
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions bot_followers/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from time import sleep

import click
from tweepy.error import RateLimitError

from bot_followers import BotFollowers

import traceback
from os import environ
from sys import exit

try:
environ["TWITTER_CONSUMER_KEY"]
environ["TWITTER_CONSUMER_SECRET"]
environ["TWITTER_ACCESS_TOKEN_KEY"]
environ["TWITTER_ACCESS_TOKEN_SECRET"]
environ["BOTOMETER_MASHAPE_KEY"]

except KeyError:
print("Environment variable(s) not found")
print("Please set it using .env file or env VAR=VALUE")
exit()


@click.group()
@click.argument("account")
@click.pass_context
def cli(ctx, account):
"""Bot Follower is a tiny app to check whether followers of a given Twitter
account are bots."""
ctx.obj = {"app": BotFollowers(account)}


@cli.command()
@click.pass_context
def analyze(ctx):
"""Run the app to collect & analyze data."""
while True:
try:
ctx.obj.get("app")()
except RateLimitError:
click.echo("Due to the Twitter API rate limit, let's take a break…")
sleep(60 * 5)
pass
else:
break


@cli.command()
@click.pass_context
def report(ctx):
"""Print a simple report of stored results."""
ctx.obj.get("app").report()


if __name__ == "__main__":
cli()

0 comments on commit 32c5c30

Please sign in to comment.