Created
June 28, 2019 07:00
-
-
Save csghone/abfe286aa093b790ab1c74c14c5782cb to your computer and use it in GitHub Desktop.
Print Slack History for slack archive
This file contains hidden or 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 sys | |
| import json | |
| import datetime | |
| import math | |
| USER_FILE = sys.argv[1] # users.json | |
| CHANNEL_DIR = sys.argv[2] # folder of channel containing message jsons | |
| users = json.load(open(USER_FILE)) | |
| user_dict = dict([ (x["id"], x["name"]) for x in users]) | |
| for filename in os.listdir(CHANNEL_DIR): | |
| filepath = os.path.join(CHANNEL_DIR, filename) | |
| if not os.path.isfile(filepath): | |
| continue | |
| if not filename.endswith(".json"): | |
| continue | |
| data = json.load(open(filepath)) | |
| data = sorted(data, key=lambda x:x["ts"]) | |
| for item in data: | |
| if item.get("username") == "bot": | |
| continue | |
| if item.get("type") != "message": | |
| continue | |
| if not item.get("user", "").startswith("U"): | |
| continue | |
| if "_tick_data_verification_stats" in item["text"]: | |
| continue | |
| print(datetime.datetime.fromtimestamp(math.ceil(float(item["ts"]))), user_dict[item["user"]], ":", item["text"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment