def get_forecast(args): current = datetime.datetime.now() future = (current - datetime.timedelta(hours=4) + datetime.timedelta(minutes=5)).strftime("%Y-%m-%dT%H:%M:%S") rsp = requests.get("https://api.forecast.io/forecast/" + apikey + "/" + home + "," + future) if rsp.status_code != 200: print("weather request failed") return print("got weather") parsed = rsp.json() if "minutely" not in parsed: print("minutely data not available") return is_raining = parsed["currently"]["precipProbability"] > rain_thresh for forecast in parsed["minutely"]["data"][0:10]: minute = datetime.datetime.fromtimestamp(forecast["time"]) if not is_raining and forecast["precipProbability"] > rain_thresh: minutes, seconds = divmod(minute - current, 60) post_message("its going to rain in " + minutes + " minutes") break if is_raining and forecast["precipProbability"] < 1 - rain_thresh: minutes, seconds = divmod(minute - current, 60) post_message("its going to stop raining in " + minutes + " minutes") break return uwsgi.SPOOL_OK
def onMessage(message): if 'png' not in message['text'] and 'jpg' not in message['text']: return rsp = requests.post(url, json={'url': message['text']}, headers={'Ocp-Apim-Subscription-Key': constants.img_desc_key}) print(rsp.text) if rsp.status_code != 200: return parsed = rsp.json() if 'description' not in parsed: return if 'captions' not in parsed['description']: return captions = parsed['description']['captions'] if len(captions) == 0: return description = "" max_score = 0 for caption in captions: print(caption) if caption['confidence'] > max_score: max_score = caption['confidence'] description = caption['text'] post_message(description)
def get_forecast(args): current = datetime.datetime.now() future = (current - datetime.timedelta(hours=4) + datetime.timedelta(minutes=5)).strftime('%Y-%m-%dT%H:%M:%S') rsp = requests.get('https://api.forecast.io/forecast/' + apikey + '/' + home + ',' + future) if rsp.status_code != 200: print('weather request failed') return print('got weather') parsed = rsp.json() if 'minutely' not in parsed: print('minutely data not available') return is_raining = parsed['currently']['precipProbability'] > rain_thresh for forecast in parsed['minutely']['data'][0:10]: minute = datetime.datetime.fromtimestamp(forecast['time']) if not is_raining and forecast['precipProbability'] > rain_thresh: minutes, seconds = divmod(minute - current, 60) post_message('its going to rain in ' + minutes + ' minutes') break if is_raining and forecast['precipProbability'] < 1 - rain_thresh: minutes, seconds = divmod(minute - current, 60) post_message('its going to stop raining in ' + minutes + ' minutes') break return uwsgi.SPOOL_OK
def onMessage(message): match = pat.search(message['text']) if not match: return url = match.group() if 'png' not in message['text'] and 'jpg' not in message['text']: return rsp = requests.post(url, json={"url": match}, headers={'Ocp-Apim-Subscription-Key': constants.emotion_key}) if rsp.status_code != 200: return parsed = rsp.json() emotions = [] for face in parsed: for emotion, score in face['scores'].items(): if score > .5: emotions.append(emotion) if len(emotions) == 0: return if len(emotions) > 1: post_message('the emotions in this picture are: ' + ', '.join(emotions[:-1]) + ' and ' + emotions[-1]) else: post_message('the emotions in this picture are: ' + emotions[0])
def onMessage(message): if "juanita roll" not in message["text"].lower(): return splits = message["text"].split(" ") if len(splits) > 2: top = int(splits[2]) post_message(str(randint(0, top))) else: post_message(str(randint(0, 10)))
def onMessage(message): if 'juanita assign' not in message['text'].lower(): return global index index = (index + 1) % len(constants.people) person = constants.people[index] if person == 'Taimur': post_message("Master Shah, I'm afraid chance has called upon thee to perform this duty") else: post_message('make {person} do it'.format(person=person))
def onMessage(message): m = r.search(message['text']) if m is None: return url = m.group() print(url) # check if it exists check_statement = """ MATCH (u:User)--(m:Message)--(l:Link {id: {url}}) return u.name as name, m.date as date """ previous_cases = graph.cypher.execute(check_statement, { 'url': url }) for pc in previous_cases: datestring = (datetime.fromtimestamp(int(pc['date'])) - delta).strftime('%m/%d %H:%M:%S') name = pc['name'].split(' ')[-1] post_message("Mr. {user} posted that on {ds}".format(user=name, ds=datestring)) url_statement = """ MATCH (m:Message {id: {m_id}}) MERGE (l:Link {id: {url} }) MERGE (m)-[r:HAS_LINK]->(l) """ graph.cypher.execute(url_statement, { 'u_id': message['sender_id'], 'm_id': message['id'], 'url': url }) rsp = requests.post("http://toomba.mybluemix.net/cypher/roombamatize", json={ 'nodeType': "Message", 'nodeId': message['id'], 'content': url, 'contentType': 'url' }) transactions = rsp.json()['transactions'] for tx in transactions: graph.cypher.execute(tx)
def onMessage(message): m = pat.search(message['text']) if m is None: return url = m.group() rsp = session.get('http://www.reddit.com/search.json?q=url:' + url) if rsp.status_code != 200: return parsed = rsp.json() if len(parsed['data']['children']) == 0: return post_message(get_top_comment(parsed['data']['children'][0]['data']['permalink']))
def onMessage(message): m = pat.search(message['text']) if m is None: return url = m.group() rsp = session.get('http://www.reddit.com/search.json?q=url:' + url) if rsp.status_code != 200: return parsed = rsp.json() if len(parsed['data']['children']) == 0: return post_message( get_top_comment(parsed['data']['children'][0]['data']['permalink']))
def onMessage(message): if 'png' not in message['text'] and 'jpg' not in message['text']: return rsp = requests.post( url, json={'url': message['text']}, headers={'Ocp-Apim-Subscription-Key': constants.img_desc_key}) print(rsp.text) if rsp.status_code != 200: return parsed = rsp.json() if 'description' not in parsed: return if 'captions' not in parsed['description']: return captions = parsed['description']['captions'] if len(captions) == 0: return description = "" max_score = 0 for caption in captions: print(caption) if caption['confidence'] > max_score: max_score = caption['confidence'] description = caption['text'] post_message(description)
def say(msg): post_message(msg) return 'sent ' + msg