debugtalk.py 7.0 KB
import random
import string
import os
import time,datetime
from urllib import parse

from helpfunc.login_func import *
from helpfunc.pg_db_func import *
from helpfunc.other_func import *
# from helpfunc.db_func import *
from helpfunc.statistics_func import *
from helpfunc.header_func import *
from random import randint
# from helpfunc.pg_app_db_func import *
from datetime import date, timedelta
import datetime
import  time
from helpfunc.cal_func import *

def sleep(n_secs):
    time.sleep(n_secs)


def convert_to_string(value):
    return str(value)

def convert_to_int(value):
    return int(value)


def get_nowtime():
    return time.strftime("%Y%m%d%H%M%S",time.localtime(time.time()))

def get_today():
    now_today = datetime.datetime.now()
    str_time = now_today.strftime("%Y-%m-%d ")
    return str_time

def get_tomorrow():
    tomorrow = (date.today() + timedelta(days=1)).strftime("%Y-%m-%d ")
    return tomorrow
#获取今天时间并转str
def today_time_str():
    curr_time = datetime.datetime.now()
    time_str = datetime.datetime.strftime(curr_time,'%Y-%m-%d %H:%M:%S')
    return time_str
#获取明天时间并转str
def tomorrow_time_str():
    curr_time = datetime.datetime.now()
    tomorrow_time = curr_time + datetime.timedelta(days=1)
    time_str = datetime.datetime.strftime(tomorrow_time,'%Y-%m-%d %H:%M:%S')
    return time_str
#获取昨天时间并转str
def yes_time_str():
    curr_time = datetime.datetime.now()
    yes_time = curr_time + datetime.timedelta(days=-1)
    time_str = datetime.datetime.strftime(yes_time,'%Y-%m-%d %H:%M:%S')
    return time_str

def get_second():
    curr_time = datetime.datetime.now()
    return  curr_time.second

def create_channel(num):
    channel = []
    for i in range(num+1):
        channel.append(i)
    return channel


def get_minute():
    i = datetime.datetime.now()
    return i.minute


def create_phone_number(num):
    phone_number = []
    for i in range(num):
        number = random.randint(0,9)
        phone_number.append('1%d%d%07d'%(get_minute(),number+1,number))
    return phone_number


def getMonth():
    year = str(datetime.date.today().year)
    d = datetime.date.today()
    month = '%02d' % d.month
    if month in ['01', '03', '05', '07', '08', '10', '12']:
        s = str("-01 00:00:00")
        e = str("-31 23:59:59")
        startTime = year + "-" + str(month) + s
        endTime = year + "-" + str(month) + e
        list = [startTime, endTime]
        return list
    elif month == '02':
        s = str("-01 00:00:00")
        e = str("-28 23:59:59")
        startTime = year + "-" + str(month) + s
        endTime = year + "-" + str(month) + e
        list = [startTime, endTime]
        return list
    else:
        s = str("-01 00:00:00")
        e = str("-30 23:59:59")
        startTime = year + "-" + str(month) + s
        endTime = year + "-" + str(month) + e
        list = [startTime, endTime]
        return list
list_time = getMonth()
###获取当月1号时间戳
def get_starTimestamp():
    return int(time.mktime(time.strptime(list_time[0], '%Y-%m-%d %H:%M:%S'))*1000)
###获取当月最后一天时间戳
def get_endTimestamp():
    return int(time.mktime(time.strptime(list_time[1], '%Y-%m-%d %H:%M:%S'))*1000)

###获取1小时后时间戳
def get_nowTimestamp_1():
    # t = time.time()
    t = datetime.datetime.now()
    # 1小时后
    t2 = (t + datetime.timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S")
    # 转为秒级时间戳
    ts2 = time.mktime(time.strptime(t2, '%Y-%m-%d %H:%M:%S'))
    # 转为毫秒级
    start_time = int(str(ts2 * 1000).split(".")[0])
    return  start_time

###获取当前时间戳
def get_nowTimestamp():
    t = time.time()
    return  int(round(t * 1000))

def get_January_timestamp():
    return int(time.mktime(time.strptime('2020-04-01 00:00:00', '%Y-%m-%d %H:%M:%S'))*1000)

def get_Decembe_timestamp():
    return int(time.mktime(time.strptime('2021-3-31 23:59:59', '%Y-%m-%d %H:%M:%S'))*1000)


#获取secret用于子系统单点登录
def get_secret(url):
    urllist = url.split('code=',1)
    code = urllist[1]
    de_code = parse.unquote(code)
    return de_code


def get_stringcode(n):
    """
    随机生成n位数字符串
    :param n:
    :return:
    """
    ran_str = ''.join(random.sample(string.ascii_letters + string.digits, n))
    return ran_str

def get_partnerCategory(n):
    if n == 1:
        return '事业'
    elif n == 2 :
        return '业务'
    elif n == 3:
        return '研发'
    else:
        return '业务-产品应用'

def get_randint(value1, value2):
    return randint(value1, value2)


def convert_to_string(value):
    return str(value)


def convert_to_int(value):
    return int(value)



#获取季度对应的月份
def getql():
    today=datetime.date.today()
    quarter = (today.month-1)//3
    if quarter == 1:
        star1 = (str(today.year))+'-04'+'-01'+' '+'00:'+'00:'+'00'
        star = ''.join('%s' %id for id in star1)
        end1 = (str(today.year))+'-06'+'-30'+' '+'23:'+'59:'+'59'
        end = ''.join('%s' % id for id in end1)
        return star,end
    elif quarter == 2:
        star1 = (str(today.year))+'-07'+'-01'+' '+'00:'+'00:'+'00'
        star = ''.join('%s' %id for id in star1)
        end1 = (str(today.year))+'-09'+'-30'+' '+'23:'+'59:'+'59'
        end = ''.join('%s' % id for id in end1)
        return star, end
    elif quarter == 3:
        star1 = (str(today.year))+'-10'+'-01'+' '+'00:'+'00:'+'00'
        star = ''.join('%s' %id for id in star1)
        end1 = (str(today.year))+'-12'+'-31'+' '+'23:'+'59:'+'59'
        end = ''.join('%s' % id for id in end1)
        return star, end
    else:
        star1 = (str(today.year))+'-01'+'-01'+' '+'00:'+'00:'+'00'
        star = ''.join('%s' %id for id in star1)
        end1 = (str(today.year))+'-03'+'-31'+' '+'23:'+'59:'+'59'
        end = ''.join('%s' % id for id in end1)
        return star, end

#获取季度对应的月份开始时间戳
def gettql_startimestamp():
    return int(time.mktime(time.strptime(getql()[0], '%Y-%m-%d %H:%M:%S'))*1000)

#获取季度对应的月份结束时间戳
def gettql_endtimestamp():
    return int(time.mktime(time.strptime(getql()[1], '%Y-%m-%d %H:%M:%S'))*1000)

#获取文件
def get_file(filePath='config/订单数据模板.xlsx'):
    return filePath

#字符串时间转时间戳
def str_to_time(times):
    #将其转换为时间数组
    timeArray = time.strptime(times, "%Y-%m-%d %H:%M:%S")
    #转换为时间戳
    timeStamp = int(time.mktime(timeArray)*1000)
    return timeStamp

#获取销售日期
def get_saleDate(*args_v):
    return args_v[0]['saleDate']

#根据日期获取当天23:59:59分时间
def get_day_zero_time():
    for x in range(24):
        today_date = datetime.datetime.now().strftime("%Y-%m-%d") + " %2d:59:59" % x
        timeArray = time.strptime(today_date, "%Y-%m-%d %H:%M:%S")
        timeStamp = int(time.mktime(timeArray)*1000)
    return timeStamp

#通过当前时间和销售日期大于今天的订单进行比较
def get_saleDate_bigger_today(*args_v):
    if get_day_zero_time() < str_to_time(get_saleDate(*args_v)):
        return 0
    else:
        return 1