/
parse_owners.py
35 lines (25 loc) · 1.17 KB
/
parse_owners.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#the re module is need for regex parsing
import re
#lists for the first and tag names are created by splitting the input strings
f_names = input['f_names'].split('**')[0].split('*')
t_names = input['t_names'].split('**')[0].split('*')
#dictionary is created to map first names to their corresponding tag names
mapping = dict(zip(f_names,t_names))
#the Slack message from Step 1 is stored
text = input['text']
#regex patterns are used to search for owner and SDR names
acc_owner = re.search('Account Owner:\s(\w*.\w*)\n',text)
acc_sdr = re.search('Account SDR:\s(\w*)\s\w*\n\n',text)
lead_owner = re.search('Lead Owner:\s(\w*.\w*)\n',text)
lead_sdr = re.search('Lead SDR:\s(\w*)\s\w*\n',text)
#list is created containing the search results
l_names = [acc_owner,acc_sdr, lead_owner, lead_sdr]
#the eventual Slack message is initialized
message = ""
#each search result is then assessed
for l in l_names:
#if the search result is not empty and the name found is not in the message already
if l != None and mapping[l.group(1)] not in message:
#append the name to message
message = message + "@" + mapping[l.group(1)] + " "
return {'message': message}