Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Last active January 9, 2020 16:35
Show Gist options
  • Save mrchrisadams/4360a645a9596f046876b6dd083ea19c to your computer and use it in GitHub Desktop.
Save mrchrisadams/4360a645a9596f046876b6dd083ea19c to your computer and use it in GitHub Desktop.
Get an idea of the timezone distribution in a slack workspace
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
slackclient = "*"
[dev-packages]
ipdb = "*"
[requires]
python_version = "3.6"
import os
import slack
import json
from collections import Counter
class TimezoneCounter:
def __init__(self):
self.members = []
# connect to the slack API
client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
# get a list of our users
res = client.users_list()
da = res.data
self.cat_members = da['members']
def members_by_timezone(self):
# set up a handy Counter dataStructure
cntr = Counter()
# pull out the timezones
timezones = [mem.get('tz') for mem in self.cat_members]
# make running totals of timezones
for tz in timezones:
cntr[tz] += 1
return cntr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment