def countyMapperMenu(caches): #Filters caches given by BC, then tries to assign them to a regional district of BC. #Menu to choose province print "Will search BC Caches and try to assign counties" #get caches in BC currently without a county (options, args, search) = Search.parse('-s "British Columbia" -O C', False) cacheList = Search.parseOptions(caches, options) #write these caches to a file filename = writeCountyMapper(cacheList) BCPolygons = ['BC/Alberni-Clayoquot.arc', 'BC/Bulkley-Nechako.arc', 'BC/Capital.arc', 'BC/Cariboo.arc', 'BC/Central Coast.arc', 'BC/Central Kootenay.arc', 'BC/Central Okanagan.arc', 'BC/Columbia-Shuswap.arc', 'BC/Comox Valley.arc', 'BC/Cowichan Valley.arc', 'BC/East Kootenay.arc', 'BC/Fraser Valley.arc', 'BC/Fraser-Fort George.arc', 'BC/Greater Vancouver.arc', 'BC/Kitimat-Stikine.arc', 'BC/Kootenay Boundary.arc', 'BC/Mount Waddington.arc', 'BC/Nanaimo.arc', 'BC/North Okanagan.arc', 'BC/Northern Rockies.arc', 'BC/Okanagan-Similkameen.arc', 'BC/Peace River.arc', 'BC/Powell River.arc', 'BC/Skeena-Queen Charlotte.arc', 'BC/Squamish-Lillooet.arc', 'BC/Stikine.arc', 'BC/Strathcona.arc', 'BC/Sunshine Coast.arc', 'BC/Thompson-Nicola.arc'] #call GPSBabel to filter these caches through each polygon, then remove temp files gcids = {} for polygonName in BCPolygons: callPolygonFilter(filename, polygonName, "test.out") gcids.update(readCountyMapper(os.path.join(os.getcwd(), 'test.out'), polygonName[3:-4])) os.remove("test.out") if len(gcids) > 0: log.info("%s has caches" %(polygonName[3:])) else: log.info("%s does not have caches" %(polygonName[3:])) os.remove(filename) #save county name to caches for cache in cacheList: if cache.gcid in gcids.keys(): cache.county = gcids[cache.gcid] else: log.error("%s was not found in a BC Regional District despite being in BC" %cache.gcid) return