-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook_doer.py
36 lines (27 loc) · 1.11 KB
/
webhook_doer.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
from datetime import datetime, timedelta
import requests
from os import getenv
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
apiUrl = getenv("WEBHOOK_URL", "get a webhook URL from Slack")
todaysDate = datetime.today().strftime('%Y-%m-%d')
ninetySixDate = (datetime.today() - timedelta(days=(365.2422*28))).strftime('%Y-%m-%d')
description = "Today in Dilbert History for " + todaysDate + ": comic from " + ninetySixDate + " courtesy <https://dilbert.transglobal.world|Dilbert Website 2000>"
imageUrl = "https://dilberts.s3.amazonaws.com/" + ninetySixDate + ".gif"
check = requests.head(imageUrl)
if check.status_code != 200:
imageUrl = imageUrl[:-4] + ".jpg"
body = {}
body["blocks"] = []
textPart = {}
imagePart = {}
textPart["type"] = "section"
textPart["text"] = {}
textPart["text"]["type"] = "mrkdwn"
textPart["text"]["text"] = description
imagePart["type"] = "image"
imagePart["image_url"] = imageUrl
imagePart["alt_text"] = "Dilbert comic from " + ninetySixDate
body["blocks"].append(textPart)
body["blocks"].append(imagePart)
bot = requests.post(apiUrl, json=body, verify=False)