url = 'http://localhost.com'
# Splicing URL function
def makeurl(*res):
lst_res = list(res)
for i in range(0,len(lst_res)):
res = lst_res[i]
if res.endswith('/') or res.startswith('/'):
lst_res[i] == res.strip('/')
lst_res.insert(0,url)
return '/'.join(lst_res)
url = makeurl('ceshi','logins')
Request to retry decorator
# Connect retry decorator
def retry(exception=Timeout,max_times=3):
def inner(func):
def warp(*args,**kwargs):
for try_time in range(max_times):
try:
return func(*args,**kwargs)
except exception as e:
if try_time == max_times -1:
raise e
time.sleep(3)
print(' Retry the last request ')
continue
return warp
return inner
Copy file
# Copy file
def copy_file(source_file, des_file):
""" Copy file """
from shutil import copyfile
import sys
try:
copyfile(source_file, des_file)
except IOError as e:
print("Unable to copy file. %s" % e)
raise e
except Exception as e:
print("Unexpected error:", sys.exc_info())
raise e
copy_file(source_file, des_file)
Create folder
# Create folder
def makedir(path):
# Remove the leading and trailing spaces
path = path.strip()
# Remove the tail \ Symbol
path.rstrip('\\')
if not os.path.exists(path):
os.makedirs(path)
return path