コード例 #1
0
ファイル: bot.py プロジェクト: Zavxoz/KlimetsFinanceBot
]
month_array_2 = [
    'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа',
    'сентября', 'октября', 'ноября', 'декабря'
]
CREDENTIALS_FILE = 'credentials.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    CREDENTIALS_FILE, [
        'https://www.googleapis.com/auth/spreadsheets',
        'https://www.googleapis.com/auth/drive'
    ])
httpAuth = credentials.authorize(httplib2.Http())
service = apiclient.discovery.build('sheets', 'v4', http=httpAuth)
gc = gspread.authorize(credentials)
to_myself = to_both = 0
bot = AsyncTeleBot("1272834678:AAHJ85rGTY8TXj8x9K5mcg7DzliwkKHMrRA",
                   threaded=True)
markup = types.ReplyKeyboardMarkup(True, True)
markup.row('На себя', 'Обоим')


def exception(func):
    """
    Wrap up function with try-except.
    """
    @wraps(func)
    def decorated(*args, **kwargs):
        try:
            out_condition = func(*args, **kwargs)
        except Exception as ex:
            full_ex_info = '{func_name}() | {type} : {ex}'.format(
                type=type(ex).__name__, func_name=func.__name__, ex=ex)
コード例 #2
0
ファイル: main.py プロジェクト: detkatechops/flibusta_bot
from aiohttp import web

import config
import strings
from send import Sender

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

from db.models import TelegramUser, Settings
from django.db.models import ObjectDoesNotExist

bot = AsyncTeleBot(config.BOT_TOKEN, num_threads=4)
sender = Sender(bot)


def update_user(msg: ttypes.Message):
    try:
        user = TelegramUser.objects.get(user_id=msg.from_user.id)
        user.first_name = msg.from_user.first_name
        user.last_name = msg.from_user.last_name
        user.username = msg.from_user.username
    except ObjectDoesNotExist:
        user = TelegramUser.objects.create(user_id=msg.from_user.id,
                                           first_name=msg.from_user.first_name,
                                           last_name=msg.from_user.last_name,
                                           username=msg.from_user.username)
    user.save()
コード例 #3
0
import os
import argparse
import json
from yad2db import Yad2DB
from yad2request import Yad2Request, Yad2Apartment
import time
import configparser
import traceback
from locationmanager import LocationManager

CONFIG_PATH = "yad2.conf"
config = configparser.ConfigParser()
config.sections()
config.read('yad2.conf')

bot = AsyncTeleBot(config['DEFAULT']['token'])


@bot.message_handler(commands=['start'])
def command_subscribe(msg):
    with Yad2DB(msg.from_user.id) as cdb:
        bot.reply_to(msg, "Subscribed successfuly")


@bot.message_handler(commands=['query'])
def command_set_query(msg):
    bot.reply_to(msg, "Hiii")


def get_params(param_list):
    param_list = [v.split("=") for v in param_list]
コード例 #4
0
from telebot import AsyncTeleBot, types
import time
import random
import re
bot = AsyncTeleBot('636547162:AAEcNQbYlIXr5oQbXYgo-7GMYM_QIn1XtlU')

markup = types.InlineKeyboardMarkup(row_width=1)
b1 = types.InlineKeyboardButton(text='1', callback_data='one')
b2 = types.InlineKeyboardButton(text='2',callback_data='two')
markup.add(b1,b2)

@bot.message_handler(commands=['send_buttons'])
def select_buttons(message):





    task = bot.send_message(
                            chat_id=message.chat.id,
                            text='Select one of those buttons below',
                            reply_markup=markup)
    result = task.wait()
    print(result)

@bot.message_handler(regexp='\d*\.\d*')
def send_plus_one(message):
    m = re.search('\d*\.\d*',message.text)
    if m:
        num = float()
        num+=1.0
コード例 #5
0
try:
    conn = sa.create_engine('sqlite:///botDataBase.db')
    meta = sa.MetaData()
    sa.Table(CONFIGURATION_TABLE, meta,
             sa.Column('id', sa.Integer, primary_key=True),
             sa.Column('first_name', sa.String),
             sa.Column('lang_code', sa.String),
             sa.Column('curr', sa.String))  # configuration table
    meta.create_all(conn)
except Exception as e:
    print(
        e, '\nThe program have started at not the first time. '
        'Configuration tables have already created.')

TOKEN = '636547162:AAEcNQbYlIXr5oQbXYgo-7GMYM_QIn1XtlU'
bot = AsyncTeleBot(TOKEN)


def get_lang_code(uid):
    meta.reflect(bind=conn)
    table = meta.tables[CONFIGURATION_TABLE]
    lang_code = conn.execute(
        sa.select([table.c.lang_code]).where(table.c.id == uid))
    lc, = lang_code.fetchone()
    return lc


def get_curr(uid):
    meta.reflect(bind=conn)
    table = meta.tables[CONFIGURATION_TABLE]
    curr = conn.execute(sa.select([table.c.curr]).where(table.c.id == uid))
コード例 #6
0
ファイル: views.py プロジェクト: Bodyk1Love/Press
from django.views import View
from django.utils import timezone
from django.http import HttpResponse

import json
import random
import requests
from .helpers import *
from core.Press import Press
from datetime import datetime
from telebot import AsyncTeleBot, types
from summarizer.models import SavedText

bot = AsyncTeleBot("1263280130:AAE8Nz5epRXsBZPgAHlRrjXXA5SWRdRog-Q")
# https://api.telegram.org/bot1263280130:AAE8Nz5epRXsBZPgAHlRrjXXA5SWRdRog-Q/setWebhook?url=https://60e5610e.ngrok.io/telegram_web_hook


class UpdateBot(View):
    def post(self, request):
        json_str = request.body.decode('utf-8')
        update = types.Update.de_json(json_str)
        log_message(update)
        bot.process_new_updates([update])
        return HttpResponse()


@bot.message_handler(commands=['start'])
def start_message(message):
    telegram_profile = get_telegram_profile(message)
    keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True,
                                         resize_keyboard=True)
コード例 #7
0
from django.conf import settings
from ..dbmodels.auth import ScheduleUser
import time
from telebot import AsyncTeleBot, logger, types
import logging

__author__ = "@schedulebase_bot"

logger.setLevel(settings.LOG_LEVEL)

bot = AsyncTeleBot(settings.TOKEN)
bot.threaded = True

settings.BOT = bot

bot.remove_webhook()
logging.info("Removed previous webhook")
time.sleep(1)
bot.set_webhook(url=f"{settings.DOMAIN}/bot/")
logging.info("Set new webhook")
logging.info(f"Webhook info: {bot.get_webhook_info()}")