def main(): """docstring""" LOG.debug('Started') with open(HTML_DIR + CDC_FILENAME, 'rU') as csv_file: LOG.info("Reading URLs from %s", HTML_DIR+CDC_FILENAME) reader = UnicodeReader(csv_file) # skip the header reader.next() for rec in reader: state = rec[STATE_INDEX] filename = state.replace(' ', '_') url = rec[URL_INDEX] LOG.info("Processing %s", state) # retrieve the webpage data webpage_data = get_info_on_webpage(url) # get the addresses from the local csv files csv_addresses = get_addresses_from_csv(CSV_DIR + filename + ".csv") unique_in_webpage = [rec for rec in webpage_data if normalize_address(rec[ADDRESS_INDEX]) not in csv_addresses] unique_in_webpage = sorted(unique_in_webpage, key=operator.itemgetter(CITY_INDEX)) try: with open(OUTPUT_DIR + filename + ".csv", "wb") as csv_f: writer = UnicodeWriter(csv_f) writer.writerows(unique_in_webpage) except UnicodeEncodeError as error: print "UnicodeEncode Error" LOG.debug('Finished')
def file_Write(self,outputList): with open('translated.csv', 'wb') as files: writer = UnicodeWriter(files,quoting=csv.QUOTE_ALL) writer.writerows(outputList)