-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.py
112 lines (106 loc) · 3.58 KB
/
clock.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
import argparse, datetime, random, time
import pytz
import json
from mastodon import Mastodon
parser = argparse.ArgumentParser(description="run Crontime")
parser.add_argument("env", help="Environment config", type=str)
args = parser.parse_args()
class chatbot:
def __init__(self,env_path):
env_json = json.load(open(env_path))
self.host = Mastodon(
access_token = env_json["host"]["token"],
api_base_url = env_json["host"]["domain"]
)
print("Run: __init__()")
def push(self,now_time,prefix=""):
time_str = now_time.strftime("%Y-%m-%d %H:%M:%S %z")
hour_int = int(now_time.strftime("%H"))
run_hour_int = hour_int
print(f"Bot.push({time_str})")
small_msg = "woof~"
large_msg = "WOOF!!!!!! WOOF!!!!!!\n"
if hour_int == 0:
woof_msg = F"[12AM midnight]\n"
elif hour_int == 12:
run_hour_int = run_hour_int - 12
woof_msg = F"[12PM noon]\n{large_msg}"
elif hour_int > 12:
run_hour_int = hour_int - 12
woof_msg = F"[{run_hour_int}PM]\n{large_msg}"
else:
woof_msg = F"[{hour_int}AM]\n"
while run_hour_int > 0:
run_hour_int = run_hour_int - 4
if run_hour_int > 0:
woof_msg = woof_msg + small_msg * 4 + "\n"
else:
woof_msg = woof_msg + small_msg * (4 + run_hour_int)
the_day_str = now_time.strftime("%Y-%m-%d")
random.seed(the_day_str)
magic_int = random.choice(range(8,23))
ear_list = [
"V{}V",
"▼{}▼",
"U{}U",
"◖{}◗",
"(◖{})",
"(V{})",
"(▼{})",
"(U{})",
"({}V)",
"({}▼)",
"({}U)",
"({}◗)"
]
face_list = [
" ʘ ᴥ ʘ ",
" ● ᴥ ● ",
" ・ᴥ・ ",
" ´ ꓃ ` ",
" ^ ェ ^ ",
"´• ﻌ •`",
" ^ ᴥ ^ ",
" - ᴥ - ",
" ⁰ ᴥ ⁰ ",
" ❍ ᴥ ❍ ",
" ⚆ ᴥ ⚆ ",
" ◕ ᴥ ◕ ",
" ・ ᴥ ・ ",
]
random.seed(the_day_str)
ear_str = random.choice(ear_list)
face_str = random.choice(face_list)
emoji_msg = ear_str.format(face_str)
print(F"Hour number: {hour_int}")
print(F"Magic number: {magic_int}")
print(F"Woof msg: {woof_msg}")
print(F"Emoji msg: {emoji_msg}")
if hour_int == 0:
self.host.status_post(prefix+woof_msg+F"\nMagic number: {magic_int}", visibility="public", spoiler_text="Magic are finding their way today! Woof!")
elif hour_int == magic_int:
self.host.status_post(prefix+woof_msg, visibility="public", spoiler_text=emoji_msg)
else:
self.host.status_post(prefix+woof_msg, visibility="public")
time.sleep(1)
Bot = chatbot(args.env)
run = True
while run:
now_time = datetime.datetime.now(pytz.timezone('Asia/Singapore'))
time_str = now_time.strftime("%Y-%m-%d %H:%M:%S %z")
min_int = int(now_time.strftime("%M"))
if min_int == 0:
print(time_str)
Bot.push(now_time)
run = False
elif min_int < 50:
print(time_str)
Bot.push(now_time,prefix="> #DELAYED <\n")
run = False
elif min_int >= 50 and min_int < 58:
print(f"[{time_str}] Countdown 60s")
time.sleep(60)
else:
print(f"[{time_str}] Countdown 5s")
time.sleep(5)