So I have a list that gets generated e.g. missingfromauthoratative and with that list I want to do two things. 1. Print the results on the screen and; 2. Write the results to a csv file.
With what I have it will do one or the other or sometimes a combination. The code below is what I have.
#Find what is missing or new
missingFromAuthoritative = dBase.execute('SELECT url, mapindex, mapname, layerid, layername FROM authoritative EXCEPT SELECT url, mapindex, mapname, layerid, layername FROM current;')
newToAuthoritative = dBase.execute('SELECT url, mapindex, mapname, layerid, layername FROM current EXCEPT SELECT url, mapindex, mapname, layerid, layername FROM authoritative;')
#Print missing services (-) and new services (+)
for missing in missingFromAuthoritative:
print '-', missing[0], '\n Map: ', missing[2], '\n Layer:', missing[4], '\n'
self.inconsistency += 1
outcsv = csv.writer(open('missing.csv', "wb"))
header = ("Map Service","Map Index","Data Frame","Layer ID","Layer Name")
outcsv.writerow(header)
outcsv.writerows(missingFromAuthoritative)
It also sometimes writes one row to the screen and the other three to the csv. This is what I want on the screen - MapServer Map: Layers Layer: Proposed Power Generation Sites - MapServer Map: Layers Layer: Existing Infrastructure - MapServer Map: Layers Layer: Existing Utility Sites - MapServer Map: Layers Layer: Existing Transmission Lines 4 inconsistencies found in 81.28 seconds.
and this is what I want in the csv Map Service Map Index Data Frame Layer ID Layer Name MapServer 0 Layers 0 Proposed Power Generation Sites MapServer 0 Layers 1 Existing Infrastructure MapServer 0 Layers 2 Existing Utility Sites MapServer 0 Layers 3 Existing Transmission Lines
I have no idea why putting them after the for iterator doesn't work. The only way to get wither to work is to comment the other out.
Thanks