From b575daf430946167baf688e486503d69fe495c5a Mon Sep 17 00:00:00 2001 From: kd Date: Thu, 2 Jul 2020 14:54:55 -0400 Subject: updated with black and pyflakes run --- slack_parser.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'slack_parser.py') diff --git a/slack_parser.py b/slack_parser.py index 8756992..d99e7c2 100644 --- a/slack_parser.py +++ b/slack_parser.py @@ -2,17 +2,14 @@ import os import json import re import time -from jsonpath_ng import jsonpath, parse +from jsonpath_ng import parse # jsonpath match will match in order of appearence. # This mapping defines which position in the RESULT of match to look for which key. # so. eg. at 0th position (of the match) will be the key "text", etc. -key_orderings = { - "text": 0, - "ts": 1, - "name": 2 -} +key_orderings = {"text": 0, "ts": 1, "name": 2} + class SlackParser(object): @@ -39,7 +36,7 @@ class SlackParser(object): :returns: a sorted list of json files names for the channel """ - files = sorted(os.listdir( self.messagesDir )) + files = sorted(os.listdir(self.messagesDir)) return files def getUsers(self): @@ -54,7 +51,6 @@ class SlackParser(object): content = json.load(open(path)) return content - def buildUsersLibrary(self): """Docstring for buildUsersLibrary Build a Users dict that keeps only usersid to name mappings. @@ -107,7 +103,7 @@ class SlackParser(object): jsonpath_expression = parse("$.." + str(self.keys)) # search slackMessage for each key, and add all matches (incl. dups.) in-order match = jsonpath_expression.find(slackMessage) - #print(match[0]) + # print(match[0]) for key in self.keys: # TODO: validation for matches possible "index out of range" here. data[key] = match[key_orderings[key]].value @@ -115,11 +111,17 @@ class SlackParser(object): userIds = self.getUserIdsFromMessage(data["text"]) if userIds != []: # find corresponding usernames from library - userNamesinMessageDict = self.getUserNamesFromIds(self.usersLib, userIds) + userNamesinMessageDict = self.getUserNamesFromIds( + self.usersLib, userIds + ) # inject usernames in the text replace userid - data["text"] = self.replaceMessageUserIdsWithNames(userNamesinMessageDict, data["text"]) + data["text"] = self.replaceMessageUserIdsWithNames( + userNamesinMessageDict, data["text"] + ) # convert ts to a human readble time - data["ts"] = time.strftime( "%H:%M %b %d, %Y", time.localtime(float(data["ts"])) ) + data["ts"] = time.strftime( + "%H:%M %b %d, %Y", time.localtime(float(data["ts"])) + ) return data @@ -165,5 +167,9 @@ class SlackParser(object): """ for userId in messageUsersDict.keys(): - text = re.sub( "<@{}>".format(userId), "@{}".format(messageUsersDict[userId]), text ) + text = re.sub( + "<@{}>".format(userId), + "@{}".format(messageUsersDict[userId]), + text, + ) return text -- cgit v1.2.3