Example #1
0
import logging
import asyncio
import aioredis
import aiohttp
import os
import json
from aiotg import TgBot

with open("config.json") as cfg:
    config = json.load(cfg)

bot = TgBot(**config)

logger = logging.getLogger("WhatisBot")
redis = None


async def search_wiki(text, lang="en"):
    url = "https://{0}.wikipedia.org/w/api.php".format(lang)
    params = {
        'titles': text,
        'action': 'query',
        'exintro': '',
        'format': 'json',
        'prop': 'extracts',
        'explaintext': '',
        'redirects': ''
    }
    response = await aiohttp.get(url, params=params)
    assert response.status == 200
    return (await response.json())
Example #2
0
File: echo.py Project: ixtel/aiotg
import os
from aiotg import TgBot

bot = TgBot(os.environ["API_TOKEN"])

@bot.command(r"/echo (.+)")
def echo(chat, match):
    return chat.reply(match.group(1))

if __name__ == '__main__':
    bot.run()
import asyncio
from aiotg import TgBot
from get_data_viktorina import get_data as get_data_viktorina
from get_question import Question_loop

# Debug mode
# PYTHONASYNCIODEBUG = 1

API = '89885175:AAEFAgCwgS-ITZ6uZo0rqOeRSofydT4bzrQ'
NUM_HANDLERS = 5

data_questions = get_data_viktorina()
bot = TgBot(API)
sem = asyncio.Semaphore(NUM_HANDLERS)
loop = asyncio.get_event_loop()

active_users = {}


@asyncio.coroutine
def send_message(chat_id, text, bot=bot):
    with (yield from sem):
        yield from bot._send_message(chat_id=chat_id, text=text, disable_web_page_preview='true')

question_loop = Question_loop(loop, active_users, send_message)


@bot.command(r"/start")
def start(message, match):
    if not message.is_group():
        print('Приєднався ',message.sender)
Example #4
0
#!/usr/bin/env python3
import logging
import asyncio
import aiohttp
import os
import json

from aiotg import TgBot
from math import ceil

LEAFLY_HEADERS = {
    "app_id": os.environ["LEAFLY_APP_ID"],
    "app_key": os.environ["LEAFLY_APP_KEY"]
}

bot = TgBot(os.environ["API_TOKEN"])
logger = logging.getLogger("StonerBot")


def format_strain(strain):
    def names(section):
        return (i["Name"] for i in strain[section])

    stars = "⭐" * ceil(strain["Rating"] / 2)
    positive = ", ".join(names("Tags"))
    negative = ", ".join(names("NegativeEffects"))
    symptoms = ", ".join(names("Symptoms"))

    text = "%s (%s)\n" % (strain["Name"], strain["Category"])
    if stars != "":
        text += "     %s\n" % stars
Example #5
0
import logging
import asyncio
import aioredis
import aiohttp
import os
import json
from aiotg import TgBot

with open("config.json") as cfg:
    config = json.load(cfg)

bot = TgBot(**config)

logger = logging.getLogger("WhatisBot")
redis = None


async def search_wiki(text, lang="en"):
    url = "https://{0}.wikipedia.org/w/api.php".format(lang)
    params = {
        'titles': text,
        'action': 'query',
        'exintro': '',
        'format': 'json',
        'prop': 'extracts',
        'explaintext': '',
        'redirects': ''
    }
    response = await aiohttp.get(url, params=params)
    assert response.status == 200
    return (await response.json())
import os
import asyncio
import aiohttp
from aiotg import TgBot

#Debug mode
#PYTHONASYNCIODEBUG = 1

API = ''
NUM_HANDLERS = 5

bot = TgBot(API)
sem = asyncio.Semaphore(NUM_HANDLERS)


@bot.command(r"/(start|help)")
def help(message, match):
    return message.reply(
        'Бот автоматично виправляє повідомлення на синтаксично правильні,\
        щоб корисуватись ботом, просто пишіть в чат\n\
        /help -- це повідомлення\
        в своїй роботі використовує https://tech.yandex.ru/speller/'
        )

@bot.default
def message_def(message):
    asyncio.Task(handler_message(message),loop=loop)
    


@asyncio.coroutine
Example #7
0
# logging config
# ###############################
logger = logging.getLogger("EMT_MadridBot")
logger.setLevel(logging.INFO)
logger.propagate = False

ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s|%(levelname)s|%(name)s|%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
# ###############################
urllib3.disable_warnings()

bot = TgBot(**config)

with open("config_emt.json") as cfg:
    emt_credentials = json.load(cfg)

EMT_URL = "https://openbus.emtmadrid.es:9443/emt-proxy-server/last/"


def make_request(uri, fields):
    headers = {"Content-Type": "application/x-www-form-urlencoded"}
    payload = emt_credentials
    payload.update(fields)

    raw = urllib.parse.urlencode(payload)
    logger.info("SEND|{}|{}".format(uri, fields))
    response = requests.post(