コード例 #1
0
    def test_05(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])
        ServerDoc.codenames2delete([Server.Codename.MARIS])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        ChannelUser.channel_users2upsert(
            [ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        # now_utc = datetime.now(pytz.utc)
        packet = {
            KhalaPacket.Field.TEXT: "?남만 +2분",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }

        with self.assertRaises(HenriqueCommandError) as context:
            NanbanSkill.packet2response(packet)

        self.assertEquals(
            """[남만시각] 이전에 설정된 남만 시각이 없어서 +/-로 남만 시각을 조정할 수 없어요.""",
            str(context.exception))

        if HenriqueEnv.env() == HenriqueEnv.Value.LOCAL:
            return  # cannot test here because LOCAL has different settings

        hyp = HenriquePacket.packet2response(packet)
        ref = "[남만시각] 이전에 설정된 남만 시각이 없어서 +/-로 남만 시각을 조정할 수 없어요."

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #2
0
    def get(cls):
        logger = HenriqueLogger.func_level2logger(cls.get, logging.DEBUG)

        sender_name = request.args.get(cls.Data.Field.SENDER_NAME)
        text_in = request.args.get(cls.Data.Field.TEXT)
        newline = request.args.get(cls.Data.Field.NEWLINE)
        logger.debug({"sender_name":sender_name, "text_in":text_in, "newline":newline})

        if not HenriqueCommand.text2is_query(text_in):
            return None

        chatroom = ChatroomKakaotalk.chatroom()
        Chatroom.chatrooms2upsert([chatroom])

        channel_user = ChannelUserKakaotalk.sender_name2channel_user(sender_name)
        ChannelUser.channel_users2upsert([channel_user])

        packet = {KhalaPacket.Field.TEXT: text_in,
                  KhalaPacket.Field.CHATROOM: Chatroom.chatroom2codename(chatroom),
                  KhalaPacket.Field.CHANNEL_USER: ChannelUser.channel_user2codename(channel_user),
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  }
        logger.debug({"packet": packet,})

        text_response = HenriquePacket.packet2response(packet)
        if not text_response:
            return None

        if cls.packet2skip_response(packet):  # run packet but do not respond
            return None

        text_out = newline.join(text_response.splitlines()) if newline else text_response

        return text_out, 200
コード例 #3
0
    def test_01(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        ChannelUser.channel_users2upsert(
            [ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        # collection = ChannelUserCollection.collection()
        # collection.delete_one({ChannelUser.Field.CODENAME: channel_user_codename})

        packet = {
            KhalaPacket.Field.TEXT: "?price 사탕무 리스본 120ㅅ",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }
        PriceSkill.packet2response(packet)

        collection = ChannelUserCollection.collection()
        channel_user_doc = MongoDBTool.bson2json(
            collection.find_one(
                {ChannelUser.Field.CODENAME: channel_user_codename}))
        hyp = MongoDBTool.doc2id_excluded(channel_user_doc, )
        ref = {
            'channel': 'kakaotalk_uwo',
            'codename': 'kakaotalk_uwo.iris',
            'alias': 'iris'
        }

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #4
0
    def test_04(self):
        cls = self.__class__

        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        ChannelUser.channel_users2upsert(
            [ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        # now_utc = datetime.now(pytz.utc)
        packet = {
            KhalaPacket.Field.TEXT: "?남만",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }
        response = NanbanSkill.packet2response(packet)
        hyp = response.splitlines()[0]

        # utc_nanban = now_utc + NanbanTimedelta.period()
        # tz = pytz.timezone("Asia/Seoul")

        # now_tz = DatetimeTool.astimezone(now_utc, tz)
        # now_nanban = DatetimeTool.astimezone(utc_nanban, tz)

        ref = """[남만시각] 글로벌서버"""

        # pprint(response)
        self.assertEqual(hyp, ref)
コード例 #5
0
    async def on_message(cls, message):
        from henrique.main.singleton.khala.henrique_khala import HenriquePacket
        from khala.singleton.messenger.discord.internal.packet_discord import PacketDiscord
        from khala.singleton.messenger.discord.internal.chatroom_discord import ChatroomDiscord
        from henrique.main.singleton.khala.henrique_khala import HenriqueCommand

        logger = KhalaLogger.func_level2logger(cls.on_message, logging.DEBUG)
        client = cls.client()
        text_in = message.content

        logger.debug({"message": message, })

        if DiscordTool.user_message2is_author(client.user, message):
            return

        if not HenriqueCommand.text2is_query(text_in):
            return

        Chatroom.chatrooms2upsert([ChatroomDiscord.message2chatroom(message)])
        ChannelUser.channel_users2upsert([ChannelUserDiscord.message2channel_user(message)])

        packet = PacketDiscord.message2packet(message)
        logger.debug({"packet": packet, })

        text_out = HenriquePacket.packet2response(packet)

        await message.channel.send(text_out)
コード例 #6
0
    def test_02(self):
        chatroom = {
            'channel': 'discord',
            'codename': 'discord-471024213159837696',
            'locale': 'ko-KR'
        }
        Chatroom.chatrooms2upsert([chatroom])

        channel_user = {
            'channel': 'discord',
            'codename': 'discord-340205035558535169',
            'alias': 'yeri'
        }
        ChannelUser.channel_users2upsert([channel_user])

        packet = {
            'text': '?ㅎㄱ 육두구',
            'chatroom': 'discord-471024213159837696',
            'channel_user': '******',
            'sender_name': 'yeri',
        }
        hyp = HenriquePacket.packet2response(packet)
        ref = """[항구] 육두구 취급항 - 룬, 암보이나"""

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #7
0
    def test_02(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?tradegood 이베리아",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = TradegoodSkill.packet2response(packet)
        ref = """[교역품] 이베리아 문화권 우대품
- 타네가시마 총
- 대만 목각
- 유자
- 일본서적
- 사마 은
- 스타아니스
- 호필
- 두반장
- 가는 끈
- 산초
- 진달래
- 진과스 금
- 청룡도
- 사슴 가죽
- 한지
- 자근
- 사다장"""

        # pprint({"hyp":hyp})
        self.assertEqual(hyp, ref)
コード例 #8
0
    def test_06(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(sender_name)
        ChannelUser.channel_users2upsert([ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        # server = "maris"
        # ports = ["Lisbon"]
        # tradegoods = ["Sugar Beet"]
        #
        # MarketpriceDoc.server_ports_tradegoods2delete(server, ports, tradegoods)
        # channel = Channel.Codename.KAKAOTALK_UWO_UWO  # discord

        packet = {KhalaPacket.Field.TEXT: "?시세 사탕무 : 말세80ㅎ; 사사리75ㅎ; 시라130ㅅ;",
                  KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
                  KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  }

        hyp_01 = PriceSkill.packet2response(packet)
        ref_01 = """[사탕무] 시세
시라쿠사 130↗ @ 방금전 [by iris]
마르세이유 80↘ @ 방금전 [by iris]
사사리 75↘ @ 방금전 [by iris]"""

        # pprint(hyp_01)
        self.assertEqual(hyp_01, ref_01)
コード例 #9
0
    def test_01(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        now_utc = datetime.now(pytz.utc)
        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        packet = {
            KhalaPacket.Field.TEXT: "?남만 지금",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }
        NanbanSkill.nanban_datetime2upsert_mongo(
            packet,
            now_utc,
        )

        response = NanbanSkill.server_lang2lookup(Server.Codename.MARIS, "ko")
        hyp = "\n".join(
            ListTool.indexes2filtered(response.splitlines(), [0, 2]))

        utc_nanban = now_utc + NanbanTimedelta.period()
        tz = pytz.timezone("Asia/Seoul")

        # now_tz = DatetimeTool.astimezone(now_utc, tz)
        now_nanban = DatetimeTool.astimezone(utc_nanban, tz)

        ref = """[남만시각] 글로벌서버
다음 남만 시각: {} (KST) / 약 2시간 후""".format(
            now_nanban.strftime("%I:%M:%S %p").lstrip("0"))

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #10
0
    def test_02(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?culture Lisbon",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = CultureSkill.packet2response(packet)
        ref = '[문화권] 리스본: 이베리아 문화권'

        # pprint({"hyp":hyp})
        self.assertEqual(hyp, ref)
コード例 #11
0
    def test_05(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(sender_name)
        ChannelUser.channel_users2upsert([ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        dt_now = datetime.now(pytz.utc)

        port = "Lisbon"
        tradegood = "Sugar Beet"
        server = Server.Codename.MARIS
        # channel_user = '******'

        def insert_docs():
            collection = MarketpriceCollection.collection()
            doc_old = {MarketpriceDoc.Field.CREATED_AT: dt_now - timedelta(hours=10),
                       MarketpriceDoc.Field.PORT: "Lisbon",
                       MarketpriceDoc.Field.TRADEGOOD: tradegood,
                       MarketpriceDoc.Field.RATE: 120,
                       MarketpriceDoc.Field.TREND: Trend.Value.RISE,

                       MarketpriceDoc.Field.SERVER: server,
                       MarketpriceDoc.Field.CHANNEL_USER: channel_user_codename,
                       }

            doc_new = {MarketpriceDoc.Field.CREATED_AT: dt_now,
                       MarketpriceDoc.Field.PORT: "Seville",
                       MarketpriceDoc.Field.TRADEGOOD: tradegood,
                       MarketpriceDoc.Field.RATE: 60,
                       MarketpriceDoc.Field.TREND: Trend.Value.RISE,

                       MarketpriceDoc.Field.SERVER: server,
                       MarketpriceDoc.Field.CHANNEL_USER: channel_user_codename,
                       }
            collection.insert_many([doc_old, doc_new])

        MarketpriceDoc.server_ports_tradegoods2delete(server, [port], [tradegood])
        insert_docs()

        packet = {KhalaPacket.Field.TEXT: "?price 리스본,세비야 사탕무",
                  KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
                  KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  }

        hyp = NORM_LIST(PriceSkill.packet2rowsblocks(packet))
        ref = [('[사탕무] 시세', ['세비야', '리스본'])]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #12
0
    def test_03(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?culture 복분자",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = CultureSkill.packet2response(packet)
        ref = """[문화권] 복분자 우대 문화권
- 동아프리카, 페르시아"""

        # pprint({"hyp":hyp})
        self.assertEqual(hyp, ref)
コード例 #13
0
    def test_06(self):
        logger = HenriqueLogger.func_level2logger(self.test_06, logging.DEBUG)

        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])
        ServerDoc.codenames2delete([Server.Codename.MARIS])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        ChannelUser.channel_users2upsert(
            [ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        tz = pytz.timezone("Asia/Seoul")
        now_tz = DatetimeTool.datetime2truncate_seconds(datetime.now(tz))
        # hour = (now_tz + timedelta(seconds=3600)).hour

        packet1 = {
            KhalaPacket.Field.TEXT:
            "?남만 {}".format(now_tz.strftime("%I:%M %p")),
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }

        NanbanSkill.packet2response(packet1)

        packet2 = {
            KhalaPacket.Field.TEXT: "?남만 +2분 1초",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }

        NanbanSkill.packet2response(packet2)

        doc = ServerDoc.codename2doc(Server.Codename.MARIS)

        dt_nanban = DatetimeTool.astimezone(
            ServerNanban.nanban2datetime(ServerDoc.doc2nanban(doc)), tz)

        logger.debug({
            "now_tz":
            now_tz,
            "dt_nanban":
            dt_nanban,
            'now_tz.strftime("%I:%M %p")':
            now_tz.strftime("%I:%M %p"),
        })
        ref = (now_tz + timedelta(seconds=2 * 60 + 1)).timetz()
        self.assertEquals(dt_nanban.timetz(), ref)
コード例 #14
0
    def test_03(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?무엇 폭시",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = WhatSkill.packet2response(packet)
        # ref = ("[이베리아] 항구 - 세비야, 세우타, 카사블랑카, 라스팔마스, 마데이라, 파루, 리스본, 포르투, 비아나두카스텔루, 히혼, "
        #        "빌바오, 말라가, 발렌시아, 팔마, 바르셀로나, 몽펠리에, 사그레스")
        ref = "[유저] Foxytrixy"

        # pprint(hyp)
        self.assertTrue(hyp.startswith(ref))
コード例 #15
0
    def test_02(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?what 이베리아",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = WhatSkill.packet2response(packet)
        # ref = ("[이베리아] 항구 - 세비야, 세우타, 카사블랑카, 라스팔마스, 마데이라, 파루, 리스본, 포르투, 비아나두카스텔루, 히혼, "
        #        "빌바오, 말라가, 발렌시아, 팔마, 바르셀로나, 몽펠리에, 사그레스")
        ref = "[문화권] 이베리아"

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #16
0
    def test_01(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?tradegood 육두구",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = TradegoodSkill.packet2response(packet)
        ref = """[교역품] 육두구
- 종류: [☆4] 향신료
- 판매항: 룬, 암보이나"""

        pprint({"hyp": hyp})
        self.assertEqual(hyp, ref)
コード例 #17
0
    def test_01(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?port 리스본",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = PortSkill.packet2response(packet)
        ref = """[항구] 리스본
- 문화권: 이베리아
- 내성: 식료품, 가축, 조미료, 주류, 기호품, 광석, 무기류, 공예품, 총포류"""

        # pprint({"hyp":hyp})
        self.assertEqual(hyp, ref)
コード例 #18
0
    def test_02(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT: "?port 이베리아",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
        }

        hyp = PortSkill.packet2response(packet)
        # ref = ("[이베리아] 항구 - 세비야, 세우타, 카사블랑카, 라스팔마스, 마데이라, 파루, 리스본, 포르투, 비아나두카스텔루, 히혼, "
        #        "빌바오, 말라가, 발렌시아, 팔마, 바르셀로나, 몽펠리에, 사그레스")
        ref = """[항구] 이베리아 문화권
- 라스팔마스, 파루, 카사블랑카, 히혼, 팔마, 마데이라, 비아나두카스텔루, 리스본, 사그레스, 빌바오, 세비야, 바르셀로나, 포르투, 말라가, 세우타, 몽펠리에, 발렌시아"""

        # pprint({"hyp":hyp})
        self.assertEqual(hyp, ref)
コード例 #19
0
    def test_03(self):
        logger = HenriqueLogger.func_level2logger(self.test_02, logging.DEBUG)

        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        ChannelUser.channel_users2upsert(
            [ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        now_seoul = datetime.now(
            tz=pytz.timezone(HenriqueLocale.lang2tzdb("ko")))
        dt_target = now_seoul - timedelta(seconds=3 * 60)
        text = "?남만 {}".format(dt_target.strftime("%I:%M %p").lstrip("0"))
        logger.debug({
            "text": text,
            "now_seoul": now_seoul,
        })

        packet = {
            KhalaPacket.Field.TEXT: text,
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }
        response = NanbanSkill.packet2response(packet)

        # pprint(text)
        # pprint(response)

        response_lines = response.splitlines()

        span = (
            len("다음 남만 시각: "),
            len("다음 남만 시각: 3:58:00 PM (KST) "),
        )

        hyp = SpanTool.list_span2sublist(response_lines[2], span).strip()
        dt_nanban = dt_target + NanbanTimedelta.period()
        ref = dt_nanban.strftime("%I:%M:00 %p (KST)").lstrip("0")
        self.assertEqual(
            hyp,
            ref,
        )
コード例 #20
0
    def test_01(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(sender_name)
        ChannelUser.channel_users2upsert([ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        packet = {KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  KhalaPacket.Field.TEXT: "?price 리스본 육두구",
                  KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
                  }

        hyp = NORM_LIST(PriceSkill.packet2rowsblocks(packet))
        ref = [('[리스본] 시세', ['육두구'])]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #21
0
    def test_02(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(sender_name)
        ChannelUser.channel_users2upsert([ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        packet = {KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  KhalaPacket.Field.TEXT: "?price 리스본 세비야 육두구 메이스",
                  KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
                  }

        hyp = NORM_SET(PriceSkill.packet2rowsblocks(packet))
        ref = [('[육두구] 시세', {'세비야', '리스본'}),
               ('[메이스] 시세', {'세비야', '리스본'}),
               ]

        # pprint({"hyp":hyp})
        self.assertEqual(hyp, ref)
コード例 #22
0
    def test_01(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        packet = {
            KhalaPacket.Field.TEXT:
            "?항구 리스본",
            KhalaPacket.Field.CHATROOM:
            KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER:
            ChannelUserKakaotalk.sender_name2codename("iris"),
            KhalaPacket.Field.SENDER_NAME:
            "iris",
        }
        hyp = HenriquePacket.packet2response(packet)
        ref = """[항구] 리스본
- 문화권: 이베리아
- 내성: 식료품, 가축, 조미료, 주류, 기호품, 광석, 무기류, 공예품, 총포류"""

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #23
0
    def test_07(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(sender_name)
        ChannelUser.channel_users2upsert([ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        packet = {KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  KhalaPacket.Field.TEXT: "?price 리스본 육두구",
                  KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
                  }

        hyp = PriceSkill.packet2response(packet)
        ref = """[사탕무] 시세
시라쿠사 130↗ @ 방금전 [by iris]
마르세이유 80↘ @ 방금전 [by iris]
사사리 75↘ @ 방금전 [by iris]"""

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #24
0
    def test_02(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(
            sender_name)
        ChannelUser.channel_users2upsert(
            [ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        packet = {
            KhalaPacket.Field.TEXT: "?누구 iris",
            KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
            KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
            KhalaPacket.Field.SENDER_NAME: sender_name,
        }

        response = WhoSkill.packet2response(packet)

        # pprint(response)

        self.assertGreaterEqual(len(response.splitlines()), 3)
        self.assertEqual(response.splitlines()[0], "[유저] iris(아리)")
コード例 #25
0
    def test_04(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(sender_name)
        ChannelUser.channel_users2upsert([ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        server = "maris"
        ports = ["Lisbon"]
        tradegoods = ["Sugar Beet"]

        MarketpriceDoc.server_ports_tradegoods2delete(server, ports, tradegoods)
        # channel = Channel.Codename.KAKAOTALK_UWO_UWO  # discord

        packet = {KhalaPacket.Field.TEXT: "?price 사탕무 리스본 120ㅅ",
                  KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
                  KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  }

        hyp_01 = PriceSkill.packet2response(packet)
        ref_01 = """[사탕무] 시세
리스본 120↗ @ 방금전 [by iris]"""

        #pprint({"hyp_01": hyp_01})
        self.assertEqual(hyp_01, ref_01)

        price_list_latest = MarketpriceDoc.ports_tradegoods2price_list_latest(server, ports, tradegoods)
        hyp_02 = lmap(MarketpriceDoc.doc2norm_unittest, price_list_latest)
        ref_02 = [{'port': 'Lisbon',
                   'rate': 120,
                   'tradegood': 'Sugar Beet',
                   'server': 'maris',
                   'trend': 'rise',
                   'channel_user': '******',
                   }]

        # pprint({"hyp_02": hyp_02})
        self.assertEqual(hyp_02, ref_02)
コード例 #26
0
    def test_03(self):
        Chatroom.chatrooms2upsert([ChatroomKakaotalk.chatroom()])

        sender_name = "iris"
        channel_user_codename = ChannelUserKakaotalk.sender_name2codename(sender_name)
        ChannelUser.channel_users2upsert([ChannelUserKakaotalk.sender_name2channel_user(sender_name)])

        packet = {KhalaPacket.Field.CHANNEL_USER: channel_user_codename,
                  KhalaPacket.Field.SENDER_NAME: sender_name,
                  KhalaPacket.Field.TEXT: "?price 육메 이베",
                  KhalaPacket.Field.CHATROOM: KakaotalkUWOChatroom.codename(),
                  }

        hyp = NORM_SET(PriceSkill.packet2rowsblocks(packet))
        ref = [('[육두구] 시세',
                {'바르셀로나', '발렌시아', "히혼", "팔마", "빌바오", "세비야", "말라가", "사그레스", "리스본", "세우타", "파루", "라스팔마스", "마데이라",
                 "비아나두카스텔루", "몽펠리에", "카사블랑카", "포르투", }),
               ('[메이스] 시세',
                {'바르셀로나', '발렌시아', "히혼", "팔마", "빌바오", "세비야", "말라가", "사그레스", "리스본", "세우타", "파루", "라스팔마스", "마데이라",
                 "비아나두카스텔루", "몽펠리에", "카사블랑카", "포르투", }),
               ]

        # pprint({"hyp": hyp})
        self.assertEqual(hyp, ref)