-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
69 lines (56 loc) · 1.81 KB
/
utils.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
67
68
69
from datetime import datetime
from termcolor import cprint, colored
import colorama
class Logger():
def __init__(self):
colorama.init()
print("{} Using python-utils by @ryan9918_".format(self.__timestamp()))
def __timestamp(self):
timestamp = str("["+datetime.now().strftime("%H:%M:%S.%f")[:-3]+"]")
return timestamp
def log(self, text):
print("{} {}".format(self.__timestamp(), text))
return
def success(self, text):
print("{} {}".format(self.__timestamp(), colored(text, "green")))
return
def warn(self, text):
print("{} {}".format(self.__timestamp(), colored(text, "yellow")))
return
def error(self, text):
print("{} {}".format(self.__timestamp(), colored(text, "red")))
return
def status(self, text):
print("{} {}".format(self.__timestamp(), colored(text, "magenta")))
return
class ProxyManager():
def __init__(self):
self.proxies = []
with open('proxies.txt') as f:
for item in f.read().splitlines():
if not item == '':
item = item.split(":")
if len(item) == 4:
proxyDict = {
'http': 'http://{}:{}@{}:{}'.format(item[2], item[3], item[0], item[1]),
'https': 'https://{}:{}@{}:{}'.format(item[2], item[3], item[0], item[1])
}
self.proxies.append(proxyDict)
elif len(item) == 2:
proxyDict = {
'http': 'http://{}:{}'.format(item[0], item[1]),
'https': 'https://{}:{}'.format(item[0], item[1])
}
self.proxies.append(proxyDict)
else:
pass
f.close()
timestamp = str("["+datetime.now().strftime("%H:%M:%S.%f")[:-3]+"]")
print("{} Loaded {} proxies from file".format(timestamp, len(self.proxies)))
def get_proxy(self):
try:
proxy = self.proxies.pop(0)
self.proxies.append(proxy)
except:
proxy = None
return proxy