Skip to content

Instantly share code, notes, and snippets.

@dohvis
Created February 18, 2017 16:17
Show Gist options
  • Save dohvis/4d3a972f128d27cb62c7800f840d3ad6 to your computer and use it in GitHub Desktop.
Save dohvis/4d3a972f128d27cb62c7800f840d3ad6 to your computer and use it in GitHub Desktop.
from datetime import datetime
from requests import post
WEBHOOK_URL = ""
# Link: <https://alert-system.com/alerts/1234|Click here>
class Slack():
@staticmethod
def send(text, username="파트라슈", channel="#general", icon_emoji=":dog:"):
if channel[0] != '#':
print('Channel must be started #')
return None
if icon_emoji[0] != ':' and icon_emoji[-1] != ':':
print('Emoji has to between :')
return None
payload = {
"text": text,
"username": username,
"channel": channel,
"icon_emoji": icon_emoji,
}
return post(WEBHOOK_URL, json=payload).text
def get_remain_time_text(deadline):
remain_time = deadline - datetime.now()
days = remain_time.days
hours = int(remain_time.seconds / 3600)
minutes = int(remain_time.seconds / 60) - hours * 60
text = "{}일 {} 시간 {}분 남음".format(days, hours, minutes)
return text
def get_trello_card():
return "아직 얘기안끝난 것들"
if __name__ == "__main__":
deadline = datetime(year=2017, month=11, day=16, hour=14, minute=40)
text = get_remain_time_text(deadline)
print("resp: {}".format(Slack.send(text, channel="#bot_playground")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment