美文网首页
day21_itchat

day21_itchat

作者: 逆流而上_2eb6 | 来源:发表于2018-10-29 20:22 被阅读0次

1.time

时间格式:时间戳和struct_time
1.获取当前时间
时间戳:一个时间到1970年1月1日0点0分0秒的时间差。单位是秒
a. 方便对时间进行加密(保存时间前进行额外的运算)
b. 节省内存(数据库) 1540518823.7941608(8字节)
2.localtime
localtime(): 获取当前时间(struct_time)
localtime(时间戳): 将指定的时间戳转换成struct_time

struct_time:
tm_year -> 年
tm_mon -> 月
tm_mday -> 日
tm_hour -> 时
tm_min -> 分
tm_sec -> 秒
tm_wday -> 星期(值的范围是06,分别对应周一周天)
tm_yday -> 当前时间是今年的第几天
tm_isdst -> 是否是夏令时
3.strftime: 将时间(struct_time)以指定的格式转换成字符串
strftime(格式, 时间) --> 返回时间字符串

格式:是时间字符串(含有时间格式符的字符串)
%Y --> 年
%m --> 月(数字)
%d --> 日
%H --> 时
%M --> 分
%S --> 秒

%a -- 星期(英文缩写)
%A --> 星期(英文)
%h --> 月(英文缩写)
4.strptime: 将字符串转换成时间

strptime(字符串, 格式)
date: 可以表示年月日
time类:可以表示时分秒
datetime类:可以表示年月日时分秒
1.date类:对象属性:day,month,year
类方法:
fromtimestamp(时间戳) --> 将时间戳转换成日期(date对象)
tody() --> 获取当前日期
对象方法:
ctime() --> 将日期对象以 '%a %h %d %H:%M:%S %Y' 格式转换成字符串
strftime(时间格式字符串) --> 将日期对象以指定的格式转换成字符串
timetuple() --> 将日期转换成struct_time
weekday()/isoweekday() --> 获取星期值

date对象和datetime的对象都支持加减操作
date对象 + timedelta对象

2.itchat


import itchat
import threading
import re
itchat.auto_login(hotReload = True)
friends = itchat.get_friends()
print(friends)
def a():
    while 1:
        @itchat.msg_register(itchat.content.TEXT)
        def print_content(msg):
            print(msg['Text'])
t1 = threading.Thread(target = a)
t1.start()
while 1:
    try:
        value = input("1.按昵称查找好友\n2.按备注查找好友\n3.结束程序")
        if value == "2":
            value1 = input("请输入好友备注:")
            # print(itchat.search_friends(remarkName=value1))
            username1 = itchat.search_friends(remarkName=value1)
        elif value =="1":
            value1 = input("请输入要发送人的昵称:")
            # print(itchat.search_friends(nickName = value1))
            username1 = itchat.search_friends(nickName = value1)
        elif value == "3":
            break
        else:
            print("输入错误:")
            continue
        re_str=r"'UserName': '(@\w+?)'"
        username = re.findall(re_str,str(username1))[0]
        while 1:
            value = input("请输入要发送的内容(输入q结束)\n")
            if value =="q":
                break
            itchat.send(value, username)
    except:
        print("没有该好友!!")
print("感谢使用小何的小程序!")

相关文章

  • day21_itchat

    1.time 时间格式:时间戳和struct_time1.获取当前时间时间戳:一个时间到1970年1月1日0点0分...

网友评论

      本文标题:day21_itchat

      本文链接:https://www.haomeiwen.com/subject/fyldtqtx.html