You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wikiteam/wikiteam3/utils/login/__init__.py

49 lines
1.4 KiB
Python

""" Provide login functions """
import time
import requests
from wikiteam3.utils.login.api import botLogin, clientLogin, fetchLoginToken
from wikiteam3.utils.login.index import indexLogin
def uniLogin(
api: str = "",
index: str = "",
session: requests.Session = requests.Session(),
username: str = "",
password: str = "",
):
"""Try to login to a wiki using various methods.\n
Return `session` if success, else return `None`.\n
Try: `cilent login (api) => bot login (api) => index login (index)`"""
if (not api and not index) or (not username or not password):
print("uniLogin: api or index or username or password is empty")
return None
if api:
print("Trying to log in to the wiki using clientLogin... (MW 1.27+)")
if _session := clientLogin(
api=api, session=session, username=username, password=password
):
return _session
time.sleep(5)
print("Trying to log in to the wiki using botLogin... (MW 1.27+)")
if _session := botLogin(
api=api, session=session, username=username, password=password
):
return _session
time.sleep(5)
if index:
print("Trying to log in to the wiki using indexLogin... (generic)")
if _session := indexLogin(
index=index, session=session, username=username, password=password
):
return _session
return None