slackに○○まで後××日ですってつぶやくpyslackはpipか,easy_installでインストールしてください.一日一回のcronの設定もしてください. tokenと.CuckooClockの設定はzipのサンプルを参考にしてください codeslackCuckooClock.zip←右クリックで保存できます.#!/usr/bin/env python # -*- coding:utf-8 -*- from pyslack import SlackClient import datetime bot_username = 'CuckooClock' bot_icon_url = '' # icon_url def teamCuckooClock( teamname, slacktoken ): client = SlackClient( slacktoken ) today = datetime.date.today() fin = file( '%s.CuckooClock' % teamname, 'r' ) for line in fin: try: d = unicode( line.strip(), 'utf8') d = d.split(',') channel = d[0] thedaystr = d[1] message = d[2] theday = datetime.datetime.strptime( thedaystr, '%Y/%m/%d') theday = datetime.date( theday.year, theday.month, theday.day ) days = (theday-today).days if( days >= 0 and ( days < 10 or ( days < 30 and days % 5 == 0 ) or days % 10 == 0 ) ): message = message % (thedaystr, days ) client.chat_post_message( channel, message, username=bot_username, icon_url=bot_icon_url) except: pass fin.close() fin = file( 'token.csv', 'r' ) for line in fin: d = line.strip().split(',') try: teamCuckooClock( d[0], d[1] ) except: pass fin.close() 参考URL |