• 生成pcf文件


    import os
    import datetime
    import hashlib
    
    
    def checksum(filename):
        with open(filename, mode='rb') as f:
            d = hashlib.md5()
            while True:
                buf = f.read(128)
                if not buf:
                    break
                d.update(buf)
            return d.hexdigest()
    
    if __name__ == "__main__":
    
        week = int(datetime.date.today().strftime("%w"))
    
        if week in {6, 0}:
            print(week)
    
        nextdate = datetime.date.today() + datetime.timedelta(days=1)
        if week == 5:
            nextdate = datetime.date.today() + datetime.timedelta(days=3)
    
        PreTradingDay = datetime.date.today().strftime('%Y%m%d')
        TradingDay = nextdate.strftime('%Y%m%d')
    
        #PreTradingDay = '20191030'
        #TradingDay = '20191031'
    
        print(PreTradingDay)
        print(TradingDay)
    
        path = 'D:/data/pcf'
        template = 'fm006etfd20191104001.txt'
        pcftemp = os.path.join(path, template)
    
        template = 'fm006etfd20191104001.flg'
        flagtemp = os.path.join(path, template)
    
        pcfname = 'fm006etfd' + TradingDay +'001.txt'
        flagname = 'fm006etfd' + TradingDay + '001.flg'
    
        pcffile = os.path.join(path, pcfname)
        flagfile = os.path.join(path, flagname)
    
        print(pcffile)
        print(flagfile)
    
    
        f = open(pcftemp, mode='r', encoding='GBK',newline='
    ')
        f_new = open(pcffile, mode="w+", encoding='GBK',newline='
    ')
    
        for line in f:
            if '20191104' in line:
                line = line.replace('20191104', TradingDay)
                line = line.replace('20191101', PreTradingDay)
            f_new.write(line)
            f_new.flush()
        f.close()
        f_new.close()
    
        stat = os.stat(pcffile)
        FileName = pcfname
        FileDate = str(TradingDay)
        FileTime = str(datetime.datetime.fromtimestamp(stat.st_mtime).strftime("%H%M%S"))
        FileBytes = str(stat.st_size)
        CheckSum = checksum(pcffile)
    
        f = open(flagtemp, mode='r', encoding='GBK',newline='
    ')
        f_new = open(flagfile, mode="w+", encoding='GBK',newline='
    ')
    
        for line in f:
            if 'fm006etfd20191104001' in line:
                line = line.replace('fm006etfd20191104001.txt', FileName)
                line = line.replace('2945', FileBytes)
                line = line.replace('20191104', FileDate)
                line = line.replace('210000', FileTime)
                line = line.replace('5362833CC3437FEC33E69D0FD0287176', CheckSum)
                print(line)
    
            f_new.write(line)
            f_new.flush()
        f.close()
        f_new.close()
        
    

      

  • 相关阅读:
    PHP之Trait详解
    PHP中__call()方法与重载解析
    PHP Closure(闭包)类详解
    PHP 核心特性
    回调函数
    php的各种 I/O流 以及用法
    关于php的buffer(缓冲区)
    php的运行原理、cgi对比fastcgi以及php-cgi和php-fpm之间的联系区别
    低功耗设计入门(一)——低功耗设计目的与功耗的类型
    从CMOS到触发器(一)
  • 原文地址:https://www.cnblogs.com/timlong/p/11850920.html
Copyright © 2020-2023  润新知