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. 实验3-1 求一元二次方程的根 (20 分) 《C语言程序设计实验与习题指导(第3版)》

    本题目要求一元二次方程的根,结果保留2位小数. 输入格式: 输入在一行中给出3个浮点系数a.b.c,中间用空格分开. 输出格式: 根据系数情况,输出不同结果: 1)如果方程有两个不相等的实数根,则每行 ...

  2. django小知识(1)

    聚合查询 关键字:aggregate from django.db.models import Max,Min,Count,Sum,Avg 分组查询 关键字:annotate 1.最简单的规律 mod ...

  3. python 比较2个文件内容

    1. 通过使用md5字符串比较2个文件 import hashlib def get_file_md5(filename): '''可以比较两个文件的md5值,来比较文件内容.未使用''' md5 = ...

  4. python + redis +ipset实现IP黑名单的动态添加及解封禁

    1.抽空用python做了一个 动态添加/删除IP黑名单 的程序(或者说实现方案),项目地址: https://gitee.com/lowmanisbusy/ip_blacklists, 2.这里的实 ...

  5. Mac OS X配置环境变量

    转载注明出处:http://www.jianshu.com/p/7e30b7b7ee48 Mac端环境变量配置 Mac使用bash做为默认的shell MAC OS X环境配置的加载顺序 # 系统级别 ...

  6. react native redux 草稿

    Provider > Provider > 使组件层级中的 方法都能够获得 Redux store.正常情况下,你的根组件应该嵌套在 Provider 中才能使用 方法. 如果你真的不想把 ...

  7. swift修饰符

    Declaration Modifiers Declaration modifiers are keywords or context-sensitive keywords that modify t ...

  8. [Algorithm] 136. Single Number

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  9. PipelineWise illustrates the power of Singer

    转自:https://www.stitchdata.com/blog/pipelinewise-singer/ Stitch is based on Singer, an open source st ...

  10. Reactive Extensions (Rx) 入门(1) —— Reactive Extensions 概要

    译文:https://blog.csdn.net/fangxing80/article/details/7381619 原文:http://www.atmarkit.co.jp/fdotnet/int ...