Skip to content

Instantly share code, notes, and snippets.

@quanon
Last active February 13, 2019 05:35
Show Gist options
  • Save quanon/b3e3fcf74bd408e14ff7e20b9e496c3f to your computer and use it in GitHub Desktop.
Save quanon/b3e3fcf74bd408e14ff7e20b9e496c3f to your computer and use it in GitHub Desktop.
「Raspberry Pi 上で J-MOTTO にログインして打刻する Node.js スクリプト」を叩くための Slack Bot
from slackbot.bot import Bot
from slackbot.bot import listen_to
import subprocess
import daemon
def main():
bot = Bot()
bot.run()
@listen_to('(出社|退社)')
def kintai(message, kintai):
channel_info = message.channel._client.channels[message.body['channel']]
channel_name = channel_info['name']
if channel_name != 'kintai':
return
options = {'出社': '--kin', '退社': '--tai'}
message.send('打刻中...')
result = subprocess.check_output(f'cd /home/quanon/workspace/jmotto && node kintai.js {options[kintai]}', shell=True)
message.send(result.decode())
if __name__ == '__main__':
with daemon.DaemonContext():
main()
API_TOKEN = 'API トークンをここに入力する'
@quanon
Copy link
Author

quanon commented Feb 13, 2019

https://github.com/lins05/slackbot というライブラリを使っている。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment