Python 检测分钟级数据传输稳定性

该博客主要介绍了如何使用Python进行数据传输稳定性检测,包括遍历文件夹获取文件名并记录,以及设置断传续传的报警机制。
摘要由CSDN通过智能技术生成

 1. 遍历所有文件夹下的文件名,记录到文本中

from configparser import ConfigParser
import os, datetime, time


# % 读取配置文件
def LoadConfig():
    conf0 = ConfigParser()
    conf0.read("config.ini", encoding="utf-8")
    TxtPath0 = conf0["Folder"]["TxtPath"]
    ...
    return ...


# % 指定路径后,列表并排序
def listdir(path_list, list0):
    for file in os.listdir(path_list):
        file_path = os.path.join(path_list, file)
        list0[file] = get_FileCreateTime(file_path)
        # print("success")
    return list0


# 时间戳转化为时间
def TimeStampToTime(timestamp):
    timeStruct = time.localtime(timestamp)
    return time.strftime("%Y-%m-%d %H:%M:%S", timeStruct)


# 获取创建文件时间
def get_FileCreateTime(filePath):
    t = os.path.getmtime(filePath)
    return TimeStampToTime(t)


# 按日期排序
def SortFileByc(lists_sort, condition):
    # condition 0:按名称排序,condition 1:按日期排序
    orderlist = sorted(lists_sort.items(), key=lambda array: array[condition], reverse=True)
    # https://docs.python.org/3/howto/sorting.html
    # print("调试:%s" % orderlist)
    return orderlist


# 按创建时间排序
def DispSortLists(path, condition):
    # del lists
    lists1 = {}
    listdir(path, lists1)
    lists1.items()
    FileLists2 = SortFileByc(lists1, condition)
    return FileLists2


def initial_flag(TxtPath2, FileName):
    # 记录日志并留存
    if not os.path.exists(".\\cache\\"):
        os.mkdir(".\\cache\\")
    with open(".\\cache\\"  + "AllItemLists.txt", "a", encoding='GBK') as fid0:
        fid0.write(FileName+"\n")
        fid0.close()
    # with open("cache", "a", encoding='utf-8') as fid0:
    #     texture = message + " 0\n"
    #     # texture11 = "夏靖杰 "
    #     fid0.write(texture)
    #     fid0.flush()


if __name__ == "__main__":
    TxtPath... = LoadConfig()
    DurationTh = eval(Duration)
    # 获取当前文件夹中的所有文件
    lists = {}
    RadarFileList = eval(RadarFileName)

    # with open("cache.ini", 'w+') as file:
    #    清空文件内容
    #     file.truncate(0)
    # 开始大规模遍历
    for Subpath in RadarFileList:
#   1
        initial_flag(TxtPath, Subpath)

        #  ---进入 /Z9002/  内 FileLists1 = ‘20210906’、‘20210907’...
        path1 = MainPath + "radarProductsStore\\" + Subpath
        FileLists1 = DispSortLists(path1, 0)
        # 选择最新的文件夹扫描,避免世界时和本地时不同步问题
        DateFolder = FileLists1[0][0]
#   2
        initial_flag(TxtPath, Subpath+"_"+DateFolder)

        path2 = path1 + "\\" + InitialTime
        # ---进入 /Z9002/20210907/ 开始遍历 FileLists2 = 'CAR-110','R-020'...
        # temp = DispSortLists(path2, lists)
        FileLists2 = [x[0] for x in DispSortLists(path2, 0)]

        # print(FileLists2)
        # ---对FileLists2[]循环遍历 'V-027', 'R-020', 'CAR-110'
        for FileTemp1 in FileLists2:
#   3
            initial_flag(TxtPath, Subpath + "_" + DateFolder + "_" + FileTemp1)

            path3 = path2 + "\\" + FileTemp1
            # ---对CAR-110内的, E1...
            FileLists3 = [x[0] for x in DispSortLists(path3, 0)]
            # 列表
            for FileTemp2 in FileLists3:
#   4
                initial_flag(TxtPath, Subpath + "_" + DateFolder + "_" + FileTemp1 + "_" + FileTemp2)

            # --- 对E1内要监控文件
                NowTimeStr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    # WT = int(WaitTime)
    # print("%ds后窗口自动关闭..." % WT)
    # # WT = 10
    # time.sleep(int(WT))
    # 留给ftp WT s时间传输文件

2. 断传续传报警

#!/usr/bin/python
# -*- coding:utf-8 -*-

# pyinstaller --onefile -p.\dll -F -w -c main.py
# 配置文件问题 notepad++编码选utf-8 保存即可


from configparser import ConfigParser
import os, datetime, time


# % 读取配置文件
def LoadConfig():
    conf = ConfigParser()
    conf.read("config.ini",encoding="utf-8")
    TxtPath0 = conf["Folder"]["TxtPath"]
...
    # print("success")
    return TxtPath0...


# 根据Allitemlist生成缓存
def CreateCache(NowTimeStr):
    # 记录日志并留存
    f = open(".\\cache\\AllItemLists.txt")  # 返回一个文件对象
    line = f.readline()  # 调用文件的 readline()方法
    idx = 0
    while line and idx < 2:
        idx = idx + 1
        da
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值