Best Python code snippet using autotest_python
creating_line_data.py
Source:creating_line_data.py
1import requests2from linebot.creating_flex_messages import *3from linebot.creating_picture_for_line_notify import *4from linebot.save_data_to_db import *567class creating_line_data ():8 def send_notify(message, token):9 try:10 Token = 'Bearer ' + token11 LINE_ACCESS_TOKEN = Token12 url = 'https://notify-api.line.me/api/notify'13 headers = {'content-type': 'application/x-www-form-urlencoded',14 'Authorization': LINE_ACCESS_TOKEN}15 r = requests.post(url, headers=headers, data={'message': message})16 print(r.text)17 return True18 except requests.ConnectionError as err:19 print("Connected to Line notify fail")20 return False21 def send_notify_picture(path, token,message,site_profile):22 try:23 url = "https://notify-api.line.me/api/notify"24 file = {'imageFile':open(path,'rb')}25 data = ({'message': message,})26 path_opened = True27 except :28 path_opened = False29 datetime_now = datetime.datetime.now().strftime("%d.%m.%y %H:%M")30 print ('CAN NOT OPEN URL PATH FOR LINE PICTURE NOTIFY FOR MESSAGES {} ON {}'.format(message,datetime_now))31 if path_opened == True:32 LINE_HEADERS = {"Authorization":"Bearer "+token}33 session = requests.Session()34 r=session.post(url, headers=LINE_HEADERS, files=file, data=data)35 if r.status_code == 200 :36 datetime_now = datetime.datetime.now().strftime("%d.%m.%y %H:%M")37 print ('SUCCESS LINE LINE NOTIFY PICTURE FOR MESSAGES {} ON {}'.format(message,datetime_now))38 file_path = path39 os.remove(file_path)40 print ('REMOVED FILE SUCCESS FOR MESSAGES {} ON {}'.format(message,datetime_now))41 return True42 elif r.status_code != 200 :43 datetime_now = datetime.datetime.now().strftime("%d.%m.%y %H:%M")44 # save_data_to_db.SaveDataSendLineFailedToBD('LINE_NOTIFY',path,message,site_profile)45 print ('FAILED SEND LINE GO TO SAVE PICTURE FOR MESSAGES {} ON {}'.format(message,datetime_now))46 return True47 else:48 return None49 def Line_Creating_MWGT_OFFLINE (line_data,site_profile):50 result_site = site_profile[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 051 day_loss = line_data[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 052 hours_loss = line_data[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 153 minutes_loss = line_data[2] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 254 datetime_now = line_data[3] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 355 MWGT_last_time = line_data[4] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 456 messages_header = 'MWGT-OFFLINE : '+'สà¸à¸²à¸à¸µ : ' + str(result_site.station_name)57 path_save=creating_picture_for_line_notify.CreatingPictureForMWGT('MWGT',line_data,site_profile,'OFF-LINE') #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token58 result_notify=creating_line_data.send_notify_picture(path_save, result_site.team_support.line_notify_token,messages_header,site_profile)59 return creating_flex_messages.CreateNotifyFormMwgtOffline(line_data,site_profile) 60 def Line_Creating_MWGT_ONLINE (line_data,site_profile):61 result_site = site_profile[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 062 day_loss = line_data[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 063 hours_loss = line_data[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 164 minutes_loss = line_data[2] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 265 datetime_now = line_data[3] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 366 Error_start = line_data[4] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 467 messages_header = 'MWGT-ONLINE : '+'สà¸à¸²à¸à¸µ : ' + str(result_site.station_name)68 path_save=creating_picture_for_line_notify.CreatingPictureForMWGT('MWGT',line_data,site_profile[1],'ON-LINE') #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token69 result_notify=creating_line_data.send_notify_picture(path_save, result_site.team_support.line_notify_token,messages_header,site_profile)70 return creating_flex_messages.CreateNotifyFormMwgtOnline(line_data,site_profile) 71 def Line_Creating_VIS_OFFLINE (line_data,site_profile):72 result_site = site_profile # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 073 messages_header = 'VIS-OFFLINE : '+'สà¸à¸²à¸à¸µ : ' + str(result_site.site.station_name)74 path_save=creating_picture_for_line_notify.CreatingPictureForVis('VIS',line_data,site_profile,'OFF-LINE') #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token75 result_notify=creating_line_data.send_notify_picture(path_save, result_site.site.team_support.line_notify_token,messages_header,site_profile)76 return creating_flex_messages.CreateNotifyFormVisOffline(line_data,site_profile) 77 def Line_Creating_VIS_ONLINE (line_data,site_profile):78 result_site = site_profile[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 79 messages_header = 'VIS-ONLINE : '+'สà¸à¸²à¸à¸µ : ' + str(result_site.site.station_name)80 path_save=creating_picture_for_line_notify.CreatingPictureForVis('VIS',line_data,site_profile[1],'ON-LINE') #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token81 result_notify=creating_line_data.send_notify_picture(path_save, result_site.site.team_support.line_notify_token,messages_header,site_profile)82 return creating_flex_messages.CreateNotifyFormVisOnline(line_data,site_profile) 83 def Line_Creating_BATTERY_LOW (site_profile):84 result_site = site_profile # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 085 # day_loss = line_data[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 086 # hours_loss = line_data[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 187 # minutes_loss = line_data[2] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 288 # datetime_now = line_data[3] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 389 # Error_start = line_data[4] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 490 messages = 'BATTERY Status LOW ' + '\n' + \91 'Type : ' + ' Battery : LOW ' + '\n' \92 'สà¸à¸²à¸à¸µ : ' + result_site.site.station_name + '\n' + \93 'IP : ' + str(result_site.site.station_ip) + '\n' + \94 'Serial : ' + str(result_site.NOZZLE_SN) + '\n' + \95 'หà¸à¹à¸²à¸à¸µà¹ : ' + str(result_site.NOZZLE_pump_log_address) + '\n' + \96 'มืà¸à¸à¹à¸²à¸¢ : ' + str(result_site.NOZZLE_num) + '\n' + \97 'ระà¸à¸±à¸à¹à¸£à¸à¸à¸±à¸ : ' + str(result_site.NOZZLE_Battery_Status_Volts) + ' V.'+ '\n' \98 + 'à¸à¹à¸²à¸à¹à¸à¸ : ' + result_site.site.team_support.team_name99 messages_header = 'BATTERY : LOW '+'สà¸à¸²à¸à¸µ : ' + str(result_site.site.station_name)100 path_save=creating_picture_for_line_notify.CreatingPictureForBATTERY('LOW',result_site) #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token101 result_notify=creating_line_data.send_notify_picture(path_save, result_site.site.team_support.line_notify_token,messages_header,site_profile)102 return creating_flex_messages.CreateNotifyFormBatteryStatus('LOW',site_profile)103 def Line_Creating_BATTERY_FAILED (site_profile):104 result_site = site_profile # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 0105 # day_loss = line_data[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 0106 # hours_loss = line_data[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 1107 # minutes_loss = line_data[2] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 2108 # datetime_now = line_data[3] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 3109 # Error_start = line_data[4] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 4110 messages = 'BATTERY Status ALARM ' + '\n' + \111 'Type : ' + ' Battery : FAILED ' + '\n' \112 'สà¸à¸²à¸à¸µ : ' + result_site.site.station_name + '\n' + \113 'IP : ' + str(result_site.site.station_ip) + '\n' + \114 'Serial : ' + str(result_site.NOZZLE_SN) + '\n' + \115 'หà¸à¹à¸²à¸à¸µà¹ : ' + str(result_site.NOZZLE_pump_log_address) + '\n' + \116 'มืà¸à¸à¹à¸²à¸¢ : ' + str(result_site.NOZZLE_num) + '\n' + \117 'ระà¸à¸±à¸à¹à¸£à¸à¸à¸±à¸ : ' + str(result_site.NOZZLE_Battery_Status_Volts) + ' V.'+ '\n' \118 + 'à¸à¹à¸²à¸à¹à¸à¸ : ' + result_site.site.team_support.team_name119 messages_header = 'BATTERY : ALARM '+'สà¸à¸²à¸à¸µ : ' + str(result_site.site.station_name)120 path_save=creating_picture_for_line_notify.CreatingPictureForBATTERY('ALARM',result_site) #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token121 result_notify=creating_line_data.send_notify_picture(path_save, result_site.site.team_support.line_notify_token,messages_header,site_profile)122 return creating_flex_messages.CreateNotifyFormBatteryStatus('ALARM',site_profile)123 def Line_Creating_BATTERY_NORMAL (site_profile):124 result_site = site_profile # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 0125 # day_loss = line_data[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 0126 # hours_loss = line_data[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 1127 # minutes_loss = line_data[2] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 2128 # datetime_now = line_data[3] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 3129 # Error_start = line_data[4] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 4130 messages = 'BATTERY Status ' + '\n' + \131 'Type : ' + ' Battery : NORMAL ' + '\n' \132 'สà¸à¸²à¸à¸µ : ' + result_site.site.station_name + '\n' + \133 'IP : ' + str(result_site.site.station_ip) + '\n' + \134 'Serial : ' + str(result_site.NOZZLE_SN) + '\n' + \135 'หà¸à¹à¸²à¸à¸µà¹ : ' + str(result_site.NOZZLE_pump_log_address) + '\n' + \136 'มืà¸à¸à¹à¸²à¸¢ : ' + str(result_site.NOZZLE_num) + '\n' + \137 'ระà¸à¸±à¸à¹à¸£à¸à¸à¸±à¸ : ' + str(result_site.NOZZLE_Battery_Status_Volts) + ' V.'+ '\n' \138 + 'à¸à¹à¸²à¸à¹à¸à¸ : ' + result_site.site.team_support.team_name139 # return creating_line_data.send_notify(messages , result_site.site.team_support.line_notify_token) #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token 140 messages_header = 'BATTERY : NORMAL'+'สà¸à¸²à¸à¸µ : ' + str(result_site.site.station_name)141 path_save=creating_picture_for_line_notify.CreatingPictureForBATTERY('NORMAL',result_site) #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token142 result_notify=creating_line_data.send_notify_picture(path_save, result_site.site.team_support.line_notify_token,messages_header,site_profile)143 return creating_flex_messages.CreateNotifyFormBatteryStatus('NORMAL',site_profile)144 def Line_Creating_NOZZLE_OFFLINE (line_data,site_profile):145 result_site = site_profile # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 0146 day_loss = line_data[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 0147 hours_loss = line_data[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 1148 minutes_loss = line_data[2] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 2149 datetime_now = line_data[3] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 3150 Error_start = line_data[4] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 4151 messages_header = 'NOZZLE-OFFLINE : '+'สà¸à¸²à¸à¸µ : ' + str(result_site.site.station_name)152 path_save=creating_picture_for_line_notify.CreatingPictureForNOZZLE('NOZZLE',line_data,site_profile,'OFF-LINE') #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token153 result_notify=creating_line_data.send_notify_picture(path_save, result_site.site.team_support.line_notify_token,messages_header,site_profile)154 return creating_flex_messages.CreateNotifyFormNozzleOffline(line_data,site_profile)155 def Line_Creating_NOZZLE_ONLINE (line_data,site_profile):156 result_site = site_profile # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/connect_db_profile/get_site_profile à¹à¸ index à¸à¸µà¹ 0157 day_loss = line_data[0] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 0158 hours_loss = line_data[1] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 1159 minutes_loss = line_data[2] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 2160 datetime_now = line_data[3] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 3161 Error_start = line_data[4] # รัà¸à¸à¹à¸² return มาà¸à¸²à¸ linebot/calculate_function/different_time_calculate à¹à¸à¸¢ return มาà¸à¸±à¹à¸à¸«à¸¡à¸ 5 index 4162 messages_header = 'NOZZLE-ONLINE : '+'สà¸à¸²à¸à¸µ : ' + str(result_site.site.station_name)163 path_save=creating_picture_for_line_notify.CreatingPictureForNOZZLE('NOZZLE',line_data,site_profile,'ON-LINE') #result_site.team_support.line_notify_token à¸à¸·à¸ à¸à¹à¸²à¸à¸à¸´à¸à¸à¸²à¸ site_profile --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Site -- > team_support --> à¸à¹à¸²à¸à¹à¸à¸à¸µà¹ à¸à¸²à¸£à¸²à¸ Team --> line_notify_token164 result_notify=creating_line_data.send_notify_picture(path_save, result_site.site.team_support.line_notify_token,messages_header,site_profile)165
...
RPFEM_doatsu.py
Source:RPFEM_doatsu.py
1"""2#######################################################3#######################################################4#####ããæ¯æåæ²ç·ããã³æ¯æåæ²é¢ã®ããã®ããã°ã©ã ã####5#######################################################6###########ãããä½ææ¥æï¼2020å¹´12æ25æ¥ãããã#########7###########ãããä½æè
ï¼å¤§å¹³ å°è¼ï¼å°æ»ç§1å¹´ï¼ã ########8#######################################################91011ã使ç¨è¨èªã12ã»Python131415ãæ¬ããã°ã©ã ã®ç®çã16ã»åå§è¨ç®ã®ä½æ¥ã®å¹çå1718ãæ¬ããã°ã©ã ã®æ¦è¦ã19ã»åå§è¨ç®ã¯ä½ç¨ä½ç½®ãå¤åããã¦ï¼åå§ãæå°å¤ã¨ãªãä½ç¨ä½ç½®ãæ¢ã20ã»å¾æ¥ã¯ï¼ï¼ã¤ï¼ã¤ï¼2Dyouso.datãæã¡æãï¼å®è¡ï¼result.dã確èªããã¨ãã£ãç¹°ãè¿ãã ã£ãï¼21ã»ãã®ããã°ã©ã ã¯ï¼åæä½ç¨ä½ç½®ãè¨å®ãããã©ã«ããç¨æããã°ï¼èªåçã«åå§ãæå°å¤ãèªèãï¼ãã®å¾ï¼3ã¤åã®è§£æãããï¼22ã»ç´°ãã解説ã¯ï¼ä»¥ä¸ã«ããã³ã¼ãã®ä¸ã«æ¸ãã¦ããï¼232425â»æ³¨æç¹26ã»2Dyouso.datå
ã®ä½ç¨ä½ç½®ãè¨å®ããè¡ã¯ããã°ã©ã ãææã¡ã§å¤æ´ããªããã°ãããªãï¼27ã»LINEéç¥ã®ããã°ã©ã ãå®è¡ããå ´åï¼èªåã®ã¢ã¯ã»ã¹ãã¼ã¯ã³ãçºè¡ãã¦å¤æ´ããï¼ï¼https://notify-bot.line.me/ja/ï¼28ã»è§£æãã©ã«ãå
ã«ããRPFEMã®å®è¡ãã¡ã¤ã«ã¯ï¼ï¼ã¤ã ãã«ããï¼RPFEMãå«ã¾ããexeãã¡ã¤ã«ãï¼ã¤ã ãæ¤åºããããï¼29ã»è§£æãçºæ£ããå ´åï¼å¯¾å¦ã§ããªãï¼éä¸ã§è§£æãæ¢ã¾ã£ã¦ãã¾ã£ããï¼ããã¾ã§ã«ä½æããããã©ã«ããå¥ãã©ã«ãã«ç§»åããã¦ï¼éä¸ããå®è¡ãã¦ãã ããï¼30ã»æ±ç¨æ§ãé«ããããï¼ç¨æãã解æãã©ã«ãã®ååã¯ä½ç¨ä½ç½®ã®ã¿ï¼ä¾ãã°ï¼ã1.5ãï¼ã¨ãã¦ãã ããï¼ï¼æåã®è§£æãã©ã«ããåæä½ç¨ä½ç½®ã¨ããããï¼ä½åãªæååãããã¨ã¨ã©ã¼ã¨ãªãã¾ãï¼31323334ããã£ã¬ã¯ããªé層ä¾ã35~~~~~~~~~~~~~~~~~~~~~~~~~~~~~36C:.37ââ1.5 <-----------------------------------------------åæä½ç¨ä½ç½®38 2D.neu39 2Dyouso.datã<--------------------------------åæä½ç¨ä½ç½®ã¨ãªãããã«ãã¦ãã ãã40 analysis output.exeã41 libiomp5md.dllã42 RPFEM_OHIRA.exeã<----------------------------解æçµäºæã®PAUSEããªãããRPFEMå®è¡ãã¡ã¤ã«43~~~~~~~~~~~~~~~~~~~~~~~~~~~~~44454647"""484950"""51 以ä¸ã®å
容ãæ¸ããã¦ããè¡ã2Dyouso.datãè¦ã¦æã¡æãã5253 E 3443ããããããããããããããããããããããããããããã<-----------ä½ç¨ä½ç½®54 E 3443 -1.00000 0.00000 0.00000ãããã <-----------ä½ç¨é55"""56changedRow_1 = 21457changedRow_2 = 21558596061import os62import glob63import shutil64import re65import sys66import pandas as pd67import subprocess as sp6869#ã解æãå®æ½ãããã£ã¬ã¯ããªã®è¨å®70curr_dir = str(input("解æãå®æ½ãããã©ã«ãããããã£ã¬ã¯ããªãå
¥åï¼"))7172initial_folder_list = glob.glob(curr_dir + "\\*")73initial_dir = initial_folder_list[0]7475# RPFEMããã°ã©ã ãåå¾ããï¼ååã¯RPFEMããå§ã¾ããã®ã¨ããï¼76rpfem_dir = glob.glob(initial_folder_list[0] + "\\*.exe")77rpfem_dir = [d for d in rpfem_dir if "RPFEM" in os.path.basename(d)]78# RPFEMã®è§£æãã©ã«ãã1ã¤ãã©ãããå¤å¥ï¼åå¾ããéã«ï¼ãã®æ°ãï¼ã¤ã§ãªããªãï¼ããã°ã©ã ãçµäºãããï¼79if len(rpfem_dir) != 1:80 print("""81---------- ERROR ----------)82RPFEMããã°ã©ã ã{}åãåå¨ãã¾ãã83æ£ãããã©ã«ããç¨æãã¦ãã ããã84---------------------------"""85.format(len(rpfem_dir)))86 sys.exit()8788# RPFEMã®å®è¡ãã¡ã¤ã«ã®åå"RPFE_âââââ.exe"ãåå¾89rpfem_exe = os.path.basename(rpfem_dir[0])90"""91 æåã®ãã©ã«ãã®åæ°ãã«ã¦ã³ãï¼ï¼ä»¥å¤ãªãããã°ã©ã ãä¸æ¢ï¼92"""93# ä½åãªãã¡ã¤ã«ã»ãã©ã«ããåå¨ããããå¤å¥94if len(initial_folder_list) != 1:95 print("""96---------- ERROR ----------)97ä½åãªãã¡ã¤ã«ã»ãã©ã«ããåå¨ãã¾ãã98æ£ãããã©ã«ããç¨æãã¦ãã ããã99---------------------------"""100.format(len(initial_folder_list)))101 sys.exit()102103# ãã©ã«ãã®ååããåæä½ç¨ä½ç½®ãåå¾104height = float(os.path.basename(initial_dir))105106107# 解æçµæãéè¨ããããã®ç©ºãªã¹ãããã³ï¼2Dyouso.datå
ã®çªå·ãå¤æ´ããããã®å¤æ°ãè¨å®108109list_value = []110list_height = []111list_time = []112node_number_count = 0113def remove_file():114 remove_files = ["out_seepage_element.d", "out_seepage_node.d", "resultseepage.d", "fem-change_data.exe", "libiomp5md.dll"]115 for remove_file in remove_files:116 if os.path.exists(remove_file):117 os.remove(remove_file)118 os.remove(rpfem_dir[0])119 120"""121 åæé«ãã®åå§è¨ç®ï¼ï¼å¨ç®ï¼122"""123def rpfem(dir, height):124125 # 解æãè¡ã解æãã©ã«ãã«ã«ã¬ã³ããã£ã¬ã¯ããªãå¤æ´126 os.chdir(dir)127 # RPFEMã®å®è¡ãã¡ã¤ã«ãå®è¡128 sp.call(rpfem_exe)129130 # 解æä¸ï¼ï¼ï¼ï¼ï¼ï¼è§£æãçµããã°[result.d]ãçæããã131 # 解æçµæãåå¾ããããï¼result.dãèªã¿è¾¼ã132 with open("result.d", "r") as ff:133 lines = ff.read().splitlines()134 # RPFEMå¤ï¼ä¸»ååå§ååï¼ã®åå¾135 res_value = "res_value_{}".format(height)136 res_value = re.compile("\d+\.\d+").findall(lines[-3])137 # 解ææéãåå¾138 res_time = re.compile("\d+\.\d+").findall(lines[-1])139140 # åå¾ãã解æçµæã¨ï¼ä½ç¨ä½ç½®ããªã¹ãã«æ ¼ç´141 list_value.append(res_value[0])142 list_time.append(res_time[0])143 list_height.append(round(height, 2))144 145 # åæä½ç¨ä½ç½®ã®è§£æãçµäº146 print(dir, ": END")147 # remove_file()148149150"""151 åå§è¨ç®ï¼ï¼å¨ç®ä»¥éï¼åã®è§£æçµæã¨ã®å·®ãï¼ã«ãªãã¾ã§ï¼152"""153def rpfem_while(dir, height, changedRow_1, changedRow_2):154 global node_number_count155156 # åæä½ç¨å°ä½ã®è§£æãã©ã«ãããã¨ã«ï¼è§£æãã©ã«ããè¤è£½157 shutil.copytree(initial_dir, dir)158159 #è¤è£½ãã解æãã©ã«ãã«ã«ã¬ã³ããã£ã¬ã¯ããªãå¤æ´160 os.chdir(dir)161162 # 以ä¸ã®[row1], [row2]ã§ï¼2Dyouso.datå
ã®ä½ç¨ä½ç½®ãå¤æ´ããï¼163 # ========================row1=============================164 with open("2Dyouso.dat", "r", encoding="cp932") as file:165 data_lines = file.read()166 row1 = data_lines.splitlines()[changedRow_1 - 1][0:]167 sep = row1.split()168 node_number_count += 1169 node_number = int(sep[1]) + node_number_count170 data_line1 = data_lines.replace(row1, "E "+ str(node_number))171172 with open("2Dyouso.dat", mode="w", encoding="cp932") as file:173 file.write(data_line1)174175 # ========================row2=============================176177178 with open("2Dyouso.dat", "r", encoding="cp932") as file:179 data_lines = file.read()180 row2 = data_lines.splitlines()[changedRow_2 - 1][0:]181182 data_line2 = data_lines.replace(row2, "E "+str(node_number)+" -1.00000 0.00000 0.00000")183184 with open("2Dyouso.dat", mode="w", encoding="cp932") as file:185 file.write(data_line2)186187 # 2Dyouso.datãå¤æ´ãããï¼RPFEMã®å®è¡ãã¡ã¤ã«ãå®è¡188 sp.call(rpfem_exe)189 # remove_file()190191192 with open("result.d", "r") as ff:193 lines = ff.read().splitlines()194 res_value = "res_value_{}".format(height)195 res_value = re.compile("\d+\.\d+").findall(lines[-3])196 #print(res_value)197 #print(diff_value)198199 res_time = re.compile("\d+\.\d+").findall(lines[-1])200201 list_value.append(res_value[0])202 list_time.append(res_time[0])203 list_height.append(round(height, 2))204205 print(dir, ": END")206207208"""209 ã°ã©ãåã®é¢æ°210"""211import matplotlib.pyplot as plt212import numpy as np213def graph():214 #y = list_height215 #x = list_value216 #x = [float(i) for j in x for i in j]217 #y = [float(i) for i in y]218219 os.chdir(curr_dir)220 # ä½æããresult.csvã®ãã¼ã¿ãèªè¾¼221 data = np.loadtxt(222 fname = "result.csv",223 dtype = "float",224 delimiter = ",",225 skiprows = 1226 )227228 # ã°ã©ããæãããã®xããã³yã®ãªã¹ããè¨å®229 x = data[:, 1]230 y = data[:, 0]231232 fig = plt.figure(figsize=(9, 9))233 ax = fig.add_subplot(111)234235 # 軸ã®å¹
ãxããã³yã®æå°å¤ã¨æ大å¤ã«å¤æ´236 ax.set_xlim(min(x), max(x))237 ax.set_ylim(min(y), max(y))238239 # 軸ã©ãã«ã®è¨å®240 ax.set_xlabel("Active Earth Pressure Pa [kN/m]", font="Times New Roman", fontsize = 20)241 ax.set_ylabel("Earth Pressure Acting Point h [m]", font="Times New Roman", fontsize = 20)242 #ax.set_title(sep_list)243244 # ãã©ã³ãã®è¨å®245 plt.rcParams['font.size'] = 14246 plt.rcParams['font.family'] = 'Times New Roman'247248 # ç®çã®è¨å®ï¼å
å´ï¼249 plt.rcParams['xtick.direction'] = 'in'250 plt.rcParams['ytick.direction'] = 'in'251252 # ç®çãç·ã®è¨å®ï¼ã°ã©ãã®ä¸ä¸å·¦å³ï¼253 ax.yaxis.set_ticks_position('both')254 ax.xaxis.set_ticks_position('both')255256 # x軸ã«è£å©ç®çç·ãè¨å®257 ax.grid(which = "major", axis = "x", color = "black", alpha = 0.5, linestyle = "--", linewidth = 1)258259 # y軸ã«ç®çç·ãè¨å®260 ax.grid(which = "major", axis = "y", color = "black", alpha = 0.5, linestyle = "--", linewidth = 1)261262 # RPFEMã®è§£æå¤ãããããï¼ç¸¦è»¸ã«ä½ç¨ä½ç½®ï¼æ¨ªè»¸ã«åå§ååï¼263 ax.scatter(x, y, label="RPFEM", s=300, color="black")264265 # ããããããç¹ãç·ã§çµã¶ï¼æãç·ã°ã©ãï¼266 ax.plot(x, y, label="RPFEM", color="black")267268 # ä½ç¨ä½ç½®ãæå°å¤ã¨ãªãç®æã«èµ¤ã横ç·ãæå269 ax.plot([min(x), max(x)],[min_height, min_height], "red", linestyle='-')270271 # 解æãã©ã«ãããããã£ã¬ã¯ããªã«ã°ã©ãã"graph.png"ã¨ãã¦ä¿å272 fig.savefig(curr_dir+ "//graph.png")273274"""275 LINEã«éç¥ããé¢æ°276"""277import requests278def send_line_notify_ohira(message):279 line_notify_token = '6KIyVw4wK3PEjRm5IhtqqLZzWELPJJIoedxJm4EYuuw'######<---------ãããã¢ã¯ã»ã¹ãã¼ã¯ã³ã§ï¼èªåã®ãã®ã«å¤ããï¼è©³ããã¯ã°ã°ãï¼ohira280 line_notify_api = 'https://notify-api.line.me/api/notify'281 headers = {'Authorization': f'Bearer {line_notify_token}'}282 data = {'message': message}283 files = {'imageFile': open(os.path.join(curr_dir, "graph.png"), "rb")}284 requests.post(line_notify_api, headers = headers, data = data, files = files)285286287288"""289 ãã©ã«ããæ´çããé¢æ°290"""291import os292import glob293294remove_files = ["out_seepage_element.d", "out_seepage_node.d", "resultseepage.d", "fem-change_data.exe", "libiomp5md.dll"]295def cleaning_folder(curr_dir, rpfem_exe):296 file_dirs = glob.glob(curr_dir + "\\*")297 for file_dir in file_dirs:298 os.chdir(file_dir)299 for remove_file in remove_files:300 if os.path.exists(remove_file):301 os.remove(remove_file)302303 if os.path.exists(rpfem_exe):304 os.remove(rpfem_exe)305306307308"""309 以ä¸ï¼ããã°ã©ã ã®å®è¡310"""311312# diffã®åæå¤ã®è¨å®313diff = 1314315#1ã¤ç®ã®RPFEMãå®è¡316rpfem(initial_dir, height)317# ãã©ã¹ãªãwhileæç¶è¡ãï¼ãã¤ãã¹ãªãwhileæãæãåºã318319320while diff > 0:321 height += 0.1322 # 解æãããã£ã¬ã¯ããªã®è¨å®323 dir = curr_dir + "\\" + str(round(height, 2))324325 # RPFEMã®å®è¡ï¼ããã«ï¼è§£æãã©ã«ãã®æºåï¼2Dyouso.datã®æ¸æãªã©ãå«ã¾ããï¼326 rpfem_while(dir, height, changedRow_1, changedRow_2)327328 # 1ã¤åã®ä½ç¨ä½ç½®ã§æ±ããRPFEMã¨ã®å·®åãç®åº329 diff = float(list_value[-2]) - float(list_value[-1])330331# whileæãçµäºããã¨ãã®æå¾ãã2ã¤ç®ã®å¤ãæå°å¤ã¨ãªã332min_value = list_value[-2]333min_height = list_height[-2]334335336"""337 åå§ãæå°å¤ã«ãªã£ãå¾ï¼2å¨åã®è§£æããã338"""339# whileæã§ã®ä½æ¥ã2ååè¡ãï¼340height += 0.1341dir = curr_dir + "\\" + str(round(height, 2))342rpfem_while(dir, height, changedRow_1, changedRow_2)343344height += 0.1345dir = curr_dir + "\\" + str(round(height, 2))346rpfem_while(dir, height, changedRow_1, changedRow_2)347348349350if min_value > list_value[-1]:351 height += 0.1352 dir = curr_dir + "\\" + str(round(height, 2))353 rpfem_while(dir, height, changedRow_1, changedRow_2)354 height += 0.1355 dir = curr_dir + "\\" + str(round(height, 2))356 rpfem_while(dir, height, changedRow_1, changedRow_2)357 height += 0.1358 dir = curr_dir + "\\" + str(round(height, 2))359 rpfem_while(dir, height, changedRow_1, changedRow_2)360361362if min_value > list_value[-2]:363 height += 0.1364 dir = curr_dir + "\\" + str(round(height, 2))365 rpfem_while(dir, height, changedRow_1, changedRow_2)366 height += 0.1367 dir = curr_dir + "\\" + str(round(height, 2))368 rpfem_while(dir, height, changedRow_1, changedRow_2)369370min_value = min(list_value)371index = list_value.index(min(list_value))372min_height = list_height[index]373374375376cleaning_folder(curr_dir, rpfem_exe)377378"""379 解æçµæãæ ¼ç´ããã¦ãããªã¹ããCSVã«éè¨380"""381df_result = pd.DataFrame.from_dict({"Height":list_height,"Analysis Value":list_value, "Analysis Time":list_time})382df_result.to_csv(os.path.join(curr_dir, "result.csv"), index=False)383384385386graph()387388print("""389=====================================================390 解æãã©ã«ãï¼{folder}391 åå§ã®æå°å¤ï¼{min_value}392 ãã®ä½ç¨ä½ç½®ï¼{min_height}393=====================================================394""".format(folder=curr_dir, min_value=min_value, min_height=min_height)395)396397398"""399 解æå¤ããã³ï¼ãã®ã°ã©ããLINEãNotify ã«éä¿¡ãã400"""401result_notify = [(str(i) + "ï¼" + str(j)) for (i, j) in zip(list_height, list_value)]402result_notify = '\n'.join(result_notify)403message = "\n ã{curr_dir}ã\n=======çµæ=======\n {result_notify}\n================".format(curr_dir=curr_dir, result_notify=result_notify)404send_line_notify_ohira(message)
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!