Analyze Slack channel history by counting threads with specified keywords.
This small project contains two Python scripts:
- fetchHistory.py - fetches a Slack channel history and saves it to a json file.
- analyzeHistory.py - counts threads with specified keywords, aggregates those threads per month and renders them on a chart.
Example Slack channel history analyze with threads containing keywords such as Apple, Mango, Orange, etc.
- Python 3.9+
- python3 -m pip install -r requirements.txt
- Token from a Slack Application with
channels.history
scope. You can create the Slack Application to get this token, but then you need to install the App in the channel which you want to analyze.
python3 ./fetchHistory.py -token {token} -channel {channelID}
Where:
- {token} is a token from Slack App with permission to read channel history. With this token you should be able to run the following test method.
- {ChannelID} you can get from URL of Slack Web Client.
python3 ./analyzeHistory.py -threads '[{"name": "Apple", "keywords": ["apple", "green"], "color": "#008000", "debug": false}, {"name": "Mango", "keywords": ["mango", "yellow"], "color": "#FF0000"}]' -printUnmatchedThreads
-threads
parameter is a JSON list in which every element has to have name
and keywords
fields.
name
is a thread name and keywords
is a list of words which represent the thread.
If a Slack channel thread contains specified keyword, then counter of the corresponding thread is incremented.
The configuration from above command means that if in a Slack thread there is a word apple
or green
,
then number of Apple
threads is incremented.