-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
49 lines (36 loc) · 1.39 KB
/
bot.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
import re
import os
import json
from dotenv import load_dotenv
from discord_webhook import DiscordWebhook, DiscordEmbed
from time import sleep
load_dotenv()
Webhook_URL = os.getenv("WEBHOOK_URL")
city = os.getenv("CITY")
Area = os.getenv("AREA")
with open('file.json', mode='r', encoding='UTF8') as jfile:
jdate1 = json.load(jfile)
ggg = re.sub(r"(\d)$", "\\1級", jdate1["1"]).replace("-", "弱").replace("+", "強")
sec = int(jdate1["2"]) + 2
webhook = DiscordWebhook(url=Webhook_URL, username="地牛Wake UP!",
avatar_url="https://cdn.discordapp.com/attachments/825307887219114034/902494942352519168/FB_IMG_1635241955969.jpg",
content=f'倒數{sec}秒抵達!')
embed = DiscordEmbed(title=':rotating_light:【地震速報】', description='慎防搖晃(預估震度)', color='03b2f8')
embed.set_author(name='Taiwan EEW System',
icon_url='https://media.discordapp.net/attachments/345147297539162115/732527807435112478/EEW.png')
embed.set_timestamp()
embed.add_embed_field(name=f"{city}", value=f"{Area} {ggg}")
webhook.add_embed(embed)
sent_webhook = webhook.execute()
sec1 = int(sec)
aaa = sent_webhook
while sec1:
sec1 = sec1 - 1
sleep(0.6)
webhook.content = f'倒數{sec1}秒後到達!'
sent_webhook = webhook.edit(aaa)
if sec1 == 0:
sleep(0.6)
webhook.content = f'已抵達!'
sent_webhook = webhook.edit(aaa)
break