Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use argparser in generate_session.py #90

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/generate_session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import re
import os
import sys
def login(email, password):
import argparse


def email_type(value: str) -> str:
"""validator on email"""
email_pattern = re.compile(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")
if not email_pattern.match(value):
raise argparse.ArgumentTypeError(f"'{value}' is not a valid email")
return value


def login(email: str, password: str) -> str:
"""generate ChatGPT session_token by email and password"""
chatbot = Chatbot(
config={
"email": email,
Expand All @@ -18,12 +30,21 @@ def login(email, password):
)
return chatbot.config.get('session_token')


def gen_argparser() -> argparse.Namespace:
"""generate argparser"""
parser = argparse.ArgumentParser(description="generate ChatGPT seesion token")
parser.add_argument("email", type=email_type, help="email address of your ChatGPT account")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it compatible with the current command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

parser.add_argument("password", type=str, help="password of your ChatGPT account")
arguments = parser.parse_args()
return arguments


if __name__ == "__main__":
try:
from revChatGPT.revChatGPT import Chatbot
except:
raise RuntimeError("Could import revChatGPT. Please install it first.You can run `poetry install` to install it.")
print(sys.argv)
email = sys.argv[1]
password = sys.argv[2]
print(login(email, password))
raise RuntimeError("Could import revChatGPT. Please install it first. You can run `poetry install` to install it.")
args = gen_argparser()
print(args)
print(login(args.email, args.password))