def urban_handler(): text = slack_utils.get_slack_text() LOG.info(text) if text is None: return 'Invalid text' ret = { "response_type": "in_channel", "text": urban_dict.word_to_defn_slack(text)} return Response(json.dumps(ret), mimetype='application/json')
def urb(text): return get_dict( "Urbandictionary", "#96a14f", urban_dict.word_to_defn_slack(text))
soup = BeautifulSoup(data) return map(make_sense, soup.find_all('div', class_='sense')) def get_word_defns(text, app='slack'): text = text.strip() synsets = get_parsed_data(text) if not synsets: return {'defns': ['No definition found']} ret = [] for synset in synsets: format_defn = slack_format if app == 'slack' else messenger_format ret.append(format_defn(synset)) return {'defns': ret, 'link': 'https://www.vocabulary.com/dictionary/{}'.format(text)} if __name__ == '__main__': import urban_dict import json while True: word = raw_input() print get_word_defns(word, 'messenger') ud = urban_dict.word_to_defn_slack(word) d = get_word_defns(word) a1 = {"title": "English Meaning", "color": "#36a64f", "text": d, "markdown_in": ["text", "pretext"]} a2 = {"title": "Urbandictionary", "color": "#96a14f", "text": ud, "markdown_in": ["text", "pretext"]} print(json.dumps({"attachments": [a1, a2]}))