-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
141 lines (115 loc) · 4.77 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import random
import string
import logging
# Configure logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# Lists for generating random user information
FIRST_NAMES = ["Alex", "Jordan", "Taylor", "Morgan", "Casey", "Riley", "Jamie", "Avery",
"Quinn", "Skyler", "Dakota", "Reese", "Finley", "Rowan", "Parker", "Cameron"]
LAST_NAMES = ["Smith", "Johnson", "Williams", "Brown", "Jones", "Miller", "Davis",
"Garcia", "Rodriguez", "Wilson", "Martinez", "Anderson", "Taylor", "Thomas",
"Hernandez", "Moore", "Martin", "Jackson", "Thompson", "White"]
GENDERS = ["Male", "Female", "Rather not say"]
MONTHS = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
def generate_random_username(first_name, last_name):
"""Generate a random username based on first and last name with numbers."""
first = first_name.lower()
last = last_name.lower()
random_digits = ''.join(random.choices(string.digits, k=random.randint(3, 5)))
username_patterns = [
f"{first}.{last}{random_digits}",
f"{first}{last}{random_digits}",
f"{first[0]}{last}{random_digits}",
f"{first}_{last}{random_digits}",
f"{first}{random_digits}",
f"{first}{last[0]}{random_digits}"
]
return random.choice(username_patterns)
def generate_random_password():
"""Generate a secure random password."""
length = random.randint(12, 16)
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
digits = string.digits
special = "!@#$%^&*-_"
# Ensure at least one of each character type
password = [
random.choice(lowercase),
random.choice(uppercase),
random.choice(digits),
random.choice(special)
]
# Fill the rest of the password
remaining_length = length - len(password)
all_chars = lowercase + uppercase + digits + special
password.extend(random.choices(all_chars, k=remaining_length))
# Shuffle the password
random.shuffle(password)
return ''.join(password)
def generate_random_user_info():
"""Generate random user information for account creation."""
first_name = random.choice(FIRST_NAMES)
last_name = random.choice(LAST_NAMES)
username = generate_random_username(first_name, last_name)
password = generate_random_password()
birth_day = str(random.randint(1, 28))
birth_month = random.choice(MONTHS)
# Generate year between 1985 and 2000
birth_year = str(random.randint(1985, 2000))
gender = random.choice(GENDERS)
user_info = {
'first_name': first_name,
'last_name': last_name,
'username': username,
'password': password,
'birth_day': birth_day,
'birth_month': birth_month,
'birth_year': birth_year,
'gender': gender
}
logger.debug(f"Generated random user info: {user_info}")
return user_info
def setup_proxy(proxy_string):
"""
Convert proxy string to a format suitable for Selenium.
Args:
proxy_string: String in format 'protocol://username:password@host:port'
Returns:
dict: Proxy configuration for Selenium
"""
if not proxy_string or proxy_string == "default":
return None
try:
# Parse the proxy string
if '@' in proxy_string:
# Proxy with authentication
auth_part, address_part = proxy_string.split('@')
protocol = auth_part.split('://')[0]
if ':' in address_part:
host, port = address_part.split(':')
return {
'proxyType': protocol,
'httpProxy': f"{host}:{port}",
'sslProxy': f"{host}:{port}",
'socksProxy': f"{host}:{port}" if protocol == 'socks5' else None
}
else:
# Proxy without authentication
if '://' in proxy_string:
protocol, address = proxy_string.split('://')
if ':' in address:
host, port = address.split(':')
return {
'proxyType': protocol,
'httpProxy': f"{host}:{port}",
'sslProxy': f"{host}:{port}",
'socksProxy': f"{host}:{port}" if protocol == 'socks5' else None
}
except Exception as e:
logger.error(f"Error parsing proxy string: {str(e)}")
return None
logger.error(f"Invalid proxy format: {proxy_string}")
return None