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='\n')
f_new = open(pcffile, mode="w+", encoding='GBK',newline='\n') 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='\n')
f_new = open(flagfile, mode="w+", encoding='GBK',newline='\n') 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()

  

生成pcf文件的更多相关文章

  1. Android 解析XML文件和生成XML文件

    解析XML文件 public static void initXML(Context context) { //can't create in /data/media/0 because permis ...

  2. SQL*Plus生成html文件

    最近使用SQL*Plus命令生成html文件,遇到一些有意思的知识点,顺便记录一下,方便以后需要的时候而这些知识点又忘记而捉急.好记性不如烂笔头吗! 为什么要用SQL*Plus生成html文件?   ...

  3. vim保存文件时,生成.un~文件

    在用vim保存文件时,文件夹下生成.un~文件 怎么删除这些文件呢 在网上搜索的答案: http://stackoverflow.com/questions/15660669/what-is-a-un ...

  4. WPF根据Oracle数据库的表,生成CS文件小工具

    开发小工具的原因: 1.我们公司的开发是客户端用C#,服务端用Java,前后台在通讯交互的时候,会用到Oracle数据库的字段,因为服务器端有公司总经理开发的一个根据Oracle数据库的表生成的cla ...

  5. 简单生成svg文件

    this.fileSaveSync = function (file, data) { var fs = require('fs-extra'); fs.writeFileSync(file, dat ...

  6. 使用Free Spire.Presentation生成PowerPoint文件

      使用Free Spire.Presentation生成PowerPoint文件 前言 之前有写过一篇使用Free Spire.XLS生成图表的文章,朋友圈内反应还不错,都希望我能继续写下去,把类似 ...

  7. caffe的python接口学习(5):生成deploy文件

    如果要把训练好的模型拿来测试新的图片,那必须得要一个deploy.prototxt文件,这个文件实际上和test.prototxt文件差不多,只是头尾不相同而也.deploy文件没有第一层数据输入层, ...

  8. 利用 autoconf 和 automake 生成 Makefile 文件

    一.相关概念的介绍 什么是 Makefile?怎么书写 Makefile?竟然有工具可以自动生成 Makefile?怎么生成啊?开始的时候,我有这么多疑问,所以,必须得先把基本的概念搞个清楚. 1.M ...

  9. linux下使用automake工具自动生成makefile文件

    linux环境下,当项目工程很大的时候,编译的过程很复杂,所以需要使用make工具,自动进行编译安装,但是手写makefile文件比较复杂,所幸在GNU的计划中,设计出了一种叫做Autoconf/Au ...

随机推荐

  1. GeoIP简介与资源,定位经纬度,获取用户IP

    所谓GeoIP,就是通过来访者的IP,定位他的经纬度,国家/地区,省市,甚至街道等位置信息.这里面的技术不算难题,关键在于有个精准的数据库.有了准确的数据源就奇货可居赚点小钱,可是发扬合作精神,集体贡 ...

  2. [转载]sql server死锁

    SQL Server Deadlocks by Examplehttps://www.red-gate.com/simple-talk/sql/performance/sql-server-deadl ...

  3. react知识点总结(持续更新。。。)

    一.webpack 1. 什么是以及为什么要使用webpack 现在的网页功能越来越丰富,所需要的JavaScript和模块也会很多,为开发更加简洁,出现了以下方法,如模块化,scss,typescr ...

  4. Falcor 学习一基本使用

    falcor 是netflix 公司为了解决自己api数据查询所开发的查询框架,很不错(尽管netflix 也在用graphql )以下是falcor 的 一个简单使用,基于express 框架,使用 ...

  5. mknod

  6. Maven配置文件POM属性最全详解

    注:本文内容来源于: BlueKitty1210 <Maven配置文件POM属性最全详解> <project xmlns="http://maven.apache.org/ ...

  7. 发现Xilinx Virtex 5 FPGA中单个DSP乘法器只支持17位无符号乘法

    发现Xilinx Virtex 5 FPGA中,单个DSP乘法器只支持17位无符号乘法.如果令18位乘数相乘,结果会与正确的乘积不同.

  8. 关于finalize()

    finalize()是Object中的方法,当垃圾回收器将要回收对象所占内存之前被调用,即当一个对象被虚拟机宣告死亡时会先调用它finalize()方法,让此对象处理它生前的最后事情(这个对象可以趁这 ...

  9. Watcher监听

    可以设置观察的操作:exists,getChildren,getData 可以触发观察的操作:create,delete,setData   zookeeper观察机制; 服务端只存储事件的信息,客户 ...

  10. 记一次 HttpClient 死锁问题

    原文:http://blog.kail.xyz/post/2019-04-21/tools/httpclient-lock.html 最近遇到一个使用 Apache HttpClient 过程中的问题 ...