From 2f078f05a86cb1ccf162c416cc515688dcd7dd5c Mon Sep 17 00:00:00 2001 From: Jarrian Date: Sat, 23 Sep 2023 17:51:02 +0800 Subject: [PATCH] feat(auth): Authentication Directly in Terminal --- scraper/__main__.py | 46 ++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/scraper/__main__.py b/scraper/__main__.py index da10451..c54e322 100644 --- a/scraper/__main__.py +++ b/scraper/__main__.py @@ -17,29 +17,30 @@ except Exception as e: def main(): try: - try: - USER_UNAME = os.getenv("TWITTER_USERNAME") - USER_PASSWORD = os.getenv("TWITTER_PASSWORD") - except Exception as e: - print(f"Error retrieving environment variables: {e}") - USER_UNAME = None - USER_PASSWORD = None - sys.exit(1) - - if USER_UNAME is None: - USER_UNAME = input("Twitter Username: ") - - if USER_PASSWORD is None: - USER_PASSWORD = getpass.getpass("Enter Password: ") - - print() - parser = argparse.ArgumentParser( add_help=True, usage="python scraper [option] ... [arg] ...", description="Twitter Scraper is a tool that allows you to scrape tweets from twitter without using Twitter's API.", ) + try: + parser.add_argument( + "--user", + type=str, + default=os.getenv("TWITTER_USERNAME"), + help="Your Twitter username.", + ) + + parser.add_argument( + "--password", + type=str, + default=os.getenv("TWITTER_PASSWORD"), + help="Your Twitter password.", + ) + except Exception as e: + print(f"Error retrieving environment variables: {e}") + sys.exit(1) + parser.add_argument( "-t", "--tweets", @@ -86,6 +87,17 @@ def main(): args = parser.parse_args() + USER_UNAME = args.user + USER_PASSWORD = args.password + + if USER_UNAME is None: + USER_UNAME = input("Twitter Username: ") + + if USER_PASSWORD is None: + USER_PASSWORD = getpass.getpass("Enter Password: ") + + print() + tweet_type_args = [] if args.username is not None: