Exemplo n.º 1
0
def login():
    username = request.form['username']
    password = request.form['password']
    m = MZone(username, password, env_cfg["mzone_secret"], "mz-a3tek")
    m.gettoken()
    res = dict()
    if m.check_token():
        res = m.current_user()
        res["token"] = m.get_token()
        res["perfil"] = json.loads(res["phoneHome"])["perfil"]
    return res
Exemplo n.º 2
0
def start(account):
    logger.info(
        "Searching notifications for " + account["user"],
        extra={'props': {
            "app": config["name"],
            "label": config["name"]
        }})
    yesterday = Utils.format_date(datetime.now() - timedelta(hours=12),
                                  "%Y-%m-%dT%H:%M:%S")
    m = MZone(account["user"], account["password"], mzone_secret, "mz-a3tek",
              "https://live.mzoneweb.net/mzone61.api/")
    m.gettoken()
    if m.check_token():
        notifis = m.get_notifications(
            extra="readUtcTimestamp eq null and utcTimestamp gt " + yesterday +
            "Z")["value"]
        if len(notifis) > 0:
            logger.info("Reading notifications",
                        extra={
                            'props': {
                                "notifications": notifis,
                                "app": config["name"],
                                "label": config["name"]
                            }
                        })
        else:
            logger.info("No notifications found for " + account["user"],
                        extra={
                            'props': {
                                "app": config["name"],
                                "label": config["name"]
                            }
                        })
        templates = []
        messages = []
        addresses = []
        for noti in notifis:
            if noti["notificationTemplate_Id"] not in templates:
                templates.append(noti["notificationTemplate_Id"])
            message = dict()
            message["template"] = noti["notificationTemplate_Id"]
            message["text"] = noti["message"]
            message["id"] = noti["id"]
            messages.append(message)

        for temple in templates:
            address = dict()
            address["phones"] = get_subscriptions(temple, m)
            address["template"] = temple
            addresses.append(address)

        build_message(messages, addresses, m, account)
    else:
        logger.error("Cant connect to MZone using " + account["user"],
                     extra={
                         'props': {
                             "account": account["user"],
                             "app": config["name"],
                             "label": config["name"]
                         }
                     })