-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_time.py
More file actions
71 lines (66 loc) · 2.98 KB
/
check_time.py
File metadata and controls
71 lines (66 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from datetime import datetime, date, timedelta, time
import time
import log
import json
import ohayo
import get_face
import random
import subprocess
from read import read
import requests
import wakeup
import pollen
last_date = date.today()
while True: #日付変更を検知
with open(f'data/goodmorning.json', 'r', encoding='utf-8') as f:
loadfiles = json.load(f)
current_date = date.today()
for LL in loadfiles:
target_datetime = datetime.strptime(LL["time"], '%Y-%m-%d-%H-%M')
#goodmorning.jsonファイルの"time"が今日の日付かつ"okita"が"False"の場合
if current_date == target_datetime.date() and LL["okita"] == "False":
print(f"日付変更,{last_date} → {current_date}")
last_date = current_date
now = datetime.now()
if now >= target_datetime:
print(target_datetime)
#おはよう関数
neteru=True
per = 10
while neteru==True:
aram=0
while aram < 1: ##鳴らす回数
subprocess.run(["mpg321", "data/Aram.mp3"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
aram+=1
if ohayo.question()==False: #不正解
filename=get_face.get_picture()
ohayo.printpicture(filename,per)
random_number = random.randint(1, 100)
print(random_number,random_number<=per)
if random_number<=per: #あたってしまう
current_time = datetime.now()
formatted_time = current_time.strftime("%H:%M")
with open(f'data/config.json', 'r', encoding='utf-8') as f:
loadconfigs = json.load(f)
webhook_url=loadconfigs["webhook"]
with open(filename, 'rb') as file:
files = {
"file": file
}
data = {
"content": f"{formatted_time}の寝顔 ({per}%)",
}
response = requests.post(webhook_url, data=data, files=files)
print(random_number,per,"送信済み")
per+=15
else: #正解
neteru=False
read("正解です")
read("おはようございます")
wakeup.goodMorning() #天気読み上げ
pollen.getPollen()
LL["okita"] = "True"
last_date = current_date
with open(f'data/goodmorning.json', 'w', encoding='utf-8') as f:
json.dump(loadfiles, f, ensure_ascii=False, indent=2)
time.sleep(3)