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
#!/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