当前位置: 首页>>代码示例>>Python>>正文


Python Node.get_by_id方法代码示例

本文整理汇总了Python中models.Node.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Node.get_by_id方法的具体用法?Python Node.get_by_id怎么用?Python Node.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Node的用法示例。


在下文中一共展示了Node.get_by_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: nodes_trigger_callback

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get_by_id [as 别名]
def nodes_trigger_callback():
    """
        Trigger Callback
        Called when node gpio triggered
        ---
        tags:
          - sensors
        responses:
          200:
            description: Returns node data
        """
    payload = request.get_json()
    id   = int(payload.get("id"))
    data = payload.get("data")
    node = Node.get_by_id(id)
    if node.printer_id:
        printer = Printer.get_by_id(node.printer_id)
        if printer.status in ["completed", "cancelled"]:
            t = Command(printer.id, hub.log, "clear", hub.Webapi)
        else:
            t = Command(printer.id, hub.log, "cancel", hub.Webapi)
        t.start()
        for sensor in node.sensors:
            if sensor.sensor_type == "LED":
                url = sensor.led_on()
                t = threading.Thread(target=requests.get,
                                     args=(url,))
                t.start()
        #r = requests.get(url, timeout=10)
    d = {'id': id,
         'data': data}
    return json.jsonify(d)
开发者ID:StratusPrint,项目名称:HUB,代码行数:34,代码来源:nodes.py

示例2: sensor_delete

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get_by_id [as 别名]
def sensor_delete(sensor_id):
    """
        Delete a Sensor
        ---
        tags:
          - sensors
        responses:
          200:
            description: Returns "Deleted"
        """
    sensor = Sensor.get_by_webid(sensor_id)
    node   = Node.get_by_id(sensor.node_id)
    node.remove_sensor(sensor.id)
    return json.jsonify({'message': 'Deleted'}), 201
开发者ID:StratusPrint,项目名称:HUB,代码行数:16,代码来源:nodes.py

示例3: activate_node

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get_by_id [as 别名]
def activate_node(payload = None):
    """
        Activate Node
        Called by node to activate itself on the hub
        ---
        tags:
          - nodes
        responses:
          200:
            description: Returns a list of sensors
        """

    global nodes
    id   = int(request.args.get("id"))
    ip   = str(request.args.get("ip"))
    port = int(request.args.get("port", 80))
    log = hub.log
    listener = hub.node_listeners

    node = Node.get_by_id(id)
    if node:
        node.update(ip=ip)
        if not listener.is_alive(id):
            t = NodeCollector(id, hub.Webapi, hub.log)
            t.start()
            listener.add_thread(id, t)
            log.log("Node " + str(id) + " is now online.")
            return json.jsonify({'message': "Node " + str(id)
                                            + " is now online."}),201
        if listener.is_alive(id):
            log.log("Node " + str(id)
                    + " is already online but tried"
                    + " to activate again, Updated it's data")
            return json.jsonify({'message': "Node " + str(id)
                                            + " was already online"}),201
    else:
        node = Node(id, ip)
        t = NodeCollector(id, hub.Webapi, hub.log)
        t.start()
        listener.add_thread(id, t)
        updates = {"nodes": []}
        node_updates = updates.get("nodes")
        for node in Node.get_all(fresh=True):
            if node.printer_id == None:
                node_updates.append(node.id)
        t = threading.Thread(target=hub.Webapi.update_nodes,args=updates)
        t.start()
        return json.jsonify({"message": str(id) + " has been activated."}),201
开发者ID:StratusPrint,项目名称:HUB,代码行数:50,代码来源:nodes.py

示例4: post

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get_by_id [as 别名]
    def post(self, user, project, nodes, current_node=None):
        title = self.request.get('title')
        if title:
            def transaction():
                q = Node.all()
                q.ancestor(project)
                q.filter('title =', title)
                node = q.get()

                if node is None:
                    node = Node(
                        parent=project,
                        title=title,
                    )
                    node.put()

                return node

            node = db.run_in_transaction(transaction)

            self.redirect(node.permalink)
            return

        if current_node:
            try:
                association_id = long(self.request.get('association'))
            except ValueError:
                pass
            else:
                association = Node.get_by_id(association_id, parent=project)
                if association:
                    associations = set(current_node.associations)
                    associations.add(association.key())
                    associations.discard(current_node.key())
                    current_node.associations = list(associations)
                    current_node.put()

                    self.redirect(current_node.permalink)
                    return

        self.redirect(project.permalink)
开发者ID:git2samus,项目名称:tamarindo-web,代码行数:43,代码来源:project.py

示例5: run

# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get_by_id [as 别名]
    def run(self):
        """TODO: Docstring for run.
        :returns: TODO

        """
        id     = self.node_id
        webapi = self.webapi
        log    = self.log
        node   = Node.get_by_id(id)
        log.log("NodeCollector starting for node " + str(id))
        sleep(10)
        failures = 0
        while(True):
            node    = Node.get_by_id(id, fresh=True)
            ip      = node.ip
            sensors = node.sensors
            if self.stopped == True:
                log.log("NodeCollector for node " + str(id)
                        + " was requested to stop. Exiting...")
                return 0
            for sensor in sensors:
                pin         = sensor.pin
                webid       = sensor.webid
                sensor_type = sensor.sensor_type
                if pin == None or sensor_type == None:
                    continue
                if sensor_type in ["TEMP", "DOOR", "HUMI", "TRIG"]:
                    url = sensor.get_url()
                elif sensor_type in ["LED"]:
                    printer = Printer.get_by_id(node.printer_id)
                    if printer:
                        if printer.status in ["completed", "cancelled"]:
                            url = sensor.led_flash()
                        else:
                            url = sensor.led_on()
                    else:
                        continue
                elif sensor_type in ["POWER"]:
                    url = sensor.power_on()
                else:
                    continue
                try:
                    response = requests.get(url, timeout=10)
                except requests.ConnectionError:
                    log.log("ERROR: Could not connect to " + url)
                    response = None
                except requests.exceptions.Timeout:
                    log.log("ERROR: Timeout occured on " + url)
                    response = None
                if response == None:
                    failures += 1
                    if failures > 10:
                        log.log("ERROR: Could not collect"
                                + " sensor data from node " + str(id)
                                + ". NodeCollector exiting...")
                        return -1
                    continue
                if response.status_code != 200:
                    log.log("ERROR Response from " 
                            + str(id) + " returned status code "
                            + str(response.status_code) + " on "
                            + response.url)
                else:
                    recent_json = response.json()
                    ret = sensor.set_value(recent_json)
                    data = sensor.to_web()
                    if data != None and data.get("id") != None:
                        webapi.add_data(data)
                sleep(3)
            sleep(3)
开发者ID:StratusPrint,项目名称:HUB,代码行数:72,代码来源:dealer.py


注:本文中的models.Node.get_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。