-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.py
47 lines (33 loc) · 1.04 KB
/
helpers.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
import re
from web3 import Web3
from colorama import Fore, Style, init, Back, ansi
init(False)
print(Back.BLACK)
print(ansi.clear_screen())
regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
# domain...
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
r'localhost|' # localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
def validate_number_selection(end: int, number: int):
return number in range(end + 1)
def get_int_answer():
inp = None
try:
inp = input("> ")
answer = int(inp)
return True, answer
except Exception:
return False, inp
def my_print(msg: str, *args, **kwargs):
print(f"{Back.BLACK}{Fore.GREEN}{msg}", *args, **kwargs)
def end_style():
print(Style.RESET_ALL)
def is_valid_url(url: str):
global regex
return re.match(regex, url) is not None
def create_web3_instance(url: str):
return Web3(Web3.HTTPProvider(url))