python自動建立每週週報模板

簡介

每週都須要寫週報,每次都須要複製週報模板,本身動手碼了一個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自動建立每週週報模板
相關文章
相關標籤/搜索