Пример #1
0
    def SvcDoRun(self):

        tools.recordLog("Service start")

        time2 = 0
        timeCha = 0  #执行扫描的时间差
        mingzhongtime = ''
        while self.run:
            tools.recordLog("Server status " + gl.getvalue('version') +
                            ' is running at ' + tools.get_time_stamp())
            tools.recordLog("这是服务器启动后的开始")
            #gl.setvalue('count','0')
            sleepsecond = configRead.readConfig('parameter', 'sleepsecond')
            runtime = configRead.readConfig('parameter', 'runtime')
            print(sleepsecond)
            print(runtime)
            tools.recordLog(str(sleepsecond))
            tools.recordLog(str(runtime))
            currentTime = tools.get_hour()
            tools.recordLog(str(currentTime))

            #开始按计划扫描后,plan=0,以错过本次的周期扫描。当plan还=1时,按定时间隔扫描。
            plan = 1
            time1 = tools.get_hour()
            for i in runtime:
                tools.recordLog(str(tools.time_cmp(currentTime, i)))
                tools.recordLog(str(i))
                print("计划扫描时间" + i)
                print('时间差1:' + str(timeCha))
                if tools.time_cmp(currentTime,
                                  i) < (int(sleepsecond) + int(timeCha)):
                    tools.recordLog("计划扫描命中:" + i)
                    print("计划扫描命中:" + i)
                    print("上次命中计划:" + mingzhongtime)
                    if i != mingzhongtime:
                        print('currentTime=' + currentTime)
                        print("上次命中计划:" + mingzhongtime)
                        ServerHealth.health(plan)  # 1 参数为计划扫描
                        plan = 0
                        mingzhongtime = i

            if plan == 1:
                print("周期扫描命中" + currentTime)
                tools.recordLog("周期扫描命中" + currentTime)
                ServerHealth.health(0)  # 0 参数为周期扫描

            time2 = tools.get_hour()
            timeCha = tools.time_cmp(time1, time2)
            print('时间差2:' + str(timeCha))
            time.sleep(int(sleepsecond))
Пример #2
0
def quitgame(words):
    global kid
    global speak
    kid.endTime = tools.get_hour()
    kid.wronglist = list(set(kid.wronglist))  #去除重复单词
    wrongTime = len(kid.wronglist)
    rightTime = kid.question - wrongTime
    if kid.question == 1:
        print('\n亲爱的,你还没开始答题呢。要坚持哦!')
        sys.exit(0)
    print('得分 = ' + str(round((rightTime - 1) / (kid.question - 1) * 100, 0)))
    print('\n总共出题:' + str(kid.question - 1))
    print('答对题目:' + str(rightTime - 1))
    print('答错题目:' + str(wrongTime))
    print('提示次数:' + str(kid.alarmTime))
    kid.spendMinute = round(tools.time_cmp(kid.endTime, kid.startTime) / 60, 0)
    kid.spendSecond = tools.time_cmp(kid.endTime, kid.startTime) % 60

    print('用时:' + str(kid.spendMinute) + '分' + str(kid.spendSecond) + '秒')

    speak.Speak('你总共得分:' +
                str(round((rightTime - 1) /
                          (kid.question - 1) * 100, 0)) + '分')

    if len(kid.wronglist) > 0:
        print('\n以下是答错的单词')
        speak.Speak('你答错了下面的单词:')
        pprint.pprint(kid.wronglist)
        time.sleep(5)
        print('\n')
        rewrite(kid.wronglist, words)

    else:
        if (kid.question - 1) > 0:
            print('恭喜你全部正确!\n')
            speak.Speak('恭喜你全部正确!')

    tools.recordLog('得分 = ' +
                    str(round((rightTime - 1) / (kid.question - 1) * 100, 0)))
    tools.recordLog('总共出题:' + str(kid.question - 1))
    tools.recordLog('答对题目:' + str(rightTime - 1))
    tools.recordLog('答错题目:' + str(wrongTime))
    tools.recordLog('提示次数:' + str(kid.alarmTime))
    tools.recordLog('用时:' + str(kid.spendMinute) + '分' + str(kid.spendSecond) +
                    '秒')
    tools.recordLog('以下是答错的单词')
    tools.recordLog(str(kid.wronglist))
    print('\n练习完毕,请输入回车退出')
    while len(input()) < 1:
        sys.exit(0)
Пример #3
0
def getSyncSeconds(list):

    #conn = pymssql.connect('183.111.122.191', 'sa', 'VTTthL5oLgyVckWdbd2EFw==', 'YT')
    conn = pymssql.connect(list[1], list[2], list[3], list[4])

    cursor = conn.cursor()

    sqltext = r"""
    SELECT top 1 
          [CreateTime]
      FROM [dbo].[LotteryHistoryNumCache]
      order by [CreateTime] desc
      """
    timeChayi = '0'
    try:
        cursor.execute(sqltext, 'timeout=6')
        row = cursor.fetchone()

        while row:

            currentTime = tools.get_hour()
            print(currentTime)
            thisTime = row[0].strftime('%H:%M:%S')
            print(thisTime)
            timeChayi = tools.time_cmp(currentTime, thisTime)
            print(timeChayi)
            row = cursor.fetchone()

    except Exception as err:
        print(str(err))
        timeChayi = 'Down'
    finally:
        cursor.close()
        conn.close()

    return timeChayi
Пример #4
0
    time_stamp = "%s.%03d" % (data_head, data_secs)
    return time_stamp


def get_hour():
    ct = time.time()
    local_time = time.localtime(ct)
    hourtime = time.strftime("%H:%M:%S", local_time)
    return hourtime


def time_cmp(first_time, second_time):
    if first_time < second_time:
        first_time, second_time = second_time, first_time
    return (datetime.datetime.strptime(first_time, "%H:%M:%S") -
            datetime.datetime.strptime(second_time, "%H:%M:%S")).seconds


sleepsecond = configRead.readConfig('parameter', 'sleepsecond')
runtime = configRead.readConfig('parameter', 'runtime')

currentTime = tools.get_hour()
tools.recordLog(str(tools.time_cmp(currentTime, i)))
print('sleepsecond=' + str(sleepsecond))
print(runtime)
for i in runtime:
    if tools.time_cmp(currentTime, i) < sleepsecond:
        print("运行时间到了")
    else:
        print("未到运行时间")