示例#1
0
    async def _send_weather_webhook(self, s2cellId, weatherId, severe, warn, day, time):
        if self.__application_args.weather_webhook:
            log.debug("Send Weather Webhook")

            cell = Cell(CellId(s2cellId))
            coords = []
            for v in range(0, 4):
                vertex = LatLng.from_point(cell.get_vertex(v))
                coords.append([vertex.lat().degrees, vertex.lng().degrees])

            data = weather_webhook_payload.format(s2cellId, coords, weatherId, severe, warn, day, time)

            log.debug(data)
            payload = json.loads(data)
            log.info("Sending weather webhook: %s" % str(payload))
            try:
                response = requests.post(
                    self.__application_args.webhook_url, data=json.dumps(payload),
                    headers={'Content-Type': 'application/json'},
                    timeout=5
                )
                if response.status_code != 200:
                    log.warning("Go status code other than 200 OK from webhook destination: %s" % str(response.status_code))
                else:
                    log.info("Success sending webhook")
            except Exception as e:
                log.warning("Exception occured while sending webhook: %s" % str(e))
        else:
            log.debug("Weather Webhook Disabled")
示例#2
0
文件: pokebot.py 项目: cdchan/pokebot
def bounds(cell_id):
    cell = Cell(cell_id)

    url_string = 'http://maps.googleapis.com/maps/api/staticmap?size=400x400&path='

    coords = []
    for i in range(4) + [0]:
        point = cell.get_vertex(i)
        coords.append("{},{}".format(LatLng.latitude(point).degrees, LatLng.longitude(point).degrees))

    url_string += "|".join(coords)
    print url_string
示例#3
0
    async def _send_weather_webhook(self, s2cellId, weatherId, severe, warn,
                                    day, time):
        if self.__application_args.weather_webhook:
            log.debug("Send Weather Webhook")

            cell = Cell(CellId(s2cellId))
            coords = []
            for v in range(0, 4):
                vertex = LatLng.from_point(cell.get_vertex(v))
                coords.append([vertex.lat().degrees, vertex.lng().degrees])

            data = weather_webhook_payload.format(s2cellId, coords, weatherId,
                                                  severe, warn, day, time)

            log.debug(data)
            payload = json.loads(data)
            self.__sendToWebhook(payload)
        else:
            log.debug("Weather Webhook Disabled")
示例#4
0
def send_weather_webhook(s2cellId, weatherId, severe, warn, day, time):
    if args.weather_webhook:
        log.debug("Send Weather Webhook")

        cell = Cell(CellId(s2cellId))
        coords = []
        for v in range(0, 4):
            vertex = LatLng.from_point(cell.get_vertex(v))
            coords.append([vertex.lat().degrees, vertex.lng().degrees])

        data = weather_webhook_payload.format(s2cellId, coords, weatherId,
                                              severe, warn, day, time)

        log.debug(data)
        payload = json.loads(data)
        response = requests.post(args.webhook_url,
                                 data=json.dumps(payload),
                                 headers={'Content-Type': 'application/json'})
    else:
        log.debug("Weather Webhook Disabled")