Skip to content

hama-caffeine/stdin2chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

stdin2chat

やってること

標準入力で入ってきたテキストを
Google Chatに飛ばすってだけ。

用途

時間がかかるコマンドが終わったときに
手元に通知が来るのが欲しかったんで、
そんな感じでの用途を考えてます。

なので、

$ ls | python3 stdin2chat.py

って感じで、出力された内容をそのまま渡せば、
あらかじめ設定したチャットに
メッセージとして飛んできます。

既存のテキストファイルでも

$ cat exsample.txt | python3 stdin2chat.py

って感じで飛ばすことができます。

用意するもの

Google chatのWebhook

設定

webhookの値をご自身の環境のものに書き換えれば
使えるんじゃないかと

コード

'''
	input
		STDIN
	output
		Google Chat

	sample
		$ ls | python3 stdin2chat.py
'''
import sys
import textwrap
import requests
import json

# google chat Webhook
Webhook  = 'https://chat.googleapis.com/v1/spaces/xxxxxxxxxxxx/messages?key=xxxxxxxxxxxxxxxxxxxxxxxxxxx'

ChatText = textwrap.dedent('''
	```
	{StdinText}
	```
''').format(
	StdinText = sys.stdin.read().strip(), 
	).strip()

# Send Webhook
response = requests.post(
    Webhook,
    json={"text": ChatText}
)

これから

とりあえず動いてる状態での公開。
手元ではオプションで送信先をSlackや
別のサービスとかに飛ばせるようにしてるのがあるので、
きれいに書き直す時間ができたらそちらも公開しようかと。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages