code: def output_to_csv(sources, csv_writeable_file):
      
      file_exists = os.path.isfile(csv_writeable_file)
  
      with open(csv_writeable_file, 'a') as csvfile:
          csv_dict = OrderedDict()
          csv_dict.update({'Time': time.strftime("%Y-%m-%d_%H:%M:%S")})
          summaries = [val for key, val in sources.items()]
          for summarie in summaries:
              csv_dict.update(summarie.source.get_sensors_summary())
  
          fieldnames = [key for key, val in csv_dict.items()]
          writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
  
          if not file_exists:
              writer.writeheader()  # file doesn't exist yet, write a header
          writer.writerow(csv_dict)
docs: Print statistics to csv file