-
Notifications
You must be signed in to change notification settings - Fork 0
/
findIt.py
143 lines (137 loc) · 9.38 KB
/
findIt.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/python
import subprocess
import shutil
import time
import os
currentUser = os.getcwd()
userStart = currentUser.find("Users")
userEnd = currentUser.find("/", userStart + 6)
user = currentUser[userStart + 6:userEnd]
users = {"lheinle": ["Lexie", "Atom", r'/Applications/Atom.app/Contents/MacOS/Atom'], "seckles": ["Steph", "DreamWeaver", r'/Applications/Adobe Dreamweaver CC 2015/Adobe Dreamweaver CC 2015.app/Contents/MacOS/Dreamweaver'], "clipskey": ["Claire", "DreamWeaver", r'/Applications/Atom.app/Contents/MacOS/Atom'], "mlambie": ["Mitch", "Sublime Text", r'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2'] }
print("Hi, {} \n Let's start/edit an email project!".format(users[user][0]))
fileSite = input("Enter the file path (start from year and go to the production /) If you don't have it, type N: ")
projectNumber = input("Enter the project number: ")
newProject = input("Is this a new project? (Type y for yes): ")
finderWindow = input("Want to open a new Finder window? (Type y for yes): ")
if newProject.lower() != 'y':
sigs = input("Is it SIGS Time? (Type y for yes): ")
def brackIt(filePath):
serverPath = "/Volumes/marketing$/Creative Services/"
if filePath.lower() == 'n':
print("Let's find that file path!") #assumes 2016 email date
serverYear = "2016/"
mainDivision = input("Enter the main division.(i.e. NDS): ")
if os.path.isdir(serverPath + serverYear + mainDivision) == True:
print("Found the main division folder.")
else:
mainFolders = [] #list of inner divisions like i.e. MBLE_EP
for folder in os.listdir(serverPath + serverYear):
if os.path.isdir(serverPath + serverYear + folder) == True:
mainFolders.append(folder)
print("Sorry I couldn't find that main division folder.")
print("Your options are:")
for folder in mainFolders:
print("{:3}. {:4}".format(mainFolders.index(folder), folder))
mainChoice = int(input("Which main division folder do you want? (Type 1 for first) "))
mainDivision = mainFolders[mainChoice]
subDivision = input("Enter the sub division. (i.e. MBLE_EP): ")#need to search for correct project folder
if os.path.isdir(serverPath + serverYear + mainDivision + "/" + subDivision) == True:
print("Found the folder.")
#/Volumes/marketing$/Creative Services/2016/NBS/RenWeb
folderDirect = serverPath + serverYear + mainDivision + '/' + subDivision
for folder in os.listdir(folderDirect):
if folder[0:4] == projectNumber:
#/Volumes/marketing$/Creative Services/2016/NBS/RenWeb/6898_RenWeb_Power_Conference_Email_1/Design/Production/
filePath = serverYear + mainDivision + "/" + subDivision + "/" + folder + "/Design/Production/"
print(filePath)
if finderWindow.lower() == 'y':
subprocess.call(["open", "-R", serverPath + filePath])
else:
subFolders = [] #list of inner divisions like i.e. MBLE_EP
for folder in os.listdir(serverPath + serverYear + mainDivision):
if os.path.isdir(serverPath + serverYear + mainDivision + "/" + folder) == True:
subFolders.append(folder)
print("Sorry I couldn't find that inner division folder.")
print("Your options are:")
for folder in subFolders:
if folder[0:4] == projectNumber:
filePath = serverYear + mainDivision + "/" + folder + "/Design/Production/"
print("Just kidding I found it.")
break
else:
print("{:3}. {:4}".format(subFolders.index(folder), folder))
if filePath.lower() == 'n':
subChoice = int(input("Type the number of the sub division folder you want. "))
subDivision = subFolders[subChoice]
print(subDivision)
if os.path.isdir(serverPath + serverYear + mainDivision + "/" + subDivision) == True:
folderDirect = serverPath + serverYear + mainDivision + '/' + subDivision
print(folderDirect)
for folder in os.listdir(folderDirect):
if folder[0:4] == projectNumber:
#/Volumes/marketing$/Creative Services/2016/NBS/RenWeb/6898_RenWeb_Power_Conference_Email_1/Design/Production/
filePath = serverYear + mainDivision + "/" + subDivision + "/" + folder + "/Design/Production/"
print(filePath)
if finderWindow.lower() == 'y':
subprocess.call(["open", "-R", serverPath + filePath])
else:
filePath = filePath.replace("\\", "/") #take care of windows weirdness
fullFile = serverPath + filePath #add weird server path
print(fullFile)
startFileName = filePath.find(projectNumber)
endFileName = filePath.find("Design")
fileName = filePath[startFileName:endFileName - 1] #cuts from project number to title
programPath = users[user][2]
def newOne():
templates = {"MMA": "Interactive/Templates/Emails/Templates/MMA_Template508.html", "GreenOperational": "Interactive/Templates/Emails/Templates/Nelnet/Green-Operational-Template.html", "GreenWelcome": "Interactive/Templates/Emails/Templates/Nelnet/Green-Welcome-Template.html", "BluePromotional": "Interactive/Templates/Emails/Templates/Nelnet/Blue-Promotional-Template.html", "QM-BluePromotional": "Interactive/Templates/Emails/Templates/Nelnet/QM_Responsive_Blue-Promotional-Template.html", "QM-GreenOperational": "Interactive/Templates/Emails/Templates/Nelnet/QM_Responsive_Green-Operational-Template.html", "QM-GreenWelcome": "Interactive/Templates/Emails/Templates/Nelnet/QM_Responsive_Green-Welcome-Template.html"}
print("Your template options are: ")
for key in templates.keys():
print (key, sep=" | ")
templateChoice = input("Which template do you need? (Select via title): ")
templateFilePath = serverPath + templates[templateChoice]
newFilePath = fullFile + fileName +"_{}{}.html".format(time.strftime("%m"), time.strftime("%d"))
print("This is the new file you created:\n\n" + filePath + fileName + "_{}{}.html".format(time.strftime("%m"), time.strftime("%d")) ) #this is used for makeLive
shutil.copy(templateFilePath, newFilePath) #copy the template
subprocess.check_call(["open", "-a", programPath, newFilePath])
subprocess.check_call(["open", newFilePath]) #open html part
if finderWindow.lower() == 'y' and filePath.lower() != 'n':
subprocess.call(["open", "-R", serverPath + filePath])
if newProject.lower() == 'y':
newOne()
else:
htmlFiles = []
if os.path.isdir(fullFile) == True:
for file in os.listdir(fullFile):
if file.endswith(".html"):
htmlFiles.append(file)
print("Here are all the files in that folder...")
print (htmlFiles)
correctFile = eval(input("Select the file you need to edit by entering 1 for first: "))
numConvert = correctFile - 1 #adjust for zero based file location
print("Copying, moving and opening {}".format(htmlFiles[numConvert]))
baseStart = htmlFiles[numConvert].rfind("_")
baseTitle = htmlFiles[numConvert][:baseStart] #filename without Date
oldFilePath = serverPath + filePath + htmlFiles[numConvert]
if sigs.lower() == 'y':
newFilePath = fullFile + baseTitle +"_FIN.html"
print("This is the new file you created:\n\n" + filePath + baseTitle + "_FIN.html")
else:
newFilePath = fullFile + baseTitle +"_{}{}.html".format(time.strftime("%m"), time.strftime("%d"))
print("This is the new file you created:\n\n" + filePath + baseTitle + "_{}{}.html".format(time.strftime("%m"), time.strftime("%d"))) #this is used for makeLive
try:
shutil.copy(oldFilePath, newFilePath) #copy old file with new name
except shutil.SameFileError:
version = input("That file has already been created. Do you want to make version 2? ")
if version.lower() == 'y':
newFilePath = fullFile + baseTitle +"_{}{}v2.html".format(time.strftime("%m"), time.strftime("%d"))
print("This is the actual new file you created:\n\n" + filePath + baseTitle +"_{}{}v2.html".format(time.strftime("%m"), time.strftime("%d")))
shutil.copy(oldFilePath, newFilePath)
oldProd = filePath.replace("Production", "_oldProduction") #find old production folder path
shutil.move(oldFilePath, serverPath + oldProd + htmlFiles[numConvert]) #move old file to production
subprocess.check_call(["open", "-a", programPath, newFilePath]) #open html in text editor
subprocess.check_call(["open", newFilePath]) #open html file in browser
if finderWindow.lower() == 'y' and filePath.lower() != 'n':
subprocess.call(["open", "-R", serverPath + filePath])
print("\nThank you for using Lexie's findIt program. \n Any suggestions give Lexie a hollar!")
#things to add.... automatically get project number from path,
brackIt(fileSite)