From 1e213bb8bc4574d1c76ab611ac21e89fefa61986 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 4 Nov 2020 19:12:58 +0100 Subject: [PATCH] Update README + Add Proxy Directory for Proxyfiles + Optimize Siteobject creation --- README.md | 16 ++++++++----- main.py | 53 ++++++++++++++++++++++++++++++++++--------- proxys/testproxy.json | 6 +++++ src/proxy.py | 18 +++++++++++---- src/site.py | 25 ++++---------------- 5 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 proxys/testproxy.json diff --git a/README.md b/README.md index 80d23ee..5589613 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ -# MSSWY +# MSSWY + + **M**e**S**crape**S**neaker**W**ebsite**Y**es :rocket: + +:rocket: Monitor Website Content +:rocket: Create Website Accounts +:rocket: Try to enter Raffles +:rocket: Automatically Shop -MeScrapeSneakerWebsiteYes +## Installation: -- Monitor Website Content -- Create Website Accounts -- Try to enter Raffles -- Automatically Shop \ No newline at end of file +## Configuration: diff --git a/main.py b/main.py index a2a3c2d..94f2449 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ import src.monitor as monitor import os import glob +import json from dotenv import load_dotenv from colorama import Style, Fore, init @@ -32,7 +33,13 @@ def checksites(sitepath=None): # Parse all sitefiles into objects for sitefile in glob.glob(sitedir + r"\*.json"): - asite = site.Site(sitefile) + + sitename, ext = os.path.splitext(os.path.basename(sitefile)) + + with open(sitefile, 'r') as f: + data = json.load(f) + + asite = site.Site(sitename, data['url']) print(f"> {Fore.MAGENTA}{asite.name:10s}{Style.RESET_ALL} |" f" {tools.keyword('URL')}({asite.url})") @@ -43,24 +50,48 @@ def checksites(sitepath=None): return sitedic -def createproxys(): +def createproxys(proxypath=None): print(f"{tools.heading('Creating Proxy(s)')}\n{tools.spacer}") proxydic = {} - one = proxy.Proxy( + + # Find proxy directory + if proxypath: + proxydir = proxypath + else: + rootdir = os.path.dirname(os.path.abspath(__file__)) + proxydir = rootdir + r"\proxys" + + # Parse all sitefiles into objects + for proxyfile in glob.glob(proxydir + r"\*.json"): + + proxyname, ext = os.path.splitext(os.path.basename(proxyfile)) + + with open(proxyfile, 'r') as f: + data = json.load(f) + + aproxy = proxy.Proxy(proxyname, data['ip'], data['port'], data['usr'], data['pwd']) + + print(f"> {Fore.MAGENTA}{aproxy.name:10s}{Style.RESET_ALL} |" + f" {tools.keyword('PROXYIP')}({aproxy.ip}) {tools.keyword('WORKING')}({aproxy.isworking})") + + # We can test our proxy using this site: + # one.testurl("http://www.whatismyproxy.com/") + + proxydic[aproxy.name] = aproxy + + # MY TEST PROXY ################### + my = proxy.Proxy( name="PrxOne", url=os.getenv("PROXYURL"), port=os.getenv("PROXYPORT"), usr=os.getenv("PROXYUSR"), pwd=os.getenv("PROXYPW") ) - print(f"> {Fore.MAGENTA}{one.name:10s}{Style.RESET_ALL} |" - f" {tools.keyword('PROXYIP')}({one.ip}) {tools.keyword('WORKING')}({one.isworking})") - - # We can test our proxy using this site: - # one.testurl("http://www.whatismyproxy.com/") - - proxydic[one.name] = one + proxydic[my.name] = my + print(f"> {Fore.MAGENTA}{my.name:10s}{Style.RESET_ALL} |" + f" {tools.keyword('PROXYIP')}({my.ip}) {tools.keyword('WORKING')}({my.isworking})") + ################################### print(tools.spacer) return proxydic @@ -72,7 +103,7 @@ def createmonitors(n=1): monitordic = {} for i in range(0, n): mon = monitor.Monitor() - mon.name = f"Mon{i}" + mon.name = f"monitor {i}" mon.url = "test" print(f"> {Fore.MAGENTA}{mon.name:10s}{Style.RESET_ALL} |" f" {tools.keyword('URL')}({mon.url}) {tools.keyword('PROXY')}({mon.proxy})") diff --git a/proxys/testproxy.json b/proxys/testproxy.json new file mode 100644 index 0000000..9222b22 --- /dev/null +++ b/proxys/testproxy.json @@ -0,0 +1,6 @@ +{ + "ip": "84.181.20.135", + "port": "4145", + "usr": null, + "pwd": null +} \ No newline at end of file diff --git a/src/proxy.py b/src/proxy.py index 14f402c..8b2f4db 100644 --- a/src/proxy.py +++ b/src/proxy.py @@ -30,10 +30,18 @@ class Proxy: self.session = requests.Session() url = "https://api.ipify.org/" - proxies = { - 'http': f'http://{self.usr}:{self.pwd}@{self.url}:{self.port}', - 'https': f'http://{self.usr}:{self.pwd}@{self.url}:{self.port}' - } + if self.usr: + proxies = { + 'http': f'http://{self.usr}:{self.pwd}@{self.url}:{self.port}', + 'https': f'http://{self.usr}:{self.pwd}@{self.url}:{self.port}' + } + else: + proxies = { + 'http': f'http://{self.url}:{self.port}', + 'https': f'http://{self.url}:{self.port}' + } + + print(f"[DEBUG] {proxies}") headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)' @@ -62,7 +70,7 @@ class Proxy: # print(f"DEBUG: Statuscode: {r.status_code}\nDEBUG: Good Proxy: {self.isworking}") except Exception as e: - print(f"Connection Error! (check proxy settings)\n\n{e}") + print(f"[DEBUG] Connection Error | (check proxy settings)\n[DEBUG] {e}") self.isworking = False def testurl(self, url): diff --git a/src/site.py b/src/site.py index 1d3fad9..f2da908 100644 --- a/src/site.py +++ b/src/site.py @@ -1,28 +1,11 @@ -import os -import json - - class Site: - def __init__(self, file): + def __init__(self, name, url): # Necessary - self.file = file + self.name = name + self.url = url - # Created on readfile - self.name = None - self.url = None + # Created self.data = None self.ext = None - - self.readfile() - - def readfile(self): - self.name = os.path.basename(self.file) - site, self.ext = os.path.splitext(self.name) - - with open(self.file, 'r') as f: - self.data = json.load(f) - - if 'url' in self.data: - self.url = self.data['url']