Example #1
0
from kutana import Plugin
from geopy.geocoders import Photon, Yandex, Nominatim
import aiohttp, json, time, datetime
plugin = Plugin(name="Weather Plugin")
plugin.category = 'Инфо и прочее'
plugin.limit = {'погода': 6}
plugin.desc = {'погода': ['{город}', 'прогноз погоды для *город*']}


@plugin.on_startup()
async def on_startup(kutana, update):
    plugin.dict = {}
    plugin.dict['token'] = '4e72572d631723e8854c3cd2e692937b'
    plugin.dict['geocoders'] = []
    plugin.dict['coords_cache'] = {}
    plugin.dict['weather_cache'] = {}
    plugin.dict['weather_clear'] = time.time() + 12 * 60 * 60
    plugin.dict['api_lim'] = 95
    plugin.dict['api_lim_clear'] = time.time() + 24 * 60 * 60
    plugin.dict['api_lim_count'] = 0
    for coder in [Photon, Yandex, Nominatim]:
        plugin.dict['geocoders'].append(coder())


async def get_weather(result):
    if plugin.dict['weather_clear'] - time.time() <= 0:
        plugin.dict['weather_clear'] = time.time() + 12 * 60 * 60
        plugin.dict['weather_cache'].clear()

    if f"{result.latitude}_{result.longitude}" in plugin.dict['weather_cache']:
        return plugin.dict['weather_cache'][
Example #2
0
from kutana import Plugin, VKController
import random, asyncio, aiohttp, json
plugin = Plugin(name="randompost")
plugin.category = 'Картинки'
plugin.category_desc = 'Присылает в чат случайные картинки определенной тематики'
plugin.desc = {"мемы": [0, 0], 'няша': [0, 0], 'цензура': [0, 0]}

commgroups = {
    "мемы": "-45745333",
    "няша": "-118445684",
    "цензура": "-137905638"
}
plugin.limit = {'посоветуй аниме': 8, 'мемы': 5, 'няша': 5, 'цензура': 5}


async def get_posts(group_id, count, offset):
    async with VKController(
            'f68c8bdf80628aff5e02739338f8c8fd948b6c05dd7b89f731739819c30137e5508ca323f34789c01d155'
    ) as group:
        result = await group.raw_request('wall.get',
                                         count=count,
                                         offset=offset,
                                         owner_id=group_id)
        return result.response


@plugin.on_text(*commgroups)
async def on_post(message, attachments, env):
    group_id = commgroups[message.text.lower()]
    smiles = ['😔', '😭', '😩', '😠', '😟', '🙁']
    vk_message, attachments = "", ""
Example #3
0
import time
import random
import lxml.html
from lxml import html
import aiohttp
from kutana import Plugin

plugin = Plugin(name="Holidays")
plugin.category = 'Инфо и прочее'
plugin.desc = {'праздники': [0, 'праздники сегодня']}
plugin.limit = {'праздники': 6}


@plugin.on_text('праздники')
async def wiki_search(message, attachments, env):
    endpoint = f'http://kakoysegodnyaprazdnik.ru'
    async with aiohttp.ClientSession() as sess:
        async with sess.post(endpoint, data=None) as resp:
            response = await resp.text()
            tree = html.fromstring(response)
            holidays = tree.xpath('//span[@itemprop="text"]/text()')
            numbers = tree.xpath('//span[@class="super"]/text()')
            vk_message = 'праздники сегодня:\n'
            for num, i in enumerate(holidays[:5], start=0):
                vk_message += '• {} ({})\n'.format(i, numbers[num])
            return await env.reply(vk_message)