-
Notifications
You must be signed in to change notification settings - Fork 0
/
chuucar.py
41 lines (34 loc) ยท 1.32 KB
/
chuucar.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
import os
import json
import slack_sdk
import random
from slackclient import SlackClient
from datetime import date, datetime, timezone, timedelta
image_path = './image.json'
with open(image_path, 'r') as image_json:
image_array = json.load(image_json)
image_array = list(image_array)
num = random.randint(0, len(image_array)-1)
image = image_array[num]
slack_token = SlackClient(os.environ.get('SLACK_TOKEN'))
SLACK_CHANNEL = "#birthday"
json_path = './birthlist.json'
with open(json_path, 'r') as birth_json:
b_dict = json.load(birth_json)
def chuucar_send_msg(slack_msg):
# client = slack_sdk.WebClient(token=slack_token)
data = {
"attachments":[{
"image_url": image
}]
}
# client.chat_postMessage(channel=SLACK_CHANNEL,text=slack_msg, data=json.dumps(data))
slack_token.api_call("chat.postMessage", channel=SLACK_CHANNEL,text=slack_msg, data=json.dumps(data))
KST = timezone(timedelta(hours=9))
today=datetime.now(KST)
for key,val in b_dict.items():
date_of_birth = date(int(val[0:4]), int(val[4:6]), int(val[6:8]))
if today.month==date_of_birth.month and today.day == date_of_birth.day:
chat = "์ค๋์ ๋ฐ๋ก๋ฐ๋ก ๊ท์ฌ์ด ํด๋ฅ์ด, "+ key + "์ ์์ผ์
๋๋ค!"+" ๋ค๋ค ์๋ฆฌ์ง๋ฌ~!!"
# final = chat + random
chuucar_send_msg(chat)