add verbose option
This commit is contained in:
parent
76a5225587
commit
d1e7dccfae
1 changed files with 24 additions and 12 deletions
34
main.py
34
main.py
|
@ -4,38 +4,50 @@ from dotenv import load_dotenv
|
||||||
from cloudscraper import CloudScraper
|
from cloudscraper import CloudScraper
|
||||||
|
|
||||||
class Scraper:
|
class Scraper:
|
||||||
def __init__(self, pseudo, password, app):
|
def __init__(self, pseudo, password, app, debug = False):
|
||||||
|
self.debug = debug
|
||||||
self.url = "https://forum.mobilism.org"
|
self.url = "https://forum.mobilism.org"
|
||||||
self.requested_app = app
|
self.requested_app = app
|
||||||
self.loginData = {
|
self.loginData = {
|
||||||
"username": pseudo,
|
"username": pseudo,
|
||||||
"password": password,
|
"password": password,
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
"redirect": "./ucp.php?mode=login",
|
# "redirect": "./ucp.php?mode=login",
|
||||||
"redirect": "index.php"
|
"redirect": "index.php"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def errorFormat(self, code: int) -> str:
|
||||||
|
return f"\Error: [{code}]"
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
with CloudScraper(browser = {"browser": "chrome", "platform": "windows"}, debug = True) as session:
|
with CloudScraper(browser = {"browser": "chrome", "platform": "windows"}) as session:
|
||||||
|
if self.debug: print("Retrieval of the login cookie...", end = " ")
|
||||||
reponse = session.get(f"{self.url}/ucp.php?mode=login")
|
reponse = session.get(f"{self.url}/ucp.php?mode=login")
|
||||||
if reponse.status_code != 200:
|
if reponse.status_code != 200:
|
||||||
raise ConnectionRefusedError(f"[{reponse.status_code}]")
|
raise ConnectionRefusedError(self.errorFormat(reponse.status_code))
|
||||||
self.loginData["sid"] = reponse.cookies.get_dict()["ppcw_29d3s_sid"]
|
self.loginData["sid"] = reponse.cookies.get_dict()["ppcw_29d3s_sid"]
|
||||||
|
if self.debug: print("Cookie retrieval done, connection attempt...", end = " ")
|
||||||
reponse = session.post(f"{self.url}/ucp.php?mode=login", data = self.loginData)
|
reponse = session.post(f"{self.url}/ucp.php?mode=login", data = self.loginData)
|
||||||
if reponse.status_code != 200:
|
if reponse.status_code != 200:
|
||||||
raise ConnectionRefusedError(f"[{reponse.status_code}]")
|
raise ConnectionRefusedError(self.errorFormat(reponse.status_code))
|
||||||
print(self.loginData)
|
if self.debug: print("Connection done.")
|
||||||
print(reponse.status_code, reponse.url)
|
if self.debug: print(reponse.status_code, reponse.url)
|
||||||
with open("temp.html", "w") as f:
|
with open("temp.html", "w") as f:
|
||||||
f.writelines(reponse.text)
|
f.writelines(reponse.text)
|
||||||
|
link = "No link for your application was found."
|
||||||
|
return link
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
argv = argv[1:]
|
argv = argv[1:]
|
||||||
if len(argv) == 3:
|
if len(argv) == 3:
|
||||||
print(Scraper(*argv).connect())
|
print(Scraper(*argv).connect())
|
||||||
else:
|
else:
|
||||||
#try:
|
try:
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
print(Scraper(environ["PSEUDO_MOBILISM"], environ["PASSWORD_MOBILISM"], environ["APP_MOBILISM"]).connect())
|
try:
|
||||||
#except:
|
debug = environ["DEBUG_MOBILISM"].lower() in ("yes", "true", "1")
|
||||||
# print('Please fill in the username and password (with ") by args or with .env file.')
|
except:
|
||||||
|
debug = False
|
||||||
|
print(Scraper(environ["PSEUDO_MOBILISM"], environ["PASSWORD_MOBILISM"], environ["APP_MOBILISM"], debug).connect())
|
||||||
|
except:
|
||||||
|
print('Please fill in the username and password (with ") by args or with .env file.')
|
||||||
|
|
Reference in a new issue