Last active
June 14, 2016 10:27
-
-
Save niko86/3a010d75ea75c1f9029051e970c8a3be to your computer and use it in GitHub Desktop.
This file contains 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 re | |
pattern_guide_1 = (r'S\d{6}\Z', 'Input project number >> ') | |
pattern_guide_2 = (r'\A[123]{1}\Z', 'Input selection number >> ') | |
ds = ['DS/Envirocheck', 'DS/Photos'] | |
si = ['SI/Photos'] | |
jobs = { | |
'1': ds, | |
'2': si, | |
'3': ds + si | |
} | |
def match(pattern, guide): | |
while True: | |
user = input(guide) | |
if re.match(pattern, user): | |
break | |
else: | |
print('Invalid input.') | |
return user | |
def mkdir(path, folder): | |
for entry in folder: | |
os.makedirs(os.path.join(path, entry), exist_ok=True) | |
def jobtype(choice, path): | |
try: | |
mkdir(path, jobs[choice]) | |
except KeyError: | |
print('no match') | |
if __name__ == '__main__': | |
job_no = match(*pattern_guide_1) | |
year = '201' + job_no[2] | |
zDrive = os.path.join('Z:', 'Z Drive', year, job_no) | |
print('\nEnter number corresponding to project type:', | |
'1 - Desk Study', | |
'2 - Site Investigation', | |
'3 - Desk Study and Site Investigation\n\n', | |
sep='\n') | |
job_choice = match(*pattern_guide_2) | |
jobtype(job_choice, zDrive) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment