-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessenger.py
34 lines (21 loc) · 973 Bytes
/
messenger.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
from slacker import Slacker
import os
from datetime import datetime
class Messenger:
def __init__(self):
# TODO: handle token better
print("configuring messenger")
self.SLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]
self.slack = Slacker(self.SLACK_BOT_TOKEN)
print("configured messenger")
def post_message_to_channel(self, image):
message_template = "Beep boop soup ({:.2%}): {}"
current_date = datetime.now().date()
date = datetime.fromtimestamp(image.post_date).date()
if (date != current_date):
message_template = "Beep boop soup ({:.2%}) [However it was posted on " \
+ str(date) + "] : {}"
message = message_template.format(image.soup_confidence, image.url)
print(f"posting message to channel:\n\t {message}")
self.slack.chat.post_message('#soup-bot', message, username="soup-bot")
image.posted = 1