Code Monkey home page Code Monkey logo

python_dz10's Introduction

import datetime
import telebot
from button import keyboard

bot = telebot.TeleBot('5604766245:AAEByki6lWouMyCIrxTWG7rZNndMPezfDQI')

value = ''
old_value = ''

@bot.message_handler(commands=['start', 'calculator'])
def getMessage(message):
    dtn = datetime.datetime.now()
    botlogfile = open('db.csv', 'a')
    print(dtn.strftime("%d-%m-%Y %H:%M"),  'username: ' + message.from_user.first_name, message.from_user.id, 'message: ' + message.text, file=botlogfile)
    botlogfile.close()    
    global value
    if value == '':
        bot.send_message(message.from_user.id, '0', reply_markup=keyboard)
    else:
        bot.send_message(message.from_user.id, value, reply_markup=keyboard) 
           
@bot.callback_query_handler(func=lambda call:True)
def callback_func(query):
    global value, old_value
    data = query.data    
    if data == 'no':
        pass
    elif data == 'C':
        value = ''
    elif data == '<=':
        if value != '':
            value = value[:len(value) - 1]    
    elif data == '=':
        try:
            value = str(eval(value))
        except:
            value = 'Ошибка'    
    else:
        value += data   
    if (value != old_value and value != '') or ('0' != old_value and value == '' ):
        if value == '':
            bot.edit_message_text(chat_id=query.message.chat.id, message_id=query.message.message_id, text='0', reply_markup=keyboard)
            old_value = '0'
        else:
            bot.edit_message_text(chat_id=query.message.chat.id, message_id=query.message.message_id, text=value, reply_markup=keyboard)
            old_value = value  
    old_value = value
    if value == 'Ошибка': value = ''                    
bot.polling(non_stop=False, interval=0)

python_dz10's People

Contributors

igor8814 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.