Created
January 27, 2015 21:20
-
-
Save bcicen/a76afeb0471defe15e9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,json,logging | |
from slacker import Slacker | |
tokenfile = "~/work/tsm/.slacktoken" | |
token = open(os.path.expanduser(tokenfile), 'r').read().strip('\n') | |
logging.basicConfig(level=logging.WARN) | |
log = logging.getLogger() | |
slack = Slacker(token) | |
def get_unread(channel_id): | |
r = slack.channels.info(channel_id).body | |
try: | |
return r['channel']['unread_count'] | |
except KeyError: | |
return False | |
def main(): | |
r = slack.channels.list().body | |
for c in r['channels']: | |
unread = get_unread(c['id']) | |
if unread: | |
print('%d unread messages for channel %s' % \ | |
(unread,c['name'])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment