-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·80 lines (66 loc) · 2.56 KB
/
main.py
File metadata and controls
executable file
·80 lines (66 loc) · 2.56 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import requests
import json
from slacker import Slacker
import logging
import os
print('Loading function... ')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def to_markdown(channels):
header = u"""
# Introduction
[mohikanz](https://mohikanz.slack.com) は、[究極のIT系最新技術情報収集用Slackチーム公開 - モヒカンSlack -]()
にて紹介されているSlackチーム、mohikan から派生した雑談用 Slack チームです。
mohikanz はエンジニアがエンジニアリングのみならず、様々な話題についてわいわい話すことができるコミュニティです!
- 社内でエンジニアが少なくて情報共有ができない!
- エンジニアのコミュニティに入ってみたいけど何から手を付けたら良いかわからない!
と思っている人に、雑談からエンジニアのコミュニティへの入り口を提供しています。
入りたいと思った方はこちらへどうぞ!
https://mohikanz-invitation.herokuapp.com
# Slack Channel List
毎日 5 時に自動更新しています。
Name | Topic | Persons
----- | ----- | -------
"""
body = []
for c in channels:
elems = [
"[#%s](https://mohikanz.slack.com/messages/%s)" % (c["name"], c["name"]),
c["topic"]["value"],
str(c["num_members"])
]
elems = [e.replace("\n", "<br>") for e in elems]
body.append(" | ".join(elems))
return header + "\n".join(body)
def slack_channels():
slack = Slacker(SLACK_TOKEN)
response = slack.channels.list(exclude_archived=1)
channels = response.body['channels']
return channels
def edit_gist(content):
headers = {'Authorization': 'token %s' % GITHUB_TOKEN}
data= {
"description": "Channels list of the mohikanz Slack( https://mohikanz.slack.com )",
'files': {
'channels.md': {
'content': content
}
}
}
jdata = json.dumps(data)
res=requests.patch(ENDPOINT, jdata,headers=headers)
def handler(event, context):
# Get Global Value
global SLACK_TOKEN
global GIST_ID
global ENDPOINT
global GITHUB_TOKEN
SLACK_TOKEN = os.environ['SLACK_TOKEN']
GIST_ID = os.environ['GIST_ID']
ENDPOINT = 'https://api.github.com/gists/%s' % GIST_ID
GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
# 受信したjsonをLogsに出力
logging.info(json.dumps(event))
channels = slack_channels()
content = to_markdown(channels)
edit_gist(content)