-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.py
66 lines (57 loc) · 1.99 KB
/
Utility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import LoadBalancer
import logging
from cache import Cache
from bs4 import BeautifulSoup
logger=logging
logger.basicConfig(filename="Logs.txt",level=logging.DEBUG,format = '%(asctime)s %(levelname)s %(name)s %(message)s')
def Inizialize_LoadBalancer(test=False):
try:
if test:
replicas=4
Load_Balancer=LoadBalancer.LoadBalancer(replicas)
ServerName="Server1"
Server_IP="192.168.1.1"
Server_Port="8000"
else:
print("please provide server replicas for load balancer")
replicas=RetrieveInputFromUser(type=int)
Load_Balancer=LoadBalancer.LoadBalancer(replicas)
print("Please Provide ServerName below")
ServerName=RetrieveInputFromUser()
print("Please Provide Server_IP below")
Server_IP=RetrieveInputFromUser()
print("Please Provide Server_Port below")
Server_Port=RetrieveInputFromUser(type=int)
Load_Balancer.Map_ServerIP(ServerName,Server_IP,Server_Port)
return Load_Balancer
except Exception as e:
print("Error Occured in LoadBalancer Module")
logger.debug(e)
def Primary_Parser(response):
response=LinksParser(response)
response=ImageParser(response)
return response
def LinksParser(response):
for link in response.find_all('a'):
hyperlink=link["href"]
link["href"]="http://localhost:8080/"+hyperlink
return response
def ImageParser(response):
for image in response.find_all('img'):
Imagelink=image['src']
image['src']="http://localhost:8080/"+Imagelink
return response
def RetrieveInputFromUser(type=str):
while True:
try:
User_Input=type(input())
return User_Input
except Exception as e:
print("Invalid Input")
def Initialize_Cache():
try:
cache=Cache()
return cache
except Exception as e:
print("Error Occured in Cache Module")
logger.debug(e)