Skip to content

Commit

Permalink
fixed login
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu1845 committed Jan 13, 2022
1 parent 4f4c693 commit c4f10eb
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions twspace_dl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from twspace_dl.login import Login, load_from_file, write_to_file


def get_args() -> argparse.Namespace:
def main() -> None:
parser = argparse.ArgumentParser(
description="Script designed to help download twitter spaces"
)
subparsers = parser.add_subparsers(
help="(EXPERIMENTAL) Login to your account using username and password"
help="(EXPERIMENTAL) Login to your account using username and password",
)
login_parser = subparsers.add_parser("login", description="EXPERIMENTAL")
input_group = parser.add_argument_group("input")
Expand All @@ -27,11 +27,20 @@ def get_args() -> argparse.Namespace:
parser.add_argument("-k", "--keep-files", action="store_true")
parser.add_argument("--input-cookie-file", type=str, metavar="COOKIE_FILE")

login_parser.add_argument("-u", "--username", type=str, metavar="USERNAME")
login_parser.add_argument("-p", "--password", type=str, metavar="PASSWORD")
login_parser.add_argument(
"-o", "--output-cookie-file", type=str, metavar="OUTPUT_COOKIE_FILE"
"-u", "--username", type=str, metavar="USERNAME", default=None
)
login_parser.add_argument(
"-p", "--password", type=str, metavar="PASSWORD", default=None
)
login_parser.add_argument(
"-o",
"--output-cookie-file",
type=str,
metavar="OUTPUT_COOKIE_FILE",
default=None,
)
login_parser.set_defaults(func=login)

input_method.add_argument("-i", "--input-url", type=str, metavar="SPACE_URL")
input_method.add_argument("-U", "--user-url", type=str, metavar="USER_URL")
Expand Down Expand Up @@ -99,22 +108,15 @@ def get_args() -> argparse.Namespace:
output_group.add_argument(
"--write-url", type=str, metavar="URL_OUTPUT", help="write master url to file"
)
parser.set_defaults(func=twspace)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
return args
args.func(args)


def main() -> None:
args = get_args()
has_input = (
args.input_url
or args.input_metadata
or args.user_url
or args.from_master_url
or args.from_dynamic_url
)
def login(args: argparse.Namespace) -> None:
has_partial_login = (
args.username or args.password or args.output_cookie_file # has at least one
) and not (
Expand All @@ -125,19 +127,27 @@ def main() -> None:
print("login needs both username, password, and output file")
sys.exit(2)

if not has_input and not (
args.username or args.password or args.output_cookie_file
):
print("Either space url, user url or master url should be provided")
sys.exit(2)

logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

if args.username and args.password and args.output_cookie_file:
login = Login(args.username, args.password, TwspaceDL.guest_token())
auth_token = login.login()
write_to_file(auth_token, args.output_cookie_file)


def twspace(args: argparse.Namespace) -> None:
has_input = (
args.input_url
or args.input_metadata
or args.user_url
or args.from_master_url
or args.from_dynamic_url
)

if not has_input:
print("Either space url, user url or master url should be provided")
sys.exit(2)

logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

if args.input_url:
twspace_dl = TwspaceDL.from_space_url(args.input_url, args.output)
elif args.user_url:
Expand Down

0 comments on commit c4f10eb

Please sign in to comment.