python3.10以下switch的思路

# -*- coding: utf-8 -*-
import datetime, time
d = '2021-08-27 15:00'
pinlv = '每月'
iszhouliu = '否'
iszhoutian = '否'
to = '姚梦玲'
content = '【温馨提示】可爱的楼长~下午好,是时候收集楼层小伙伴们的加班需求啦!'

today = datetime.datetime.now()
timeStruct = time.strptime(d, "%Y-%m-%d %H:%M")
timeStamp = int(time.mktime(timeStruct))

def days():
    hour = time.strftime("%H", time.localtime(timeStamp))
    # print(hour)
    # print(today.hour)
    if int(today.hour) == int(hour):
        return True
    return False
def hour():
    return True
def month():
    hour = time.strftime("%H", time.localtime(timeStamp))
    day = time.strftime("%d", time.localtime(timeStamp))
    # print(day,today.day)
    if int(today.hour) == int(hour) and int(today.day) == int(day):
        return True
    return False
def default():
    return False


flag = True
result = False
weekday = today.isoweekday()
if iszhouliu == '否' and weekday == 6:
    flag = False
if iszhoutian == '否' and weekday == 7:
    flag = False

if flag:
    switch = {'每天': days, '每小时': hour, '每月': month}
    result = switch.get(pinlv, default)()


标签:暂无标签
版权属于:瑶玲OvO 所有,转载请注明文章来源。

本文链接: https://linmy.cn/index.php/python/29.html

赞 (0)

评论区

发表评论

字数
0
/200
35+35=?

暂无评论,要不来一发?

回到顶部