Update README + Add Proxy Directory for Proxyfiles + Optimize Siteobject creation

This commit is contained in:
Lukas 2020-11-04 19:12:58 +01:00
parent 7e012d3c88
commit 1e213bb8bc
5 changed files with 75 additions and 43 deletions

View File

@ -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
## Configuration:

53
main.py
View File

@ -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})")

6
proxys/testproxy.json Normal file
View File

@ -0,0 +1,6 @@
{
"ip": "84.181.20.135",
"port": "4145",
"usr": null,
"pwd": null
}

View File

@ -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):

View File

@ -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']