This repository was archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslack_message.py
More file actions
54 lines (49 loc) · 1.33 KB
/
slack_message.py
File metadata and controls
54 lines (49 loc) · 1.33 KB
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
50
51
52
53
# A test file for testing Slack messages.
import json, requests
import datetime
current_date = datetime.datetime.today()
weeknumber = current_date.strftime("%U")
webhook_url = 'https://hooks.slack.com/services/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'
message_data = {
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "ZNY Statistics week #{0}".format(weeknumber)
}
},
{
"type": "section",
"block_id": "section567",
"text": {
"type": "mrkdwn",
"text": "*Member Data*\n:male-scientist: 113\tMembers \n :female-scientist: 13 \tVisitors. \n :man-woman-boy-boy: 12 \tMembers are marked as LOA."
},
"accessory": {
"type": "image",
"image_url": "https://image.prntscr.com/image/xkd5HTpdS7GEroH48mgyzA.png",
"alt_text": "Statistics Icon"
}
},
{
"type": "section",
"block_id": "section789",
"fields": [
{
"type": "mrkdwn",
"text": "*Staff Data*\n :guardsman: 6 \tSenior Staff \n :male_mage: 3 \tInstructors \n :male-teacher: 12\tMentors"
}
]
}
]
}
response = requests.post(
webhook_url, data=json.dumps(message_data),
headers={'Content-type':'application/json'}
)
if response.status_code != 200:
raise ValueError(
'Request to Slack returned an error %s, the response is:\n%s'
%(reponse.status_code, response.text)
)