When sharing an error that occurred when installing a ruby gem created by a friend in the laboratory on my machine, I found it troublesome to take a picture of the screen with a smartphone and share it on line. So I decided to create this.
Notes on posting messages from python via Discord webhook
Refer to here and post the image to discord using api.
At the terminal
$ screencapture -i -x ~/screenshot/test.png
Now you can specify the capture range yourself and save it as test.png in the specified folder without the shutter sound.
ss.py
import json
import requests
import os
path = "{0}/tmp.png ".format(os.environ['HOME'])
os.system(f"screencapture -i -x {path}")
WEBHOOK_URL = "your webhook url"
#Image attachment
with open(path, 'rb') as f:
file_bin = f.read()
files_qiita = {
"ss": ("tmp.png ", file_bin),
}
res = requests.post(WEBHOOK_URL, files=files_qiita)
print(res.status_code)
os.system(f"rm {path}")
Set alias in fish config.
config.fish
alias ss='python3 ~/screenshot/ss.py'
Now I'm posting to the discord channel. With this, it is not possible to select and send a specific friend. For example, try to send an image to line's personal talk.
Recommended Posts