#python #cron #raspberry-pi #discord
#питон #крон #малина-пи #Discord
Вопрос:
я запланировал выполнение задания cron при перезапуске в raspberry pi (ОС twister)
@reboot python3 /bin/temperature_.py
вот мой рабочий сценарий :
import subprocess from datetime import datetime from discord_webhooks import DiscordWebhooks import time def send_notification(): with open(r"/home/pi/Documents/sharing/temperature.txt","a")as f: f.write(f'{datetime.now().strftime("%H:%M:%S")} : {subprocess.Popen("vcgencmd measure_temp", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()[0]}' "n") while True: send_notification() time.sleep(10)
но когда я добавляю webhook
import subprocess from datetime import datetime from discord_webhooks import DiscordWebhooks import time def send_notification(): webhook=DiscordWebhooks(webhook_url=r"") webhook.set_footer(text="--Abhimanyu Sharma") webhook.set_content(title="Temperature Report",description="Here's Your Report With :heart:") webhook.add_field(name="Temperature",value=f'{subprocess.Popen("vcgencmd measure_temp", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()[0]}') webhook.add_field(name="Time",value=f'{datetime.now().strftime("%H:%M:%S")}') webhook.send() with open(r"/home/pi/Documents/sharing/temperature.txt","a")as f: f.write(f'{datetime.now().strftime("%H:%M:%S")} : {subprocess.Popen("vcgencmd measure_temp", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()[0]}' "n") while True: send_notification() time.sleep(10)
задание cron не выполняется
я попытался добавить time.sleep(60)
в начале своего сценария, но это не сработало