connecting...
Google translation for articles :
1 NEMBER donated to you!!

自作AI?の中身

nem0.85xem (1) 88 4 0
ジャック 2019-12-02 20:47:47

自作したPythonのコードを載せておきます

janeというlinebotの中身です。

 

よかったら遊んでみてください。

 

ただ、サーバーはherokuを使っているため

3時間アクセスなければ消えますし、1日で記録は全て消去されます。

from flask import Flask, request, abort

from linebot import (
   LineBotApi, WebhookHandler
)
from linebot.exceptions import (
   InvalidSignatureError
)
from linebot.models import (
   MessageEvent, TextMessage, TextSendMessage,
)

import os
import json

def choice(id,key):
    with open("log.txt","rt") as f:
        load_log = json.load(f)
    with open("dict.txt","rt") as f:
        load_dict = json.load(f)
    if id in load_log :
        load_log[id]["times"] += 1
        # リセット
        if  load_log[id]["reset"] == 1 or key == "リセットしてよジェーン":
            reset_log = {"log":[0,0,0,0,0],"key":0,"value":0,"reset":0}
            load_log[id].update(reset_log)
            load_log[id]["text"] = "リセットしましたよ!"
        #5
        if load_log[id]["log"][4] == 0:
            load_log[id]["log"][4] = 0
            if load_log[id]["log"][3] == 1:
                load_log[id]["log"][4] = 0
                if key == "はい":
                    new_dict = {load_log[id]["key"]:[load_log[id]["value"]]}
                    load_dict.update(new_dict)
                    load_log[id]["text"] = "わかりました" + load_log[id]["key"] + "の意味は" + load_log[id]["value"] + "ですね!記録しましたよ!"
                    load_log[id]["reset"] = 1
                if key == "いいえ":
                    load_log[id]["text"] = "わかりました" + load_log[id]["key"] + "は" + load_log[id]["value"] + "という意味ではないのですね!"
                    load_log[id]["reset"] = 1
            if load_log[id]["log"][3] == 2:
                if key == "はい":
                    load_dict[load_log[id]["key"]].insert(0,load_log[id]["value"])
                    load_log[id]["text"] = "わかりました" + load_log[id]["key"] + "の意味は" + load_log[id]["value"] + "ですね!記録しましたよ!"
                    load_log[id]["reset"] = 1
                if key == "いいえ":
                    load_log[id]["text"] = "わかりました" + load_log[id]["key"] + "は" + load_log[id]["value"] + "という意味ではないのですね!"
                    load_log[id]["reset"] = 1
            #4
            if load_log[id]["log"][3] == 0:
                load_log[id]["log"][3] = 0
                if load_log[id]["log"][2] == 1 and not load_log[id]["key"] in load_dict:
                    load_log[id]["text"] = load_log[id]["key"] + "の意味は" + key + "で良いですか?# y/n"
                    load_log[id]["value"] = key
                    load_log[id]["log"][3] = 1
                if load_log[id]["log"][2] == 2:
                    load_log[id]["log"][3] = 0
                    if not key in load_dict[load_log[id]["key"]]:
                        load_log[id]["text"] = load_log[id]["key"] + "の意味は" + key + "で良いですか?# y/n"
                        load_log[id]["log"][3] = 2
                        load_log[id]["value"] = key
                if load_log[id]["log"][2] == 2 and key in load_dict[load_log[id]["key"]]:
                    load_log[id]["log"][3] = 0
                    if key in load_dict[load_log[id]["key"]]:
                        load_log[id]["text"] = "その意味は知っていますよ?"
                        load_log[id]["reset"] = 1
                #3
                if load_log[id]["log"][2] == 0:
                    load_log[id]["log"][2] = 0
                    if (load_log[id]["log"][1] == 0) and (load_log[id]["log"][0] == 1) and (not key in load_dict):
                        load_log[id]["text"] = "意味を教えていただけますか?"
                        load_log[id]["key"] = key
                        load_log[id]["log"][2] = 1
                    if (load_log[id]["log"][1] == 2) and (key == "はい"):
                        load_log[id]["text"] = "他の意味を教えていただけますか?"
                        load_log[id]["log"][2] = 2
                    if load_log[id]["log"][1] == 2 and key == "いいえ":
                        load_log[id]["text"] = "わかりました。このままにしますね!"
                        load_log[id]["reset"] = 1
                    #2
                    if load_log[id]["log"][1] == 0:
                        load_log[id]["log"][1] = 0
                        if load_log[id]["log"][0] == 1 and key in load_dict:
                            load_log[id]["text"] = key + "の意味は" + str(load_dict[key]) + "ですよね?他に意味がありあすか?# y/n"
                            load_log[id]["key"] = key
                            load_log[id]["log"][1] = 2
                        #1
                        if load_log[id]["log"][0] == 0:
                            load_log[id]["text"] = "今" + str(len(load_dict)) + "個の単語を覚えましたよ!あなたの知っている単語を教えてください"
                            load_log[id]["log"][0] = 1

    else :
        new_log = {id:{"log":[0,0,0,0,0],"key":0,"value":0,"reset":0,"times":0,"text":0}}
        load_log.update(new_log)
        load_log[id]["text"] = "準備できましたよ○○さん!"

    with open("log.txt","wt") as f:
        json.dump(load_log,f)
    with open("dict.txt","wt") as f:
        json.dump(load_dict,f)

    with open("log.txt","rt") as f:
        load_log = json.load(f)
    with open("dict.txt","rt") as f:
        load_dict = json.load(f)
    x = str(load_log[id]["text"])

    return x

Why don't you get crypt currency 'nem' by posting your blog article?

nemlog is blog posting service which has donation feature by crypt currency nem.
nemlog was launched to create environment which can be donated nem among NEMbers via blog articles.
Let's get nem by posting good blogs.

Nem prize event is being held frequently, Please join us on this opportunity!

nemlog registration from here
Register
Comments from NEMber
ジャック
2019-12-02 22:01:12ID:162383

>>matsuno.nem::さん
了解です!ありがとう御座います。

matsuno.nem
2019-12-02 21:36:40ID:162378

>>ジャック::さん
おお!
nemlog内にもくもく会作ったので気軽にもくもくしてください!
https://nemlog.nem.social/blog/35596

ジャック
2019-12-02 21:31:30ID:162375

>>matsuno.nem::さん
お久しぶりです!
コメントありがとう御座います。
linebotの技術解説用として使わせてもらいました。

matsuno.nem
2019-12-02 21:27:22ID:162374

ジャックさんお久しぶりです!

NEMber who posted this article

仮想通貨が好きです。
ダーツが好きです。
音楽が好きです。
絵が好きです。

自分の副業が大好きです!
18118
0

Why don't you read following articles?