SHARE
TWEET

Untitled

a guest Mar 19th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ExcelOutputService(BaseOutput):
  2.     def __init__(self, client):
  3.         BaseOutput.__init__(self, client)
  4.         self.output_path = os.path.join(os.path.abspath(os.sep), "output")
  5.         if not os.path.exists(self.output_path):
  6.             os.makedirs(self.output_path)
  7.         self.file_name = os.path.join(self.output_path, self.client + datetime.now().strftime("%Y%m%d_%H%M") + ".xlsx")
  8.         self.writer = pd.ExcelWriter(self.file_name, engine="xlsxwriter", options={'remove_timezone': True})
  9.  
  10.     def write_values(self, selection_set, table, field_map):
  11.         fields = dict([(f["source"], f["destination"]) for f in field_map])
  12.         ss_data = []
  13.         for feature in selection_set:
  14.             ss_data.append(feature.attributes)
  15.         df = pd.DataFrame(ss_data)
  16.         df = df.rename(columns=fields)
  17.         if df.empty:
  18.             df = pd.DataFrame(columns=[value for key, value in fields.items()])
  19.         df.to_excel(writer, table, index=False)
  20.  
  21.     def finalize(self):
  22.         self.writer.save()
  23.         self.writer.close()
  24.      
  25. def __init__(self, client):
  26.     ....
  27.     table_arrays = []
  28.  
  29. def finalize(self):
  30.     for item in table_arrays:
  31.         for worksheet, array in item.items():
  32.             #create the dataframes
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top