feat(auth): Authentication Directly in Terminal

This commit is contained in:
Jarrian
2023-09-23 17:51:02 +08:00
parent 33dc3403d3
commit 2f078f05a8

View File

@@ -17,29 +17,30 @@ except Exception as e:
def main(): def main():
try: 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( parser = argparse.ArgumentParser(
add_help=True, add_help=True,
usage="python scraper [option] ... [arg] ...", usage="python scraper [option] ... [arg] ...",
description="Twitter Scraper is a tool that allows you to scrape tweets from twitter without using Twitter's API.", 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( parser.add_argument(
"-t", "-t",
"--tweets", "--tweets",
@@ -86,6 +87,17 @@ def main():
args = parser.parse_args() 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 = [] tweet_type_args = []
if args.username is not None: if args.username is not None: