コード例 #1
0
async def __(msg, ctx):
    # Document
    with open(get_path(__file__, "assets/pizza.png"), "rb") as fh:
        doc = Attachment.new(fh.read(), "pizza.png")

    await ctx.reply("Document", attachments=doc)

    # Audio message
    with open(get_path(__file__, "assets/audio.ogg"), "rb") as fh:
        audio_message = Attachment.new(fh.read(), "audio.ogg", "voice")

    await ctx.reply("Audio message", attachments=audio_message)
コード例 #2
0
ファイル: documents.py プロジェクト: nm17/kutana
async def _(message, env):
    # Document
    with open(get_path(__file__, "document_assets/pizza.png"), "rb") as fh:
        doc = await env.upload_doc(fh.read(), filename="pizza.png")

    await env.reply("Document", attachment=doc)

    # Graffiti
    with open(get_path(__file__, "document_assets/pizza.png"), "rb") as fh:
        graffiti = await env.upload_doc(fh.read(), type="graffiti", filename="pizza.png")

    await env.reply("Graffiti", attachment=graffiti)

    # Audio message
    with open(get_path(__file__, "document_assets/audio.mp3"), "rb") as fh:
        audio_message = await env.upload_doc(fh.read(), type="audio_message", filename="audio.mp3")

    await env.reply("Audio message", attachment=audio_message)
コード例 #3
0
ファイル: stream.py プロジェクト: sakost/kutana
async def bg_loop(vk):
    while True:
        with open(get_path(__file__, "assets/pizza.png"), "rb") as fh:
            temp_a = Attachment.new(fh.read(), "pizza.png")

        a = await vk.upload_attachment(temp_a, peer_id=None)

        for sub in subscribers:
            await vk.send_message(sub, "", a)

        await asyncio.sleep(5)
コード例 #4
0
ファイル: documents.py プロジェクト: sakost/kutana
async def _(msg, ctx):
    # Document
    with open(get_path(__file__, "assets/pizza.png"), "rb") as fh:
        doc = Attachment.new(fh.read(), "pizza.png")

    await ctx.reply("Document", attachments=doc)

    # Graffiti (special for vk)
    with open(get_path(__file__, "assets/pizza.png"), "rb") as fh:
        graffiti = Attachment.new(fh.read(), "pizza.png", type="graffiti")

    try:
        await ctx.reply("Graffiti", attachments=graffiti)
    except ValueError:
        await ctx.reply("Can't upload this type of attachments")

    # Audio message
    with open(get_path(__file__, "assets/audio.ogg"), "rb") as fh:
        audio_message = Attachment.new(fh.read(), "audio.ogg", "voice")

    await ctx.reply("Audio message", attachments=audio_message)
コード例 #5
0
async def _(msg, ctx):
    files = files_find("/home/hord/Музыка/", ctx.body)

    if (len(files) == 0):
        await ctx.reply("Нет такой музыки...")

    else:
        filepath = files.pop()

        with open(get_path(__file__, filepath), "rb") as fh:
            audio_message = Attachment.new(fh.read(),
                                           os.path.basename(filepath), "voice")

        await ctx.reply(os.path.basename(filepath), attachments=audio_message)
コード例 #6
0
async def bg_loop(vk):
    while True:
        with open(get_path(__file__, "assets/pizza.png"), "rb") as fh:
            temp_a = Attachment.new(fh.read(), "pizza.png")

        try:
            a = await vk.upload_attachment(temp_a, peer_id=None)
        except RequestException:
            for sub in subscribers:
                await vk.send_message(sub, "Failed to upload attachment; Paused for 1 hour")

            await asyncio.sleep(60 * 60)

            continue

        for sub in subscribers:
            await vk.send_message(sub, "", a)

        await asyncio.sleep(60 * 10)
コード例 #7
0
async def _(message, env):
    with open(get_path(__file__, "send_image_assets/pizza.png"), "rb") as fh:
        image = await env.upload_photo(fh.read())

    await env.reply("", attachment=image)
コード例 #8
0
ファイル: parser.py プロジェクト: 0niel/mirea-schedule-bot
async def new_schedule_check():
    while True:
        try:
            resp = requests.get("https://www.mirea.ru/schedule/")
            soup = BeautifulSoup(resp.text, 'lxml')

            test = soup.findAll('a', class_='uk-link-toggle')
            url = test[15].get('href')

            f = open(get_path(__file__, "schedule.xlsx"), "wb")
            ufr = requests.get(url)
            f.write(ufr.content)
            f.close()

            wb = openpyxl.load_workbook(get_path(__file__, "schedule.xlsx"))
            ws = wb.active

            column_letters = {
                'schedule': '',
                'cabinets': '',
                'lesson_type': '',
                'teachers': ''
            }

            for column in range(50, 900):
                column_letter = get_column_letter(column)
                current_column = ws[column_letter]
                for cell in current_column:
                    if isinstance(cell.value, str):
                        if cell.value.find(
                                json.load(open("config.json",
                                               'r'))['group']) > -1:
                            column_letters['schedule'] = column_letter
                            column_letters['cabinets'] = get_column_letter(
                                column + 3)
                            column_letters['lesson_type'] = get_column_letter(
                                column + 1)
                            column_letters['teachers'] = get_column_letter(
                                column + 2)

            columns = {
                'schedule': ws[column_letters['schedule']],
                'cabinets': ws[column_letters['cabinets']],
                'lesson_type': ws[column_letters['lesson_type']],
                'teachers': ws[column_letters['teachers']]
            }

            column_ws_array = [[], [], [], []]

            for cell in columns['schedule']:
                column_ws_array[0].append(cell.value)

            for cell in columns['cabinets']:
                column_ws_array[1].append(cell.value)

            for cell in columns['lesson_type']:
                column_ws_array[2].append(cell.value)

            for cell in columns['teachers']:
                column_ws_array[3].append(cell.value)

            cabs = np.array_split(column_ws_array[1][3:75], 6)
            schedule = np.array_split(column_ws_array[0][3:75], 6)
            lesson_types = np.array_split(column_ws_array[2][3:75], 6)
            teachers = np.array_split(column_ws_array[3][3:75], 6)

            os.remove(get_path(__file__, "schedule.xlsx"))

            all_days_list, all_cabs_list, all_types_list, all_teachers_list = [], [], [], []

            for day in schedule:
                all_days_list.append(list(day))

            for cab in cabs:
                all_cabs_list.append(list(cab))

            for lesson_type in lesson_types:
                all_types_list.append(list(lesson_type))

            for teacher in teachers:
                all_teachers_list.append(list(teacher))

            schedule_all = schedule_collection.find_one({'type': 'schedule'})

            tz = pytz.timezone('Europe/Moscow')
            date = datetime.now(tz).weekday()

            if schedule_all is not None:
                if date == 0:
                    week_number = schedule_all['week_number'] + 1
                    is_even = True if week_number % 2 == 0 else False
                    schedule_collection.update_one({'type': 'schedule'}, {
                        '$set': {
                            'is_even': is_even,
                            'week_number': week_number
                        }
                    })

                schedule_collection.update_one({'type': 'schedule'}, {
                    '$set': {
                        'schedule': all_days_list,
                        'cabinets': all_cabs_list,
                        'lesson_types': all_types_list,
                        'teachers': all_teachers_list
                    }
                })
            else:
                schedule_collection.insert_one({
                    'type': 'schedule',
                    'schedule': all_days_list,
                    'cabinets': all_cabs_list,
                    'lesson_types': all_types_list,
                    'teachers': all_teachers_list,
                    'is_even': False,
                    'week_number': 1
                })
        except BadZipFile:
            print('Exception BadZipFile: file not found on mirea.ru')

        await asyncio.sleep(600)
コード例 #9
0
ファイル: image.py プロジェクト: pdaeks/kutana
async def __(msg, ctx):
    with open(get_path(__file__, "assets/pizza.png"), "rb") as fh:
        image = Attachment.new(fh.read(), "pizza.png")

    await ctx.reply("", attachments=image)
コード例 #10
0
async def startup_1(app):
    with open(get_path(__file__, "my_file")) as fh:
        pl1.my_file = fh.read().strip()