运维开发网
广告位招商联系QQ:123077622
 
广告位招商联系QQ:123077622

python自动创建每周周报模板

运维开发网 https://www.qedev.com 2021-04-07 20:31 出处:51CTO 作者:喵来个鱼
通过Python自动创建每周周报模板。

简介

每周都需要写周报,每次都需要复制周报模板,自己动手码了一个Python自动复制周报模板的工具,按照年度归档文件夹

code

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Aiker Zhao
# @Date  : 2020/8/11 6:17 下午
# @File  : create_week_log.py
# @Desc  : 
import os
import time
import copyfile
from datetime import datetime
week_now = int(time.strftime('%W')) + 1

timenow=datetime.now().strftime('%Y-%m-%d %H:%M:%S')

theyear = str(datetime.today().year)
# print(theyear)
print(timenow + "" + " 本周是" + theyear +"年第" + str(week_now) + "周")

# print(week_now)
log_model = '周报模板.md'
log_file = str(week_now) + '周.md'

f_path = '/Users/Aiker/Documents/xxx/gitnote/xxx/周报/'

file_path = os.path.join(f_path, str(theyear))

if not os.path.exists(file_path):
    os.mkdir(file_path)
else:
    pass

if not os.path.isfile(os.path.join(file_path, log_file)):
    copyfile.copyFile(os.path.join(f_path, log_model), os.path.join(file_path, log_file))
    print("新的周报文件已经创建好了... ")
else:
    print("周报文件已经存在了哦,无需新建。")

创建计划任务

  • macos下的launch
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.create.weeklog.auto</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/Aiker/PycharmProjects/pacong3/venv/bin/python</string>
        <string>/Users/Aiker/PycharmProjects/pacong3/create_week_log.py</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/Users/Aiker/Documents/xxx/gitnote/xxx/周报/org.create.weeklog.auto.log</string>
    <key>StandardOutPath</key>
    <string>/Users/Aiker/Documents/xxx/gitnote/xxx/周报/org.create.weeklog.auto.log</string>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>9</integer>
        <key>Minute</key>
        <integer>10</integer>
    </dict>
</dict>
</plist>
  • 加载计划任务
    launchctl load ~/Library/LaunchAgents/org.create.weeklog.auto.plist

    python自动创建每周周报模板

  • 日志输出

    python自动创建每周周报模板

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号