-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
36 lines (23 loc) · 838 Bytes
/
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
import random
import string
import logging
import threading
import requests
def get_random_password(length=16):
return ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=length))
def set_logger_format():
# set logger
logging.basicConfig(
format='%(asctime)s [%(processName)s] [%(threadName)s] [%(levelname)8s] %(message)s',
level=logging.INFO,
handlers=[logging.StreamHandler()]
)
def create_thread(target, name):
new_thread = threading.Thread(target=target)
new_thread.setName(name)
return new_thread
def create_http_session(adapter):
request_session = requests.Session()
request_session.mount('https://', adapter)
request_session.mount('http://', adapter)
return request_session