def retrain(image, emp_id): try: AZURE_FACE_RETRAIN_URL = keys.get_azure_face_retrain_url( )['AZURE_FACE_RETRAIN_URL'] BEARER_TOKEN = keys.get_bearer_token()['BEARER_TOKEN'] base64string = "" with open(image, "rb") as image_file: base64string = base64.b64encode(image_file.read()) base64string = base64string.decode('utf8') url = AZURE_FACE_RETRAIN_URL payload = { "empId": emp_id, "imageString": "data:image/jpeg;base64," + base64string } # f = open("t.txt","a") # f.write(format(payload)) # f.close() headers = { "Content-Type": "application/json", 'Authorization': BEARER_TOKEN } response = requests.request("POST", url, headers=headers, data=json.dumps(payload)) payload = json.loads(response.text) return None, payload except Exception as e: return e, None
def recognize(data): try: AZURE_FACE_RECOGNIZE_URL = keys.get_azure_face_recognize_url( )['AZURE_FACE_RECOGNIZE_URL'] BEARER_TOKEN = keys.get_bearer_token()['BEARER_TOKEN'] base64string = "" with open(data, "rb") as image_file: base64string = base64.b64encode(image_file.read()) base64string = base64string.decode('utf8') url = AZURE_FACE_RECOGNIZE_URL ##print(base64string) payload = {"imageString": "data:image/jpeg;base64," + base64string} headers = { "Content-Type": "application/json", "Authorization": BEARER_TOKEN } response = requests.request("POST", url, headers=headers, data=json.dumps(payload)) payload = json.loads(response.text) ##print("response") return None, payload except Exception as e: return e, None
def check_status(hostname): try: CHECK_WFH_STATUS_URL = keys.get_check_wfh_status_url( )['CHECK_WFH_STATUS_URL'] BEARER_TOKEN = keys.get_bearer_token()['BEARER_TOKEN'] #print(BEARER_TOKEN) url = CHECK_WFH_STATUS_URL + hostname payload = {} headers = {'Authorization': BEARER_TOKEN} response = requests.request("GET", url, headers=headers, data=payload) payload = json.loads(response.text) return None, payload except Exception as e: return e, None
def verify_otp(otp_cont,emp_id): try: VERIFY_OTP_URL = keys.get_verify_otp_url()['VERIFY_OTP_URL'] BEARER_TOKEN = keys.get_bearer_token()['BEARER_TOKEN'] url = VERIFY_OTP_URL+"otp="+otp_cont+"&empId="+emp_id payload = {} headers = { 'Authorization': BEARER_TOKEN } response = requests.request("GET", url, headers=headers, data = payload) payload = json.loads(response.text) return None, payload except Exception as e: return e, None
def send_otp(emp_id): try: SEND_OTP_URL = keys.get_send_otp_url()['SEND_OTP_URL'] BEARER_TOKEN = keys.get_bearer_token()['BEARER_TOKEN'] url = SEND_OTP_URL+emp_id payload = {} headers = { 'Authorization': BEARER_TOKEN } response = requests.request("GET", url, headers=headers, data = payload) payload = json.loads(response.text) return None, payload except Exception as e: return e, None
def send_approval_mail(publicIP, macAddress, hostName, image, empId): try: SEND_MAIL_URL = keys.get_send_mail_url()['SEND_MAIL_URL'] BEARER_TOKEN = keys.get_bearer_token()['BEARER_TOKEN'] ts = time.time() utc_time = datetime.datetime.utcfromtimestamp(ts).strftime( '%Y-%m-%dT%H:%M:%S') base64string = "" with open(image, "rb") as image_file: base64string = base64.b64encode(image_file.read()) base64string = base64string.decode('utf8') url = SEND_MAIL_URL payload = { "publicIP": publicIP, "macAddress": macAddress, "hostName": hostName, "image": "data:image/jpeg;base64," + base64string, "timestamp": utc_time, "empId": empId } headers = { "Content-Type": "application/json", 'Authorization': BEARER_TOKEN } response = requests.request("POST", url, headers=headers, data=json.dumps(payload)) payload = json.loads(response.text) return None, payload except Exception as e: return e, None