Last active
January 9, 2020 16:35
-
-
Save mrchrisadams/4360a645a9596f046876b6dd083ea19c to your computer and use it in GitHub Desktop.
Get an idea of the timezone distribution in a slack workspace
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
[[source]] | |
url = "https://pypi.org/simple" | |
verify_ssl = true | |
name = "pypi" | |
[packages] | |
slackclient = "*" | |
[dev-packages] | |
ipdb = "*" | |
[requires] | |
python_version = "3.6" |
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 | |
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