首页 > 编程语言 > 详细

python自动创建每周周报模板

时间:2021-03-28 22:20:45      阅读:19      评论:0      收藏:0      [点我收藏+]
简介

每周都需要写周报,每次都需要复制周报模板,自己动手码了一个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/onedrive/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/onedrive/gitnote/wonders/周报/org.create.weeklog.auto.log</string>
    <key>StandardOutPath</key>
    <string>/Users/Aiker/Documents/onedrive/gitnote/wonders/周报/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自动创建每周周报模板

原文:https://blog.51cto.com/m51cto/2675484

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!