import re
import requests

class BearerAuth(requests.auth.AuthBase):
    def __init__(self, token):
        self.token = token
    def __call__(self, r):
        r.headers["authorization"] = "Bearer " + self.token
        return r

def broadcast_with_temp(payload):
    # 推送到echo server
    url= 'http://192.168.6.240:6001/apps/EcomFaceEcho/events'
    
#     payload = {
#     'time':datetime.fromtimestamp(jsondata["datetime"]).strftime("%Y-%m-%d %H:%M:%S"),
#     'id': faceid,
#     'score': jsondata["score"],
#     'snapshot':"/result?topic="+faceid+"&filename="+filename,
#     '_token': csrf_token,
#     }
    data={
        "channel": "FaceTemperature",
        "name": "App\\Events\\FaceTemperatureEvent",
        "data": payload
        }
    r = requests.post(url, auth=BearerAuth('9f15dc67520920153edaa79f462f024c'),json=data)
    return r.status_code
