0
0

More than 1 year has passed since last update.

PythonでOutlookの予定を登録できるようにした

Posted at

困ってたこと

Microsoft365のTodoというアプリの扱いに慣れないので、
Outlookの予定表にて、タスクを終日の予定として管理しているが、
タスクの登録をGUIで操作するのが面倒だった。

解決策

Pythonのプログラムを作り、コマンドプロンプトから登録できるようにした。

環境

・Windows11
・Python

事前準備

・Pythonのインストール(当たり前ですが)
・win32comのインストール
 コマンドプロンプトで次のコマンドを実行

pip install -U pypiwin32

動かすプログラム

add_task.py
import win32com.client, sys, datetime, re

outlook = win32com.client.Dispatch("Outlook.Application")
item = outlook.CreateItem(1)

if (len(sys.argv) == 3):
    if (re.match('^\d+$', sys.argv[2]) == None):
        print('number format error')
        exit()
    else:
        item.start = datetime.datetime.today() + datetime.timedelta(days=int(sys.argv[2]))
else:
    item.start = datetime.datetime.today()

item.subject = sys.argv[1]
item.allDayEvent = True
item.reminderSet = False
item.Save()
print(item.start.strftime('%Y/%m/%d') + ":" + item.subject + " is added")

コマンドでの使用

・引数1:タスク名

C:\Users\hoge>python add_task.py test
2022/02/15:test is added

・引数2:登録する日を今日から加算する日数(任意なので引数2がない場合は今日で登録)

C:\Users\hoge>python add_task.py test 1
2022/02/16:test is added

他により良い手段がありましたら、ぜひご教示ください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0