-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMatcher.py
More file actions
74 lines (56 loc) · 2.32 KB
/
StringMatcher.py
File metadata and controls
74 lines (56 loc) · 2.32 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/python
## CODED in Python 3.7 ##
print ("\n+-----------+-----------+")
print (" String Match Automation \n by Mark Mon Monteros")
print ("+-----------+-----------+")
print (">> Coded in Python 3.7 <<\n")
import subprocess
import sys
import os
matchFile = subprocess.check_output("cat ~/Desktop/'Supply and Demand Tool.csv' | tr ' ' '_' | awk '{print$1}'", shell=True).split()
###ADD ROLE HERE
roles = "Application Support Engineer\\|"
roles += "Project Control Services Practitioner\\|"
roles += "Application Developer\\|"
roles += "Application Lead\\|"
roles += "Advance Application Engineer\\|"
roles += "Tester\\|"
roles += "Application Designer\\|"
roles += "Program/Project Manager\\|"
roles += "Mobilization Lead"
###USING DEMAND-UPSERT CSV FILE
shellCommand1 = "cat ~/Desktop/demand-upsert05042018.csv | awk -F \"\\\"*,\\\"*\" '{print$21 " " $22 " " $23 " " $24 " " $25 " " $26 " " $27}' "
shellCommand1 += "| grep -o 'R[0-9]*' | grep -v R$"
shellCommand2 = "cat ~/Desktop/demand-upsert05042018.csv | grep weeks "
shellCommand2 += "| grep -o " + "\"" + roles + "\""
shellCommand2 += " | tr ' ' '_'"
mainSourceCol1 = subprocess.check_output(shellCommand1, shell=True).split() #Assign RRD Column
mainSourceCol2 = subprocess.check_output(shellCommand2, shell=True).split() #Assign Role Column
###REDIRECTING OUTPUT TO DRAFT.CSV
path = "c:\\%HOMEPATH%\\Desktop\\"
with open("draft.csv", "w") as f:
print("Filename: ", path, file=f)
orig_stdout = sys.stdout
f = open("draft.csv", "w")
sys.stdout = f
for i in range(1,len(matchFile)):
for j in range(0,len(mainSourceCol1)):
if (matchFile[i]==mainSourceCol1[j]):
print(matchFile[i],mainSourceCol2[j])
sys.stdout = orig_stdout
f.close()
###FINAL OUTPUT FILE
fileName = input("Enter filename: ")
with open(fileName + ".csv", "w") as f:
print("Filename :", path, file=f)
orig_stdout = sys.stdout
f = open(fileName + ".csv", "w")
sys.stdout = f
print("RRD Name,Assigned Role")
sys.stdout = orig_stdout
f.close()
os.system("cat " + path + "draft.csv | tr 'b' ',' | tr -d \"'\" | cut -d , -f2,3 | tr -d ' ' | tr '_' ' ' >> " + path + fileName + ".csv")
os.system("rm " + path + "draft.csv")
print("\nSaving " + fileName + ".csv ...\n")
print(os.system("cat " + path + fileName + ".csv"))
os.system("start " + path + fileName + ".csv")