diff --git a/examples/detailed_example/detailed_example.py b/examples/detailed_example/detailed_example.py index 8fad9af..4bd428b 100644 --- a/examples/detailed_example/detailed_example.py +++ b/examples/detailed_example/detailed_example.py @@ -33,7 +33,7 @@ def get_user_step(uid): else: knownUsers.append(uid) userStep[uid] = 0 - print "New user detected, who hasn't used \"/start\" yet" + print("New user detected, who hasn't used \"/start\" yet") return 0 @@ -45,7 +45,7 @@ def listener(messages): for m in messages: if m.content_type == 'text': # print the sent message to the console - print str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text + print(str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text) bot = telebot.TeleBot(TOKEN) diff --git a/examples/inline_example.py b/examples/inline_example.py index c97dea2..725708e 100644 --- a/examples/inline_example.py +++ b/examples/inline_example.py @@ -69,5 +69,5 @@ if __name__ == '__main__': try: main_loop() except KeyboardInterrupt: - print >> sys.stderr, '\nExiting by user request.\n' + print('\nExiting by user request.\n') sys.exit(0) diff --git a/examples/telebot_bot/telebot_bot.py b/examples/telebot_bot/telebot_bot.py index cd29276..46319ce 100644 --- a/examples/telebot_bot/telebot_bot.py +++ b/examples/telebot_bot/telebot_bot.py @@ -70,7 +70,7 @@ def on_start(message): def listener(messages): for m in messages: - print str(m) + print(str(m)) bot.set_update_listener(listener) bot.polling() diff --git a/examples/webhook_examples/webhook_cpython_echo_bot.py b/examples/webhook_examples/webhook_cpython_echo_bot.py index 5c1dfc9..807b5a7 100644 --- a/examples/webhook_examples/webhook_cpython_echo_bot.py +++ b/examples/webhook_examples/webhook_cpython_echo_bot.py @@ -4,7 +4,13 @@ # This is a simple echo bot using decorators and webhook with BaseHTTPServer # It echoes any incoming text messages and does not use the polling method. -import BaseHTTPServer +try: + # Python 2 + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer +except ImportError: + # Python 3 + from http.server import BaseHTTPRequestHandler, HTTPServer + import ssl import telebot import logging @@ -38,7 +44,7 @@ bot = telebot.TeleBot(API_TOKEN) # WebhookHandler, process webhook calls -class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler): +class WebhookHandler(BaseHTTPRequestHandler): server_version = "WebhookHandler/1.0" def do_HEAD(self): @@ -88,7 +94,7 @@ bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH, certificate=open(WEBHOOK_SSL_CERT, 'r')) # Start server -httpd = BaseHTTPServer.HTTPServer((WEBHOOK_LISTEN, WEBHOOK_PORT), +httpd = HTTPServer((WEBHOOK_LISTEN, WEBHOOK_PORT), WebhookHandler) httpd.socket = ssl.wrap_socket(httpd.socket,