def log_event(worksheet, duration): now = datetime.fromtimestamp(time.time()).strftime(Constant.time_format_military) titles = worksheet.get_all_values()[0] titles_dict = dict() for i, title in enumerate(titles): titles_dict[title] = i + 1 next_row = G_API.get_next_available_row(worksheet, 1) worksheet.update_cell(next_row, titles_dict['Process'], Constant.process_name) worksheet.update_cell(next_row, titles_dict['Log By'], Constant.login_userid) worksheet.update_cell(next_row, titles_dict['Log Time'], now) worksheet.update_cell(next_row, titles_dict['Duration'], duration)
data_dict = Assign_SubTrade_Flag.assign_flag(data_dict) # ------------------------------------------------------------------------------------------------------------- # Extract the special 'menu value' list for POST request URL concatenation. menu_values = data_dict['menu_value'] # ------------------------------------------------------------------------------------------------------------- # Begin to push Ref: SubTrade update to each shipment. for i, subtrade_flag in enumerate(data_dict['subtrade_flag']): Post_Data.add_ref(session_requests, csrf, menu_values[i], Constant.menu_value_ref_type_subtrade, subtrade_flag) count += 1 print('SubTrade flag is added to ', count, ' number of shipments.') # ----------------------------------------------------------------------------------------------------------------- # Record the end time of this execution. end = time.time() # ----------------------------------------------------------------------------------------------------------------- # Create a log and upload it to Google Sheets. duration = end - start workbook_log = G_API.get_workbook_by_id(Constant.g_sheets_workbook_id_log) worksheet_log = G_API.get_worksheet_by_id( workbook_log, Constant.g_sheets_worksheet_id_log) Post_Data.log_event(worksheet_log, duration) # ----------------------------------------------------------------------------------------------------------------- # Hold the system from closing in 30 seconds. time.sleep(30) # save_file = open(Constant.root_path + 'test.html', 'w+') # save_file.write(html_script) # save_file.close()
import time if __name__ == '__main__': #START COUNTING RUNNING TIME start = time.time() #LOGIN TMS Get_Data.read_login_credentials() session_requests, csrf = Post_Data.login_tms() #READ GOOGLE SHEETS VALUE print('Loading Google Sheet...') workbook_cr = G_API.get_workbook_by_id(Constant.g_sheets_workbook_id_ops) worksheet_cr = G_API.get_worksheet_by_id( workbook_cr, Constant.g_sheets_worksheet_id_ops) sheet_values = G_API.get_values_in_list(worksheet_cr) sheet_values = G_API.convert_values_to_dict( sheet_values) #Convert value list to dictionary. for key, value_list in sheet_values.items(): sheet_values[key] = ','.join(value_list) assert sheet_values is not None, 'Error: Google Sheet is empty or reading failure.' print('Google Sheet loading completed.') for key, item in sheet_values.items(): #SET UP FILTER FOR REMOVE ASSIGNMENT BY CARRIER SCAC unassign_data_dict = Config_Post_Data.config_transport_ops_unassignment( csrf, item)