1
0

More than 1 year has passed since last update.

PythonでOutlookの予定表をキーワード検索してテキストで抽出(メールなどにコピペできる)

Last updated at Posted at 2021-11-03

困ってたこと

顧客とのアポなどので、Outlookの予定表に候補の予定を登録してから、
メールなどにチマチマと候補日程を書くという単純作業があまりに面倒だった。

解決策

Pythonのプログラムを作り、コマンドプロンプトからキーワードを入力して、
テキストでコピペできるようにした。
ちなみに、今日以降という条件も入れている。

環境

・Windows10

事前準備

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

pip install -U pypiwin32

動かすプログラム

schedule.py
import win32com.client, sys, datetime

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
calender = outlook.GetDefaultFolder(9).items
items = sorted(calender, key=lambda calendar:calendar.start)
now = datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=9)))
weekday_liset = ['月', '火', '水', '木', '金', '土', '日']
keyword = sys.argv[1]
extract_items = []

for item in items:
    if keyword in item.subject and item.start >= now:
            extract_items.append(item)

for extract_item in extract_items:
    print(extract_item.subject + ":" + extract_item.start.strftime("%Y/%m/%d(") + weekday_liset[extract_item.start.weekday()] + extract_item.start.strftime(") %H:%M") + "~" + extract_item.end.strftime("%H:%M"))

コマンドと結果の例

・schedule.pyはC:\Users\hoge-userに格納
・コマンドプロンプトで実行

C:\Users\hoge-user>python schedule.py hoge
hoge(調整中):2021/11/17(水) 14:00~14:30
hoge(調整中):2021/11/18(木) 14:30~15:30
hoge(調整中):2021/11/19(金) 10:30~11:30

・微妙にレスポンスが遅い気もする(仕方ないけど)。
・登録してから検索に引っかかるまで、若干タイムラグがあることも。

結果をコピーするための設定

・コマンドプロンプトのプロパティ
 簡易編集モードをチェック、行の折り返し選択を有効にするをチェックしない
image.png

コピペで完了

こんな感じで、矩形で選択してEnterでコピーできる。
image.png

ペーストして完了。
2021/11/17(水) 14:00~14:30
2021/11/18(木) 14:30~15:30
2021/11/19(金) 10:30~11:30

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

1
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
1
0