Skip to content

Instantly share code, notes, and snippets.

@bcicen
Created January 27, 2015 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcicen/a76afeb0471defe15e9e to your computer and use it in GitHub Desktop.
Save bcicen/a76afeb0471defe15e9e to your computer and use it in GitHub Desktop.
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