Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created May 2, 2015 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jpmens/1d8f451f115ad4849280 to your computer and use it in GitHub Desktop.
Save jpmens/1d8f451f115ad4849280 to your computer and use it in GitHub Desktop.
mqttwarn functions for slack whereis slash-command
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import time
import urllib2
# --- slack_whereis
def _isloc(s):
data = json.loads(s)
if type(data) == dict:
if '_type' in data and data['_type'] == 'location':
if 'lat' in data and 'lon' in data:
return data
return None
def slack_whereis_filter(topic, payload):
''' return True if this message should be suppressed '''
data = _isloc(payload)
if data is None:
return True
return False
def slack_whereis(topic, data, srv=None):
geo = "?"
data = _isloc(data['payload'])
if data is not None:
lat = data['lat']
lon = data['lon']
try:
jsondata = json.load(urllib2.urlopen('http://maps.googleapis.com/maps/api/geocode/json?latlng='+str(lat)+','+str(lon)+'&sensor=true'))
geo = jsondata['results'][0]['formatted_address']
except:
geo = 'reverse lookup error'
return dict(geo=geo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment