Site Objects

This commit is contained in:
Lukas 2020-11-01 20:06:22 +01:00
parent 7883a82b11
commit bc33b89fbd
2 changed files with 58 additions and 21 deletions

51
main.py
View File

@ -1,10 +1,10 @@
import src.tools as tools import src.tools as tools
import src.monitor as monitor import src.site as site
import src.proxy as proxy import src.proxy as proxy
import src.monitor as monitor
import os import os
import glob import glob
import json
from dotenv import load_dotenv from dotenv import load_dotenv
from colorama import Style, Fore, init from colorama import Style, Fore, init
@ -18,10 +18,10 @@ def initialize():
init(autoreset=True) init(autoreset=True)
def readsites(sitepath=None): def checksites(sitepath=None):
print(f"{tools.heading('Checking Sitedata')}\n{tools.spacer}") print(f"{tools.heading('Checking Sitedata')}\n{tools.spacer}")
dod = {} sitedic = {}
if sitepath: if sitepath:
sitedir = sitepath sitedir = sitepath
else: else:
@ -29,54 +29,63 @@ def readsites(sitepath=None):
sitedir = rootdir + r"\sites" sitedir = rootdir + r"\sites"
for sitefile in glob.glob(sitedir + r"\*.json"): for sitefile in glob.glob(sitedir + r"\*.json"):
sfn = os.path.basename(sitefile) asite = site.Site(sitefile)
site, ext = os.path.splitext(sfn)
print(f"> {sfn}", end=" | ")
with open(sitefile, 'r') as f:
data = json.load(f)
print(f"data:{data}")
dod[site] = data
# print(f"DEBUG: {dod}") print(f"> {Fore.MAGENTA}{asite.name:10s}{Style.RESET_ALL} |"
f" {tools.keyword('URL')}({asite.url})")
sitedic[asite.name] = asite
print(tools.spacer) print(tools.spacer)
return sitedic
def proxytest(): def createproxys():
print(f"{tools.heading('Creating Proxy(s)')}\n{tools.spacer}") print(f"{tools.heading('Creating Proxy(s)')}\n{tools.spacer}")
proxydic = {}
one = proxy.Proxy( one = proxy.Proxy(
name="One", name="PrxOne",
url=os.getenv("PROXYURL"), url=os.getenv("PROXYURL"),
port=os.getenv("PROXYPORT"), port=os.getenv("PROXYPORT"),
usr=os.getenv("PROXYUSR"), usr=os.getenv("PROXYUSR"),
pwd=os.getenv("PROXYPW") pwd=os.getenv("PROXYPW")
) )
print(f"> {Fore.MAGENTA}{one.name}{Style.RESET_ALL} |" print(f"> {Fore.MAGENTA}{one.name:10s}{Style.RESET_ALL} |"
f" {tools.keyword('PROXYIP')}({one.ip}) {tools.keyword('WORKING')}({one.isworking})") f" {tools.keyword('PROXYIP')}({one.ip}) {tools.keyword('WORKING')}({one.isworking})")
# one.testurl("http://www.whatismyproxy.com/") # one.testurl("http://www.whatismyproxy.com/")
proxydic[one.name] = one
print(tools.spacer) print(tools.spacer)
return proxydic
def monitortest(n=1): def createmonitors(n=1):
print(f"{tools.heading(f'Creating Monitor(s)')}\n{tools.spacer}") print(f"{tools.heading(f'Creating Monitor(s)')}\n{tools.spacer}")
monitordic = {}
for i in range(0, n): for i in range(0, n):
mon = monitor.Monitor() mon = monitor.Monitor()
mon.name = f"Monitor {i}" mon.name = f"Mon{i}"
mon.url = "test" mon.url = "test"
print(f"> {Fore.MAGENTA}{mon.name}{Style.RESET_ALL} |" print(f"> {Fore.MAGENTA}{mon.name:10s}{Style.RESET_ALL} |"
f" {tools.keyword('URL')}({mon.url}) {tools.keyword('PROXY')}({mon.proxy})") f" {tools.keyword('URL')}({mon.url}) {tools.keyword('PROXY')}({mon.proxy})")
monitordic[mon.name] = mon
print(tools.spacer) print(tools.spacer)
return monitordic
if __name__ == "__main__": if __name__ == "__main__":
tools.clear() tools.clear()
initialize() initialize()
readsites() dicSites = checksites()
proxytest() dicProxys = createproxys()
monitortest() dicMonitors = createmonitors()
print(dicSites)
print(dicProxys)
print(dicMonitors)

28
src/site.py Normal file
View File

@ -0,0 +1,28 @@
import os
import json
class Site:
def __init__(self, file):
# Necessary
self.file = file
# Created on readfile
self.name = None
self.url = None
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']