日期2022.3.28

目录

1、从腾讯问卷导出CSV数据

2、Python实现一天打卡(需手动下载数据,并解压重命名)

3、Python实现连续多天打卡检测(需手动下载数据,并解压重命名)

4、url下载文件,打卡检测(未成功)

5、改进Python实现连续多天打卡检测(仅需手动下载数据,然后运行)


1、从腾讯问卷导出CSV数据

将全部打卡人数的信息,放入benkeshen文件夹,一行一个名字

运行python程序,得出结果

2、Python实现一天打卡(需手动下载数据,并解压重命名)

import csv
time = r"2022/3/22"
# 读取第一个文件name
with open(r'C:\Users\14193\Desktop\benkesheng.txt', 'r', encoding='utf-8') as f1:name = f1.read()
# 将字符串name 切片成 list
name = name.split()
print(f"人数:\t{len(name)}")# 读取第二个文件
with open(r'C:\Users\14193\Desktop\1.csv', 'r', encoding='utf-8') as f2:reader = csv.reader(f2)# 略过第一行next(reader)# 逐行遍历剩下的每行数据for row in reader:# 对比所需找的日期 将出现的name删除if time in row[2] and row[11] in name:name.remove(row[11])
# 直接在控制台输出结果
print(f"未打卡:\t{name}")# 将结果输出到文件中
with open(r'C:\Users\14193\Desktop\result.txt', 'w', encoding='utf-8') as f3:# 逐行遍历namefor row in name:f3.write(row)f3.write("\n")

3、Python实现连续多天打卡检测(需手动下载数据,并解压重命名)

import os
root = os.getcwd()#获取当前文件执行路径import csv
from datetime import datetime, timedelta
# 开始日期的前一天
start = datetime.strptime("20-Mar-2022", "%d-%b-%Y")
now = datetime.strftime(datetime.now(), "%d-%b-%Y")
# 重置结束日期为0点0分0秒
end = datetime.strptime(now, "%d-%b-%Y")
print(f"输出一下日期格式\n{start}\n{end}")
print(f"今天打卡日期:\t{now}")timeList = []
temp = end
while temp != start:# 转化为字符串格式,放入列表中timeList.append(datetime.strftime(temp, "%d-%b-%Y"))# 向前推一天temp = temp - timedelta(days=1)
print(f"日历列表如下:\n{timeList}")
print(f"打卡天数:\t{len(timeList)}")
print(f"打卡开始日期:\t{timeList[len(timeList) - 1]}")
print(f"打卡结束日期:\t{timeList[0]}")# 读取第一个文件name,包含全部打卡人员名字
with open(root + '\\benkesheng.txt', 'r', encoding='utf-8') as f1:name = f1.read()# 将字符串 name 切片成 list
name = name.split()
print(f"总人数:\t{len(name)}")
# 存放全部日期未打卡人员的名字,即每一天
notFindName = []# 读取第二个文件
with open(root + '\\1.csv', 'r', encoding='utf-8') as f2:reader = csv.reader(f2)# 略过第一行next(reader)# 一天未打卡人员名字,结果中包含所有名字,打卡的则从中剔除,剩下即为未打卡res = name[:]# 逐行遍历剩下的每行数据i = 0for row in reader:# 打印文件中的时间格式# print(row[2])# 找到对应的日期while timeList[i] not in row[2]:if len(res) != len(name):# 控制台输出print(f"{timeList[i]}未打卡人数:\t{len(res)}\n{res}")# 结果放入列表中,最后读入文件notFindName.append(res)# 下一天的打卡信息i += 1res = name[:]# 打卡的则从中剔除,剩下即为未打卡if row[11] in res:res.remove(row[11])
# 输出最早的一天数据
notFindName.append(res)
print(f"{timeList[i]}未打卡人数:\t{len(res)}\n{res}")# 将结果输出到文件中
with open(root + '\\result.txt', 'w', encoding='utf-8') as f3:# 逐行遍历日期列表timeListfor i in range(len(timeList)):f3.write(f"{timeList[i]}未打卡人数:\t{len(notFindName[i])}\n{notFindName[i]}\n")

4、url下载文件,打卡检测(未成功)

因为腾讯问卷的url时刻变化,

实现后发现,腾讯问卷导出数据的链接,每次都不一样,因此通过同一个url下载的数据一致,无法动态检测。

因此还需手动点击下载数据

root = os.getcwd()  # 获取当前文件执行路径
url = r'https://wj-collection-1258344706.cos-website.ap-guangzhou.myqcloud.com/export/answer/9501508_202205091414576686.csv.zip?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKID3dz5uN4cMpGamjMvBaySkOoxwmMgMacO%26q-sign-time%3D1652076839%3B1652098499%26q-key-time%3D1652076839%3B1652098499%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D4954e92a16074b56f7812697c298c238c5a5aa2b&_=1652076899732'# 下载文件到本地的路径,拼接路径,等价于 root \ 文件名
zippath = os.path.join(root, '9501508_202205091414576686.zip')
urllib.request.urlretrieve(url, zippath)  # 下载文件
with zipfile.ZipFile(zippath, 'r') as zip:  # 解压文件zip.extractall(root)  # 压缩包内文件全部解压到root目录# 压缩包文件名,拼接成路径,等价于 root \ 文件名datafile = os.path.join(root, zip.namelist()[0])# 删除压缩文件
# os.remove(zippath)
# 删除解压后的文件
# os.remove(datafile)

5、改进Python实现连续多天打卡检测(仅需手动下载数据,然后运行)

默认下载路径:C:\Users\Lenovo\Downloads

在该路径下找csv.zip压缩包,然后解压,读取解压文件,然后删除压缩包和数据文件。

每次运行前,需要下载好数据压缩包

from datetime import datetime, timedelta
import csv
import zipfile
import os# 生成打卡日期的timeList
def makeTimeList(start, end, timeList):temp = endwhile temp != start:# 转化为字符串格式,放入列表中timeList.append(datetime.strftime(temp, "%d-%b-%Y"))# 向前推一天temp = temp - timedelta(days=1)print(f"日历列表如下:\n{timeList}")print(f"打卡天数:\t{len(timeList)}")print(f"打卡开始日期:\t{timeList[len(timeList) - 1]}")print(f"打卡结束日期:\t{timeList[0]}")# 从文件一,读取名字list
def getName(root):# 读取第一个文件name,包含全部打卡人员名字with open(root + '\\name.txt', 'r', encoding='utf-8') as f1:name = f1.read()# 将字符串 name 切片成 listname = name.split()return name# 解压文件,返回解压后的数据文件路径
def zipFile(root):downloadpath = r'C:' + os.environ['HOMEPATH'] + r'\Downloads'  # 下载的压缩包所在路径# 遍历当前路径的文件列表for i in os.listdir(downloadpath):if '.csv.zip' in i:zippath = os.path.join(downloadpath, i)  # 压缩包文件名,拼接成路径break# 解压文件with zipfile.ZipFile(zippath, 'r') as zip:zip.extractall(downloadpath)  # 压缩包内文件全部解压到downloadpath目录# 压缩包解压后文件名,拼接成路径datafile = os.path.join(downloadpath, zip.namelist()[0])os.remove(zippath)return datafile# 读取数据文件,找到每天未打卡的名字
def FindName(notFindName, name, timeList):with open(datafile, 'r', encoding='utf-8') as f2:reader = csv.reader(f2)# 略过第一行各种标签行next(reader)# 一天未打卡人员名字,结果中包含所有名字,打卡的则从中剔除,剩下即为未打卡res = name[:]# 逐行遍历剩下的每行数据i = 0for row in reader:# 打印文件中的时间格式# print(row[2])# 找到对应的日期while timeList[i] not in row[2]:# 结果放入列表中,最后读入文件notFindName.append(res)#print(i, '  ', len(notFindName))# 下一天的打卡信息i += 1res = name[:]# 打卡的则从中剔除,剩下即为未打卡if row[11] in res:res.remove(row[11])# 输出最早的一天的结果加入notFindName.append(res)# print(len(notFindName))# 对未找到的名字,进行统计,返回统计的字典
def countNUm(dic, notFindName):for i in notFindName:for j in i:if j not in dic:dic[j] = 1else:dic[j] += 1# 按照字典值降序排列,次数为临时的字典,需要使用deepcopy, 或者返回赋值return {k: v for k, v in sorted(dic.items(), key=lambda item: item[1], reverse=True)}# 将结果输出到文件中
def outputToFileAndConsole(root, dic, timeList, notFindName):with open(root + '\\result.txt', 'w', encoding='utf-8') as f3:f3.write(f'打卡的总次数\t{len(timeList)}\n未打卡的统计次数\n')# 控制台输出print(f'打卡的总次数\t{len(timeList)}\n未打卡的统计次数\n', end='')# 逐行遍历日期列表timeListi = 0for key, value in dic.items():f3.write(f'{key}:\t{value}\t')print(f'{key}:\t{value}\t', end='')i += 1  # 控制输出格式5个输出一行if i % 5 == 0:f3.write(f'\n')print()f3.write(f'\n\n\n')print(f'\n\n\n', end='')print(len(timeList), len(notFindName))# 逐行遍历日期列表timeListfor i in range(len(timeList)):f3.write(f'{timeList[i]}未打卡人数:\t{len(notFindName[i])}\n{notFindName[i]}\n')print(f'{timeList[i]}未打卡人数:\t{len(notFindName[i])}\n{notFindName[i]}\n', end='')# 开始日期的前一天
start = datetime.strptime("20-Mar-2022", "%d-%b-%Y")
now = datetime.strftime(datetime.now(), "%d-%b-%Y")
# 重置结束日期为0点0分0秒
end = datetime.strptime(now, "%d-%b-%Y")
print(f'输出一下日期格式\n{start}\n{end}')
print(f'今天打卡日期:\t{now}')timeList = []
# 获取日期timelist
makeTimeList(start, end, timeList)
# 获取当前文件执行路径
root = os.getcwd()
# 解压后返回数据文件路径
datafile = zipFile(root)
# 从文件获取名字list
name = getName(root)
# 存放全部日期未打卡人员的名字,即每一天
notFindName = []
FindName(notFindName, name, timeList)
# 删除csv数据文件
os.remove(datafile)# 结果使用字典进行计数并输出
dic = {}
dic = countNUm(dic, notFindName)
outputToFileAndConsole(root, dic, timeList, notFindName)

Python对腾讯问卷进行打卡核对相关推荐

  1. 【python】使用pandas快速提取腾讯问卷信息,比对未填写的人员的名单

    前言背景 这几天的疫情,学校要求每个同学都要填写问卷. 于是我简单地创建了一个腾讯问卷. 今天辅导员让我统计下哪几位同学没有填写,并且告知以后每天都要统计. 我们班大约有40人, 每天填写问卷的人大约 ...

  2. 零基础学python图文版-如何快速创建投票页面 | 腾讯问卷怎么用_什么值得买

    Kim工房:如何快速创建投票页面?这颗"腾讯问卷"请吃下! 2018-01-11 19:50:10 28点赞 275收藏 7评论 序:微信群没有投票功能,QQ群投票又太简陋,想搞个 ...

  3. python刷新腾讯云cdn

    程序需要使用python3,使用前需获取腾讯云SecretID和SecretKey. # -*- coding:utf-8 -*- __author__ = 'wx' import hashlib i ...

  4. 【python】自动填写问卷星问卷及提交

    前言:问卷是很好的网络调查方式之一,近年来,问卷星被广泛应用于各方面的调查.本文介绍了利用python代码自动填写问卷星基本题目,拥有自动填写.解决智能验证.批量提交问卷等功能. 目录 1.下载浏览器 ...

  5. 微信公众号文章添加腾讯问卷的方法

    公众号无需认证即可在文章内添加问卷链接了 首先在腾讯问卷创建好问卷,生成访问链接 https://wj.qq.com/s2/12343928/1a23/ 回到公众号文章,找到文章上方的添加小程序 页面 ...

  6. 腾讯视频VIP周卡深圳地区免费领!附非深圳免费领腾讯视频会员攻略

    深圳今天开始,暂停了所有公共交通,小区开始封闭管理,大家都居家办公,腾讯官方今天给深圳地区用户免费发放7天腾讯视频VIP会员,居家期间,可以追剧了! 这是腾讯官方给深圳地区的抗疫福利,小编刚领取成功了 ...

  7. 2020年度总结-送你一张腾讯视频VIP月卡

    文章目录 回首2020 寄语2030 福利抽奖 回首2020 2020对我来说绝对是具有纪念意义的一年,因为这一年我开始了写博客,而一切也因此变得不一样. 万事开头难.第一次看见周围的人写博客,是@j ...

  8. 使用python自动提交调查问卷

    使用python自动提交调查问卷 创建问卷 写python脚本 跑程序 查看结果 创建问卷 用问卷星创建一个调查问卷,填完数据提交 然后用burpsuite抓取数据包: 发现submitdata参数是 ...

  9. 《微信公众号-腾讯问卷》01-如何创建问卷

    <微信公众号-腾讯问卷>01-如何创建问卷 一.关注腾讯问卷公众号 二.进入公众号,点击我的问卷 三.选择登录方式(QQ登录&微信登录)   注:QQ登录和微信登录后创建的问卷信息 ...

最新文章

  1. Linux命令中21个不太好搜索其含义的特殊符号你都知道吗?
  2. 数据库MYSQL学习系列三
  3. 建立TCP连接时的三次握手与四次挥手问题
  4. arduino 勘智k210_如何评价嘉楠耘智的勘智K210芯片?
  5. 4 文件操作 支持图片 视频 mp3 文本等
  6. 计算机网络运输层习题5-17
  7. dw网页设计作品_UI设计需要学习哪些软件 如何成为高薪UI设计师
  8. [HDU 4842]--过河(dp+状态压缩)
  9. 学习WPF——WPF布局——了解布局容器
  10. 超实用!SKETCH大师最常用的3个实战小技巧
  11. wordpress 调用css,WordPress折腾记-精简CSS及JS在插件中的调用
  12. [postgresql]postgresql自定义函数查询ETL作业依赖的实例
  13. java scjp 试题_SCJP(JAVA)试题一套!求答案...
  14. PR Lumetri颜色
  15. 64位Linux下安装iNode客户端
  16. 大学物理公式和名词整理
  17. 商业分析的50个网站和分析方法
  18. 不伤眼睛的文字背景色
  19. 企业使用Windows Sysprep工具来封装Win10、Win11操作系统(最新最全)
  20. 巨潮网站爬虫程序修改

热门文章

  1. 微机原理与汇编--输入n个数进行排序并输出
  2. scratch实现抛物线效果
  3. Linux小技巧:cat file 和 EOF 的妙用
  4. node作为中间层进行前后端分离
  5. ThinkPadE470 win10系统没有声音问题完美解决
  6. linux上运行记事本,推荐Linux下的“记事本”leafpad
  7. 织梦模板生成html页面,织梦模板制作html常用标签
  8. 响应式在线教育培训类网站织梦模板(自适应手机端)
  9. 【阿里天池赛题】2021年赛道一:医学影像报告异常检测
  10. Windows Binaries for Python Extension Packages