-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_template.py
74 lines (68 loc) · 3.05 KB
/
message_template.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#############################################################################
#
# chief delphi slack bot
# message_template.py
# written by siddharth lohani
# june 17th, 2021
#
#############################################################################
from datetime import datetime
import requests
def createPayload(latest_technical_post):
data = {
"attachments": [
{
"color": "#c55100",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "[Technical] " + latest_technical_post["fancy_title"],
"emoji": True
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Created On:*\n " + datetime.fromisoformat(latest_technical_post["created_at"].replace('Z', '+00:00')).strftime('%B %d, %Y at %I:%M:%S %p')
},
{
"type": "mrkdwn",
"text": "*Likes:*\n " + str(latest_technical_post["like_count"])
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Updated On:*\n " + datetime.fromisoformat(latest_technical_post["last_posted_at"].replace('Z', '+00:00')).strftime('%B %d, %Y at %I:%M:%S %p')
},
{
"type": "mrkdwn",
"text": "*Replies:*\n " + str(latest_technical_post["posts_count"]-1)
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Description:* " + latest_technical_post["excerpt"].replace('…', '...') + '<https://chiefdelphi.com/t/' + latest_technical_post["slug"] + "/" + str(latest_technical_post["id"]) + '|View More>'
},
"block_id": "text1"
},
]
}
]
}
return data
def test_data():
assert createPayload(requests.get("https://www.chiefdelphi.com/c/technical/9/l/latest.json").json()['topic_list']['topics'][1])