import json import random import string from flask import request import db from initlogging import getlog from utils import read_file LOG = getlog(__name__) slack_client_id = '16781810420.17757441574' # disk ftw :/ slack_secret = read_file('/usr/local/slack_secret', prefix="") slack_tokens = set(map(lambda x: x.strip(), read_file( '/usr/local/slack_token', prefix="").split('\n'))) LOG.info(slack_tokens) auth_tokens = db.RedisTable('authtokens') def get_slack_text(app_name='random'): # todo : use slack_app instead of checking in all tokens text = request.form['text'].strip() token = request.form['token'].strip() LOG.info(request.form) if token not in slack_tokens: return return text def get_adv_slack_text(app_name='random'):
import urllib import json from bs4 import BeautifulSoup import db import initlogging import profanity cache = db.RedisTable('urbandict-cache') LOG = initlogging.getlog(__name__) def process_defn(defn): try: head = defn.find('div', class_='def-header') ret = {} if head is not None: ret['head'] = head.find('a').get_text() mean = defn.find('div', class_='meaning') examp = defn.find('div', class_='example') if examp is not None: ret['example'] = examp.get_text().strip() if mean is not None: ret['mean'] = mean.get_text().strip() return ret except Exception: LOG.print_exc("exception in processing defn") def get_meaning(word, use_cache=False): if use_cache: cache.get('json_' + word)