Skip to content

Instantly share code, notes, and snippets.

@cezarsa
Last active June 19, 2019 13:50
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 cezarsa/f61bcbb06bec8569596e634bc7abf9fc to your computer and use it in GitHub Desktop.
Save cezarsa/f61bcbb06bec8569596e634bc7abf9fc to your computer and use it in GitHub Desktop.
import os
from datetime import datetime, timedelta
import slack
import holidays
SLACK_TOKEN = os.environ.get('SLACK_TOKEN')
SLACK_USER = os.environ.get('SLACK_USER')
from_date = datetime.strptime('2019-01-01', '%Y-%m-%d')
to_date = datetime.strptime('2019-06-18', '%Y-%m-%d')
rj_holidays = holidays.Brazil(state='RJ')
def is_non_working_day(day):
return day.weekday() >= 5 or day in rj_holidays
ranges = []
cur_range = None
for n in range((to_date - from_date).days):
day = from_date + timedelta(days=n)
if is_non_working_day(day):
if cur_range is None:
cur_range = [day, day]
else:
cur_range[1] = day
elif cur_range is not None:
ranges.append(cur_range)
cur_range = None
client = slack.WebClient(token=SLACK_TOKEN)
for cur_range in ranges:
query = 'from:@{} after:{} before:{}'.format(
SLACK_USER,
(cur_range[0] + timedelta(days=-1)).strftime('%Y-%m-%d'),
(cur_range[1] + timedelta(days=1)).strftime('%Y-%m-%d'),
)
result = client.search_messages(query=query)
msgs_count = result.data.get('messages', {}).get('total')
if msgs_count > 0:
print("activity found on {} - {}: {} msgs".format(cur_range[0].strftime('%Y-%m-%d'), cur_range[1].strftime('%Y-%m-%d'), msgs_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment