def record_log_file(self, path, log_tup, disk_space_warning_percentage): file_str = StringIO() csv_file_str = StringIO() file_str.write('Local Time, Latitude, Longitude, Altitude (ft.), ' 'Speed (mph), GPS Time (utc), Image File, Image ' 'Description, SMS Mobile Number, Email\n') line_str = ("%s, %f, %f, %f, %f, %s, %s, %s, '%s', %s\n" % (log_tup[0], log_tup[1], log_tup[2], log_tup[3], log_tup[4], log_tup[5], log_tup[6], log_tup[7], log_tup[8].replace("+44","(+44)"), log_tup[9])) file_str.write(line_str) csv_file_str.write(line_str) # Check destination path exists if it does check free-space is # greater that disk space warning percentage (default is 14%) # if it doesn't then remove the oldest file in path sfio = SnapshotFileIO(path, disk_space_warning_percentage, ".csv") if sfio.folder_exist(path) != True: sys.exit() if sfio.file_exist(path + "/" + time.strftime("%Y-%m-%d") + ".csv"): file_obj = open(path + "/" + time.strftime("%Y-%m-%d") + ".csv", "a") file_obj.write(csv_file_str.getvalue()) else: file_obj = open(path + "/" + time.strftime("%Y-%m-%d") + ".csv", "w") file_obj.write(file_str.getvalue()) file_obj.close
def record_log_file(self, path, log_tup, disk_space_warning_percentage): file_str = StringIO() csv_file_str = StringIO() file_str.write('Local Time, Latitude, Longitude, Altitude (ft.), ' 'Speed (mph), GPS Time (utc), Image File, Image ' 'Description, SMS Mobile Number, Email\n') line_str = ("%s, %f, %f, %f, %f, %s, %s, %s, '%s', %s\n" % (log_tup[0], log_tup[1], log_tup[2], log_tup[3], log_tup[4], log_tup[5], log_tup[6], log_tup[7], log_tup[8].replace("+44", "(+44)"), log_tup[9])) file_str.write(line_str) csv_file_str.write(line_str) # Check destination path exists if it does check free-space is # greater that disk space warning percentage (default is 14%) # if it doesn't then remove the oldest file in path sfio = SnapshotFileIO(path, disk_space_warning_percentage, ".csv") if sfio.folder_exist(path) != True: sys.exit() if sfio.file_exist(path + "/" + time.strftime("%Y-%m-%d") + ".csv"): file_obj = open(path + "/" + time.strftime("%Y-%m-%d") + ".csv", "a") file_obj.write(csv_file_str.getvalue()) else: file_obj = open(path + "/" + time.strftime("%Y-%m-%d") + ".csv", "w") file_obj.write(file_str.getvalue()) file_obj.close
def onAction(self, action): if action == ACTION_SELECT_ITEM: try: # Display waiting dialog (like hourglass) xbmc.executebuiltin("ActivateWindow(busydialog)") width = self.Dimensions(self.FetchResolution(self.image_resolution))[0] height = self.Dimensions(self.FetchResolution(self.image_resolution))[1] # Check destination path exists if it does check free-space is # greater that disk space warning percentage (default is 14%) # if it doesn't then remove the oldest file in path sfio = SnapshotFileIO(output_path, DISK_SPACE_WARNING_PERCENTAGE, ".jpg") if sfio.folder_exist(output_path) != True: self.message("Folder path '%s' does not exist!" % output_path, "Error Occurred!") sys.exit() # Fetch gps location if (self.gps_text_overlay_enabled == 'true') and (self.text_overlay_enabled == 'true'): self.lProgressUpdate.setLabel('Polling gps device ...') sgps = SnapshotGPS() gps_txt_tup = sgps.prepare_gps_socket() else: gps_txt_tup = ("*** NO GPS FIX! ***",); # Capture image self.lProgressUpdate.setLabel('Capturing image ...') sci = SnapshotCaptureImage() image_return_values = sci.capture_image(width, height, image_quality, output_path, self.gps_text_overlay_enabled, gps_txt_tup) image_full_path = image_return_values[0] filename = image_return_values[1] image_type = image_return_values[2] image_capture_method = image_return_values[3] if image_capture_method == 'raspistill': subject_new = email_subject.replace(")", " - Current User)") else: subject_new = email_subject.replace(")", " - SMS Request)") self.email_subject = subject_new # Add text overlay if self.text_overlay_enabled == 'true': self.lProgressUpdate.setLabel('Adding text overlay ...') self.add_text_overlay(str(image_full_path), self.gps_text_overlay_enabled, gps_txt_tup) self.imgSnapshot.setImage(image_full_path) # Send email with images as attachments if self.email_enabled == 'true': self.lProgressUpdate.setLabel('Sending email ...') sse = SnapshotSendEmail(False) if sse.send_email(self.email_to, self.email_from, self.username, self.password, self.smtp_server, self.smtp_server_port, self.email_subject, output_path, filename, image_full_path, image_type, gps_txt_tup) == True: self.message('Email sent succesully :)', 'Email Sent.') # Save to log file if self.log_enabled == 'true': import time self.lProgressUpdate.setLabel('Saving log file ...') if gps_txt_tup[0] == "*** NO GPS FIX! ***": log_tup = (gps_txt_tup[0], 0.0, 0.0, 0.0, 0.0, '', str(filename + "." + image_type), str(self.email_subject), '', str(self.email_to)); else: log_tup = (gps_txt_tup[0], float(gps_txt_tup[1]), float(gps_txt_tup[2]), float(gps_txt_tup[3]), float(gps_txt_tup[4]), str(gps_txt_tup[5]), str(filename + "." + image_type), str(self.email_subject), '', str(self.email_to)); slf = SnapshotLogFile() slf.record_log_file(output_path, log_tup, DISK_SPACE_WARNING_PERCENTAGE) time.sleep(1) except: self.message('Something wicked happened :( \n' + str(sys.exc_info()[0]), 'Error Occurred!') raise finally: self.lProgressUpdate.setLabel('') # Remove waiting dialog (like hourglass) xbmc.executebuiltin("Dialog.Close(busydialog)") if (action == ACTION_PREVIOUS_MENU or action == ACTION_NAV_BACK): #self.message('Goodbye', 'Exiting GPS') self.close()