ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

每周跑一下Python脚本,轻松生成工作日志模板

2021-06-01 18:01:23  阅读:435  来源: 互联网

标签:-% outputfile Python datetime file print path 日志 模板


需求:

1.因为有要记录每天工作日志的需求,为了方便就写了个日志模板

2.已经实现打包,每周一 只需要跑一下脚本就行

3.其他需求同理

本人python学习萌新-这里贴一下一期版本源码-仅供学习-勿喷!

本人联系方式-微信:wvqusrtg

 一期版本源码-仅供学习:

import sys
import datetime


# 创建一个txt文件,文件名为mytxtfile
def text_create(name, path):
    desktop_path = path
    # 新创建的txt文件的存放路径
    full_path = desktop_path + name + '.txt'  # 也可以创建一个.doc的word文档
    file = open(full_path, 'w')
    filename = name
    # text_create(filename)
    output = sys.stdout
    outputfile = open(path + filename + '.txt', 'w')
    sys.stdout = outputfile

    for i in range(0, 7):
        timeStr = (datetime.datetime.now() + datetime.timedelta(days=i)).strftime("%Y-%m-%d %A")
        print('---------', timeStr, '---------', file=outputfile)
        print('---AM:', file=outputfile)
        print('项目:收单App 工作内容:收单App', file=outputfile)
        print('1.', file=outputfile)
        print('2.\n', file=outputfile)

        print('---PM:', file=outputfile)
        print('项目:收单App 工作内容:收单App', file=outputfile)
        print('1.', file=outputfile)
        print('2.\n', file=outputfile)

        print('---Night:', file=outputfile)
        print('项目:收单App 工作内容:收单App', file=outputfile)
        print('1.', file=outputfile)
        print('2.\n', file=outputfile)
    # close后才能看到写入的数据
    outputfile.close()


# print(datetime.datetime.now().strftime("%Y-%m-%d %A"))

begin = datetime.datetime.now().strftime("%Y-%m-%d")
end = (datetime.datetime.now() + datetime.timedelta(days=7)).strftime("%Y-%m-%d")
# print(begin, end)
print(f'---用途:生成工作日志模板')

target = f'{begin}---{end} 工作日志'
print(f'---生成文件标题如下: \n{target}.txt')

path = '/Users/nixinsheng/Documents/python3/PyCharm_HelloWorld/Demo20210201/'
print(f'---生成文件路径如下: \n{path}')

text_create(target, path)

 

标签:-%,outputfile,Python,datetime,file,print,path,日志,模板
来源: https://blog.51cto.com/u_4955660/2842787

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有