def main(myblob: func.InputStream): #Read the blob file from the blob storage lines = myblob.readlines() #Close off the file #transFile.close() #Tags for opening and closing name in transcipt charOpenName = '<v ' charCloseName = '>' #Create List of speakers speakerList = {} #What were the total words spoken totalWordsSpoken = 0 #Count 1 Dynamic count on not knowing who is in the call #As we count each line check on the speaker to see who it is, and count the number of words spoken for textLine in lines: #Lets make sure we decode the line from binary to text newTxtLine = textLine.decode('utf-8') #Check to see if its a spoken line if newTxtLine[:len(charOpenName)] == charOpenName: #We need to find the occurrence of the first closing tag closePos = newTxtLine.find(charCloseName) #If this is a spoken line, lets look for the persons name speakerName = newTxtLine[len(charOpenName):closePos] if speakerName not in speakerList: #Insert the new speaker and increment the line count by 1 speakerList[speakerName] = len( re.findall(r'\w+', newTxtLine[closePos:len(newTxtLine) - 4])) else: #if the speaker already exists we need to find the speaker and increment their line count speakerList[speakerName] += len( re.findall(r'\w+', newTxtLine[closePos:len(newTxtLine) - 4])) totalWordsSpoken += len( re.findall(r'\w+', newTxtLine[closePos:len(newTxtLine) - 4])) #TODO: Can we try and do something here that connects to the length of time people spoke. We would need to take line 1 for time taken, and then line 2 to determine who spoke. #Code to sort output sortedSpeakers = sorted(speakerList.items(), key=lambda x: x[1], reverse=True) print('Of the', totalWordsSpoken, 'words spoken.') #Output the speaker list for x in sortedSpeakers: print(str(x[0]), 'spoke', '{:.1%}'.format(x[1] / totalWordsSpoken), 'of the time.')
def main(req: func.HttpRequest, inputblob: func.InputStream, outputblob: func.Out[func.InputStream]) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') root = ET.Element('catalog') # root tag name root.text = '\n' # newline before the book element test = inputblob.readlines() #for filename in g.glob(path): # with open(filename) as f: #firstline = f.readlines(1) firstline = test[0].decode() tags = [word for line in firstline for word in line.split(',')] for line in test: line = line.decode() if '\n' in line: book = ET.SubElement(root, 'book') book.text = '\n' book.tail = '\n\n' # Split the line into a List. F1 = line.split(',') count = 0 for data in F1: tags1 = tags[count].strip() e = ET.SubElement(book, tags1.lower()) e.text = data.strip() e.tail = '\n' count += 1 # Display for debugging #ET.dump(root) # Include the root element to the tree and write the tree # to the file. tree = ET.ElementTree(root) #tree.write('C:/Users/xs54tso/VSCode/csvtoxml/InsertRecords.xml', encoding='utf-8', xml_declaration=True) #f.close() outputblob.set(ET.tostring(root)) name = req.params.get('name') if not name: try: req_body = req.get_json() except ValueError: pass else: name = req_body.get('name') if name: return func.HttpResponse( f"Hello, {name}. This HTTP triggered function executed successfully." ) else: return func.HttpResponse( "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", status_code=200)
def main(myblob: func.InputStream): logging.info(f"Python blob trigger function processed blob \n" f"Name: {myblob.name}\n" f"Blob Size: {myblob.length} bytes") # data = str(myblob.read(size=-1)) #logging.info(data) delete_record = False if "-delete" in myblob.name: delete_record = True logging.info( "----------------Delete Operations-----------------------") else: logging.info( "----------------Assigned Operations-----------------------") lines_data = myblob.readlines() total_operations = len(lines_data) logging.info("---------------Total Records are: " + str(len(lines_data)) + "---------------") completed_operation = 0 for obj in lines_data: try: obj = obj.decode().replace("\\n", "").replace("\\r", "") attributes = obj.split(",") attributes_len = len(attributes) if attributes_len >= 7: submittedcode = attributes[0] submittedid = attributes[1] clientid = 1 date = attributes[6] date_time_obj = datetime.strptime(date, "%m/%d/%Y") - datetime( 1900, 1, 1) time = attributes[7] (h, m, s) = time.split(':') seconds = int(h) * 3600 + int(m) * 60 + int(s) date_time_sec = date_time_obj.total_seconds() + seconds if submittedid and submittedcode: id = "--RFID:" + submittedid + "--CODE:" + submittedcode + "--" elif submittedid == "" and submittedcode: id = "--CODE:" + submittedcode + "--" elif submittedcode == "" and submittedid: id = "--RFID:" + submittedid else: id = "" tag_obj = {} tag_obj['id'] = id tag_obj['status'] = 'assigned' tag_obj['clientid'] = clientid tag_obj['isDeleted'] = 0 tag_obj['description'] = "" tag_obj['datetime'] = str(int(date_time_sec)) # scan = {} # scan["id"] = 0 # scan['scannedby'] = scannedby # scan['datetime'] = str(int(round(time.time() * 1000))) # scan['ip'] = ip # scan['LatLocation'] = LatLocation # scan['LonLocation'] = LonLocation # scan['distance'] = distance # scan['mph'] = 0 # scans_array = list() # scans_array.append(scan) tag_obj["scans"] = [] already_obj = ReadTagContainerForBulk(id) if delete_record: response = DeleteTagContainer(tag_obj["id"]) if not already_obj: logging.info("Object not exist " + id) elif response: completed_operation = completed_operation + 1 else: logging.info("Delete error with id: " + id) else: # response = CreateTagContainer(tag_obj) if (already_obj and "status" in already_obj and already_obj["status"] == "enroll"): logging.info( "Assignment error with id: " + id + " record already exist with enrolled status.") elif already_obj and "isDeleted" in already_obj and already_obj[ "isDeleted"] == 0: logging.info("Assignment error with id: " + id + " record already exist") elif already_obj and "isDeleted" in already_obj and already_obj[ "isDeleted"] == 1: response = UpdateTagContainer(tag_obj) if response: completed_operation = completed_operation + 1 else: logging.info("Assignment error with id: " + id) else: response = CreateTagContainer(tag_obj) if response: completed_operation = completed_operation + 1 else: logging.info("Assignment error with id: " + id) except Exception as ex: pass logging.info("Failed operations: " + str(total_operations - completed_operation))