Camera.py idea

from discord import Webhook
import discord
import aiohttp
import asyncio
import cv2
import time
import datetime
import cv2 as cv

webhook_url = "Discdord Webhook URL"
 #カメラで撮影用 
camera = cv2.VideoCapture(0) 
ret,frame =camera.read()
motion_detected = False
if not ret:
	break
dt_now = datetime.datetime.now() #データを取得した時刻 

title="image"+str(dt_now)+".jpeg"
cv2.imwrite(title, frame)
print(title)
		
#メッセージの詳細 
username = "test"
title = (dt_now.strftime('%Y年%m月%d日 %H:%M:%S'))+ “認証に失敗しました”
description = "description"
color_hex = "ff0000"
image_path = "image"+str(dt_now)+".jpeg"
pathid = "image"+str(dt_now)+".jpeg"
		
#discordに画像を送信する 
file = discord.File(image_path, filename="image"+str(dt_now)+".jpeg")
embed = discord.Embed(
title=title, description=description, color=int(color_hex, 16)
).set_image(url="attachment://"+pathid)
async def foo():
	async with aiohttp.ClientSession() as session:
	webhookdata = Webhook.from_url(webhook_url, session=session)
	await webhookdata.send(username=username, embed=embed, file=file)
asyncio.run(foo())

key = cv2.waitKey(1)

if key == 27:
	break


camera.release()
cv2.destroyAllWindows()

いいなと思ったら応援しよう!