Created
March 28, 2019 18:29
-
-
Save bart02/0cbff421e8717a7ea60dcdc89233b7aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | |
| import logging | |
| from uncv import classificate | |
| # Enable logging | |
| logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
| level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def start(bot, update): | |
| update.message.reply_text('Hi!') | |
| def help(bot, update): | |
| update.message.reply_text('Help!') | |
| def img(bot, update): | |
| photo = update.message.photo[-2] | |
| file = bot.get_file(photo.file_id) | |
| file.download('tmp.jpg') | |
| num = classificate('tmp.jpg') | |
| if num != 0: | |
| update.message.reply_text('Это шестерня номер ' + str(num)) | |
| else: | |
| update.message.reply_text('Шестерня не найдена') | |
| def error(bot, update, error): | |
| logger.warning('Update "%s" caused error "%s"', update, error) | |
| def main(): | |
| updater = Updater("token") | |
| dp = updater.dispatcher | |
| dp.add_handler(CommandHandler("start", start)) | |
| dp.add_handler(CommandHandler("help", help)) | |
| dp.add_handler(MessageHandler(Filters.photo, img)) | |
| dp.add_error_handler(error) | |
| updater.start_polling() | |
| updater.idle() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment