-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.py
46 lines (42 loc) · 1.21 KB
/
slack.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
import json
from pathlib import Path
def to_slack_json(post: str, post_file: Path, repo: str, base_repo: str):
return {
"text": post,
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": f"Daily Update for {repo}",
"emoji": True
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": post
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View on Github"
},
"url": f"{base_repo}{repo}/{post_file}"
}
]
}
]
}
def write_to_file(file_path, data):
with open(file_path, "w", encoding="utf-8") as file:
json.dump(data, file, ensure_ascii=False)