Cursor(AI)で定期的にスクショ撮ってDiscordにアップロードするスクリプト書いた
from mss import mss
def capture_screenshot(filename='screenshot.png'):
with mss() as sct:
sct.shot(output=filename)
import requests
import time,datetime
def send_to_discord(webhook_url, filename,message=""):
payload = {
'content': message
}
files = {
'file': (filename, open(filename, 'rb'), 'image/png')
}
response = requests.post(webhook_url, data=payload, files=files)
return response
import subprocess
while True:
if True:
result = subprocess.run("nvidia-smi", stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# Access the stdout and stderr
stdout_output = result.stdout
stderr_output = result.stderr
i=stdout_output.find("A100")
out=stdout_output[i-10:i+200]
print("%s/%s"%(stdout_output,stderr_output))
webhook="webhookのurl"
capture_screenshot()
print("send")
resp=send_to_discord(webhook,"screenshot.png",message=out)
print(resp)
time.sleep(60*5)
これで五分ごとにスクショが送られてくる。超便利。
世界中どこにいても、ターミナルが起動できなくても、マシンの稼働状態を把握したいので、監視カメラと各種IoTで温度管理などは最低限しているのだが、メモリの状態とかGPU温度とか気になるのでNVIDIA-SMIを実行して温度関係のところだけ抜き出して送るようにした。NVIDIA-SMIの全文を送ろうとしたけどそうすると長すぎてエラーになるのでこんなもんでいいだろう。
CursorはGithub Copilotを内蔵したエディタなので、呪文を打ち込むとそんな感じのコードを勝手に書いてくれる。Discordに画像投稿とかしたことなかったけど、一瞬で書いてくれたし、スクショの撮り方もよく知らなかったけど勝手にmssというモジュールをインストールしてインポートしてくれた。
マジでこの先、AIに対して欲望だけを説明すればあとはどうにかしてくれるようになるんじゃないかなあ。