예제 #1
0
파일: monday.py 프로젝트: kyunooh/yui
async def monday_dog(bot):
    monday_dog_say = functools.partial(
        bot.api.chat.postMessage,
        channel=C.general.get(),
        as_user=False,
        username='******',
        icon_url='https://i.imgur.com/UtBQSLl.jpg',
    )
    today = now()
    holiday = await get_holiday_name(today)

    if holiday:
        says = [
            '월' * random.randint(5, 15) + '…' + ''.join(
                random.choice(['?', '!']) for x in range(random.randint(3, 10))
            ),
            '(하지만 {}이라 쉬는 날이었다고 한다)'.format(holiday)
        ]
        for say in says:
            await monday_dog_say(text=say)
    else:
        says = [
            '월' * random.randint(60, 220),
            ''.join(
                '월' * random.randint(1, 6) + '!' * random.randint(1, 3)
                for x in range(40)
            ),
            '월요일' * random.randint(30, 70),
        ]
        random.shuffle(says)

        for say in says[:bot.config.get('MONDAY_DOG_LIMIT', len(says))]:
            await monday_dog_say(text=say)
예제 #2
0
def test_aws_model_with_aware_dt(fx_sess):
    now_dt = now()

    record = AWS()
    record.name = '인천'
    record.height = 1234
    record.is_raining = True
    record.rain15 = 111.111
    record.rain60 = 222.222
    record.rain6h = 333.333
    record.rain12h = 444.444
    record.rainday = 555.555
    record.temperature = 12.34
    record.wind_direction1 = 'SSW'
    record.wind_speed1 = 11.11
    record.wind_direction10 = 'NNE'
    record.wind_speed10 = 22.22
    record.humidity = 55
    record.pressure = 1234.56
    record.location = '인천광역시 중구 전동'
    record.observed_at = now_dt

    with fx_sess.begin():
        fx_sess.add(record)

    assert record.observed_at == now_dt
    assert record.observed_datetime == now_dt.replace(tzinfo=None)
    assert record.observed_timezone is pytz.timezone('Asia/Seoul')
예제 #3
0
파일: commands_test.py 프로젝트: hunj/yui
async def test_search_aws_zone(fx_sess):
    dt = now()

    bot = FakeBot()
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'ts': '1234.5678'
    })

    await search_aws_zone(bot, event, fx_sess, 'name', '인')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과가 없어요!'
    assert said.data['thread_ts'] == '1234.5678'

    record = AWS()
    record.name = '인천'
    record.height = 1234
    record.is_raining = True
    record.rain15 = 111.111
    record.rain60 = 222.222
    record.rain6h = 333.333
    record.rain12h = 444.444
    record.rainday = 555.555
    record.temperature = 12.34
    record.wind_direction1 = 'SSW'
    record.wind_speed1 = 11.11
    record.wind_direction10 = 'NNE'
    record.wind_speed10 = 22.22
    record.humidity = 55
    record.pressure = 1234.56
    record.location = '인천광역시 중구 전동'
    record.observed_at = dt

    with fx_sess.begin():
        fx_sess.add(record)

    await search_aws_zone(bot, event, fx_sess, 'name', '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과는 다음과 같습니다.\n\n인천(인천광역시 중구 전동)'
    assert said.data['thread_ts'] == '1234.5678'

    await search_aws_zone(bot, event, fx_sess, 'location', '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과는 다음과 같습니다.\n\n인천(인천광역시 중구 전동)'
    assert said.data['thread_ts'] == '1234.5678'
예제 #4
0
def test_rss_feed_sub_model_with_aware_dt(fx_sess):
    now_dt = now()

    record = RssFeedSub()
    record.url = 'http://example.com'
    record.channel = 'C1'
    record.updated_at = now_dt

    with fx_sess.begin():
        fx_sess.add(record)

    assert record.updated_at == now_dt
    assert record.updated_datetime == now_dt.replace(tzinfo=None)
    assert record.updated_timezone is pytz.timezone('Asia/Seoul')
예제 #5
0
파일: cache_test.py 프로젝트: kyunooh/yui
def test_json_cache_model_with_aware_dt(fx_sess):
    now_dt = now()

    record = JSONCache()
    record.name = 'test'
    record.body = 'Hello!'
    record.created_at = now_dt

    with fx_sess.begin():
        fx_sess.add(record)

    assert record.created_at == now_dt
    assert record.created_datetime == now_dt.replace(tzinfo=None)
    assert record.created_timezone is pytz.timezone('Asia/Seoul')
예제 #6
0
파일: models_test.py 프로젝트: hunj/yui
def test_memo_model_with_aware_dt(fx_sess):
    now_dt = now()

    record = Memo()
    record.keyword = 'test'
    record.text = 'test test'
    record.author = 'U1'
    record.created_at = now_dt

    with fx_sess.begin():
        fx_sess.add(record)

    assert record.created_at == now_dt
    assert record.created_datetime == now_dt.replace(tzinfo=None)
    assert record.created_timezone is pytz.timezone('Asia/Seoul')
예제 #7
0
async def weekend_loading(bot, event: Message):
    """
    주말로딩

    주말까지 얼마나 남았는지 출력합니다.

    `{PREFIX}주말로딩`

    """

    now_dt = now()
    percent = weekend_loading_percent(now_dt)
    if percent == 100.0:
        await bot.say(event.channel, '주말이에요! 즐거운 주말 되세요!')
    else:
        await bot.say(event.channel, f'주말로딩… {percent:.2f}%')
예제 #8
0
파일: commands_test.py 프로젝트: hunj/yui
async def test_aws(fx_sess):
    dt = now()

    bot = FakeBot()
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과가 없어요!'

    record = AWS()
    record.name = '인천'
    record.height = 1234
    record.is_raining = True
    record.rain15 = 111.111
    record.rain60 = 222.222
    record.rain6h = 333.333
    record.rain12h = 444.444
    record.rainday = 555.555
    record.temperature = 12.34
    record.wind_direction1 = 'SSW'
    record.wind_speed1 = 11.11
    record.wind_direction10 = 'NNE'
    record.wind_speed10 = 22.22
    record.humidity = 55
    record.pressure = 1234.56
    record.location = '인천광역시 중구 전동'
    record.observed_at = dt

    with fx_sess.begin():
        fx_sess.add(record)

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '[{}@인천/인천광역시 중구 전동]'
        ' 강수: 예(15min: 111.111/일일: 555.555)'
        ' / 12.34℃ / 바람: 남남서 11.11㎧ / 습도: 55% / 해면기압: 1234.56hPa'
    ).format(
        dt.strftime('%Y년 %m월 %d일 %H시 %M분')
    )

    record2 = AWS()
    record2.name = '인천'
    record2.height = 1234
    record2.is_raining = True
    record2.rain15 = 111.111
    record2.rain60 = 222.222
    record2.rain6h = 333.333
    record2.rain12h = 444.444
    record2.rainday = 555.555
    record2.temperature = 12.34
    record2.wind_direction1 = 'SSW'
    record2.wind_speed1 = 11.11
    record2.wind_direction10 = 'NNE'
    record2.wind_speed10 = 22.22
    record2.humidity = 55
    record2.pressure = 1234.56
    record2.location = '인천광역시 중구 전동'
    record2.observed_at = dt

    with fx_sess.begin():
        fx_sess.add(record2)

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '검색 결과가 여러가지 있어요! 시스템 관리자에게 문의해주세요!'
    )
예제 #9
0
async def auto_weekend_loading(bot):
    now_dt = now()
    percent = weekend_loading_percent(now_dt)
    await bot.say(C.general.get(), f'주말로딩… {percent:.2f}%')