以深圳为例Python一键生成核酸检测日历
📢博客主页:
大家好,我是小小明。鉴于深圳最近每天都要做核酸,我觉得有必要用程序生成自己的检测日历,方便查看。
UI自动化提取检测记录
点击 核酸检测记录,再点击自己的姓名即可查看自己的核酸检测记录:
下面我们打开inspect.exe工具分析查看节点:
于是开始编码:
import pandas as pd import uiautomation as auto pane = auto.PaneControl(searchDepth=1, Name="深i您 - 自主申报") pane.SetActive(waitTime=0.01) pane.SetTopmost(waitTime=0.01) tags = pane.GetFirstChildControl().GetFirstChildControl() .GetLastChildControl().GetFirstChildControl() .GetChildren() result = [] for tag in tags: tmp = [] for item, depth in auto.WalkControl(tag, maxDepth=4): if item.ControlType != auto.ControlType.TextControl: continue tmp.append(item.Name) row = { "检测结果": tmp[1]} for k, v in zip(tmp[2::2], tmp[3::2]): row[k[:-1]] = v result.append(row) pane.SetTopmost(False, waitTime=0.01) df = pd.DataFrame(result) df.采样时间 = pd.to_datetime(df.采样时间) df.检测时间 = pd.to_datetime(df.检测时间) df.head()
结果如下:
有了检测数据,我们就可以生成检测日历了。也可以先将检测数据保存起来:
df.to_excel(f"{ pd.Timestamp(now).date()}核酸检测记录.xlsx", index=False)
注意:其他省市的童鞋,请根据自己城市对应的小程序实际情况编写代码进行提取。
后面碰到正在检测的记录上面的代码会报错,分析节点后,下面升级到能够兼容出现检测记录的情况:
import pandas as pd import uiautomation as auto pane = auto.PaneControl(searchDepth=1, Name="深i您 - 自主申报") pane.SetActive(waitTime=0.01) pane.SetTopmost(waitTime=0.01) tag = pane.GetFirstChildControl().GetFirstChildControl() .GetLastChildControl().GetFirstChildControl() tmp = [] for item, depth in auto.WalkControl(tag, maxDepth=2): if item.ControlType != auto.ControlType.TextControl: continue tmp.append(item.Name) result = [] tags = tag.GetChildren() if tmp: row = { "检测结果": tmp[1]} for k, v in zip(tmp[2::2], tmp[3::2]): row[k[:-1]] = v result.append(row) for tag in tags: if tag.Name or tag.GetFirstChildControl().Name: continue tmp = [] for item, depth in auto.WalkControl(tag, maxDepth=4): if item.ControlType != auto.ControlType.TextControl: continue tmp.append(item.Name) row = { "检测结果": tmp[1]} for k, v in zip(tmp[2::2], tmp[3::2]): row[k[:-1]] = v result.append(row) pane.SetTopmost(False, waitTime=0.01) df = pd.DataFrame(result) df.采样时间 = pd.to_datetime(df.采样时间) df.检测时间 = pd.to_datetime(df.检测时间) df.head()
生成核酸检测日历
经过几小时的测试,最终编写出如下方法:
然后我们可以生成最近1-3个月的核酸检测日历:
dates = df.采样时间.dt.date.sort_values().astype(str) for month, date_split in dates.groupby(dates.str[:7]): year, month = map(int, month.split("-")) days = date_split.str[-2:].astype(int) im = create_calendar_img(year, month, days.values) display(im)
可以看到我最近连续9天都是每天做一次核酸。
如果有需要,这些图片也可以按需保存:
im.save(f"{ year}年{ month}月检测记录.jpg")
下一篇:
要被抖音笑死了,打开个网页就算黑客?