-
Notifications
You must be signed in to change notification settings - Fork 0
/
affiliationAutoGroupBuilder.py
executable file
·77 lines (59 loc) · 2.89 KB
/
affiliationAutoGroupBuilder.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
#!/usr/bin/env python
# Symplectice Elements provides functionality to create Auto Groups using metadata in Generic Organization Specific fields.
# We've allocated Generic01 through Generic09 for organizational affiliations. This script takes as input the affiliations.txt
# file generated by hrDataFeeder.py and creates the WHERE statements that Elements needs to assign those values to Auto Groups,
# which must be pasted into the Elements UI.
from os.path import join
from os import getcwd
from datetime import datetime
from shutil import copy2
afile = join(getcwd(), 'affiliations.txt') # affiliations text file output from hrDataFeeder.py
oldafile = join(getcwd(), 'affiliations-lastUpdated.txt') # affilitions from last time script was run
reportfile = join(getcwd(), 'affiliations-report.txt') # affiliation report including WHERE clause statements for addition to Elements
af = open(afile, 'r')
oldaf = open(oldafile, 'r')
report = open(reportfile, 'w')
# build list of current affiliations
current_affiliations = []
for line in af:
line = line.strip() # Remove newline characters
current_affiliations.append(line)
af.close()
# build list of existing affliations from last script execution
old_affiliations = []
for line in oldaf:
line = line.strip() # Remove newline characters
old_affiliations.append(line)
# diff old and current to find new affiliations to add and deprecated ones to remove
new_affiliations = []
for a in current_affiliations: # for each affiliation in the current file
if a not in old_affiliations: # determine if it is in the old affiliations. If not, it's new and needs to be added to Elements.
new_affiliations.append(a) # add to list for SQL generation further down
else:
old_affiliations.remove(a) # remove the affiliation from old list. Remaining affiliations are ones that should be removed from Elements.
# write out report
report.write('Affiliations Report for Symplectic Elements\n')
timestr = datetime.now().strftime("%Y-%m-%d %H:%M")
report.write(timestr + '\n\n')
# write out list of affiliations that are deprecated
if len(old_affiliations) > 0:
report.write('Deprecated Affiliations:\n')
for a in old_affiliations:
report.write(a + '\n')
print '\n\n'
else:
report.write('No Deprecated Affiliations.\n')
# write out list of newly discovered affiliations
if len(new_affiliations) > 0:
report.write('New Affiliations:\n')
for a in new_affiliations:
s = "(Generic01 = '%s') OR (Generic02 = '%s') OR (Generic03 = '%s') OR (Generic04 = '%s') OR (Generic05 = '%s') OR (Generic06 = '%s') OR (Generic07 = '%s') OR (Generic08 = '%s') OR (Generic09 = '%s')" % (a, a, a, a, a, a, a, a, a)
report.write(s + '\n')
print '\n\n'
else:
report.write('No New Affiliations.\n')
af.close()
oldaf.close()
report.close()
# copy new affiliations to existing affiliations so this works next time
copy2(afile, oldafile)