예제 #1
0
파일: api.py 프로젝트: kuhaku/web-atango
def dialogue():
    def explicit_fword(text):
        for (implicit, explicit) in fwords.items():
            text = text.replace(implicit, explicit)
        return text

    _input = request.args.get('text')
    _input = explicit_fword(_input)

    uid = compute_id(request)
    db = redis.db('twitter')
    user_info = db.get('user:%s' % uid)
    if user_info:
        user_info = json.loads(user_info.decode('utf8'))
        user_info['tweets'].append(_input)
    else:
        user_info = {'replies': [], 'tweets': [_input]}
    user_info.update({'screen_name': '貴殿', 'name': '貴殿'})

    rep = Reply()
    response = rep.make_response(_input, user_info)
    if len(user_info['replies']) >= 20:
        user_info['replies'].pop(0)
    if len(user_info['tweets']) >= 20:
        user_info['tweets'].pop(0)
    user_info['replies'].append(response['text'])
    db.setex('user:%s' % uid, json.dumps(user_info), TWO_WEEK)
    response['text'] = normalize.remove_emoticon(response['text'])
    response['text'] = response['text'].strip()
    return response['text']
예제 #2
0
def dialogue():
    def explicit_fword(text):
        for (implicit, explicit) in fwords.items():
            text = text.replace(implicit, explicit)
        return text

    _input = request.args.get('text')
    _input = explicit_fword(_input)

    uid = compute_id(request)
    db = redis.db('twitter')
    user_info = db.get('user:%s' % uid)
    if user_info:
        user_info = json.loads(user_info.decode('utf8'))
        user_info['tweets'].append(_input)
    else:
        user_info = {'replies': [], 'tweets': [_input]}
    user_info.update({'screen_name': '貴殿', 'name': '貴殿'})

    rep = Reply()
    response = rep.make_response(_input, user_info)
    if len(user_info['replies']) >= 20:
        user_info['replies'].pop(0)
    if len(user_info['tweets']) >= 20:
        user_info['tweets'].pop(0)
    user_info['replies'].append(response['text'])
    db.setex('user:%s' % uid, json.dumps(user_info), TWO_WEEK)
    response['text'] = normalize.remove_emoticon(response['text'])
    response['text'] = response['text'].strip()
    return response['text']
예제 #3
0
파일: misc.py 프로젝트: 5470x3/atango
def give_present(*arg):
    present_list = file_io.read('present.txt')
    sentence = misc.choice(present_list)
    while ('集計' in sentence or 'シュウケイ' in sentence or 'を' not in sentence or
            sentence.endswith('萌え') or len(sentence) < 3):
        sentence = misc.choice(present_list)
    present = normalize.remove_emoticon(sentence)
    present = present[:-1] if present.endswith('を') else present
    search_result = google_image.search(present)
    if 'images' in search_result:
        for url in search_result['images']:
            if url.endswith(('.jpg', '.gif', '.png')):
                try:
                    web.download(url, '/tmp/present')
                    break
                except:
                    continue
    sentence = normalize.normalize(sentence)
    return {'text': u'%nameに' + sentence, 'media[]': '/tmp/present'}
예제 #4
0
파일: misc.py 프로젝트: pombredanne/atango
def give_present(*arg):
    present_list = file_io.read('present.txt', data=True)
    sentence = misc.choice(present_list)
    while ('集計' in sentence or 'シュウケイ' in sentence or 'を' not in sentence or
            sentence.endswith('萌え') or len(sentence) < 3):
        sentence = misc.choice(present_list)
    present = normalize.remove_emoticon(sentence)
    present = present.replace('!', '').replace('!', '')
    present = present.replace('漏れの', '').replace('俺の', '').replace('俺が', '')
    present = present[:-1] if present.endswith('を') else present
    search_result = google_image.search(present)
    if 'images' in search_result:
        for url in search_result['images']:
            if url.endswith(('.jpg', '.gif', '.png')):
                try:
                    web.download(url, '/tmp/present')
                    break
                except:
                    continue
    sentence = normalize.normalize(sentence)
    return {'text': '%nameに' + sentence, 'media[]': '/tmp/present'}
예제 #5
0
파일: ome.py 프로젝트: kuhaku/atango
 def simplify(text):
     text = normalize.remove_emoticon(text)
     return re_kigou.sub('', text)
예제 #6
0
def test_remove_emoticon():
    emoticons = (u'(;´Д`)', u'ヽ(´ー`)ノ', u'v(*゚Д、`)v', u'(;´Д`)人(;´Д`)')
    for emoticon in emoticons:
        got = normalize.remove_emoticon(emoticon)
        assert got == ''
예제 #7
0
def cleansing(text):
    text = text.strip()
    text = text.replace('\n', '')
    text = regex.re_a_tag.sub('', text)
    text = normalize.remove_emoticon(text)
    return normalize.normalize(text, repeat=3)
예제 #8
0
def test_remove_emoticon():
    emoticons = (u'(;´Д`)', u'ヽ(´ー`)ノ', u'v(*゚Д、`)v', u'(;´Д`)人(;´Д`)')
    for emoticon in emoticons:
        got = normalize.remove_emoticon(emoticon)
        assert got == ''
예제 #9
0
파일: ome.py 프로젝트: pombredanne/atango
 def simplify(text):
     text = normalize.remove_emoticon(text)
     return re_kigou.sub('', text)