create methods
This commit is contained in:
parent
d1e7dccfae
commit
a4772a94c6
1 changed files with 31 additions and 19 deletions
20
main.py
20
main.py
|
@ -1,7 +1,7 @@
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from os import environ
|
from os import environ
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from cloudscraper import CloudScraper
|
from cloudscraper import create_scraper
|
||||||
|
|
||||||
class Scraper:
|
class Scraper:
|
||||||
def __init__(self, pseudo, password, app, debug = False):
|
def __init__(self, pseudo, password, app, debug = False):
|
||||||
|
@ -20,7 +20,7 @@ class Scraper:
|
||||||
return f"\Error: [{code}]"
|
return f"\Error: [{code}]"
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
with CloudScraper(browser = {"browser": "chrome", "platform": "windows"}) as session:
|
session = create_scraper(browser = {"browser": "chrome", "platform": "windows"})
|
||||||
if self.debug: print("Retrieval of the login cookie...", end = " ")
|
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:
|
||||||
|
@ -34,13 +34,25 @@ class Scraper:
|
||||||
if self.debug: 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)
|
||||||
|
|
||||||
|
return session
|
||||||
|
|
||||||
|
def search(self, session):
|
||||||
|
|
||||||
link = "No link for your application was found."
|
link = "No link for your application was found."
|
||||||
return link
|
return link
|
||||||
|
|
||||||
|
def work(self):
|
||||||
|
session = self.connect()
|
||||||
|
|
||||||
|
link = self.search(session)
|
||||||
|
|
||||||
|
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).work())
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
@ -48,6 +60,6 @@ if __name__ == "__main__":
|
||||||
debug = environ["DEBUG_MOBILISM"].lower() in ("yes", "true", "1")
|
debug = environ["DEBUG_MOBILISM"].lower() in ("yes", "true", "1")
|
||||||
except:
|
except:
|
||||||
debug = False
|
debug = False
|
||||||
print(Scraper(environ["PSEUDO_MOBILISM"], environ["PASSWORD_MOBILISM"], environ["APP_MOBILISM"], debug).connect())
|
print(Scraper(environ["PSEUDO_MOBILISM"], environ["PASSWORD_MOBILISM"], environ["APP_MOBILISM"], debug).work())
|
||||||
except:
|
except:
|
||||||
print('Please fill in the username and password (with ") by args or with .env file.')
|
print('Please fill in the username and password (with ") by args or with .env file.')
|
||||||
|
|
Reference in a new issue