This commit is contained in:
Leandro Toledo 2015-11-11 11:25:05 -02:00
commit 235dcd2ad2
6 changed files with 223 additions and 141 deletions

View file

@ -1,189 +1,260 @@
2015-11-10
Released 2.9
Emoji class now uses bytes_to_native_str from future 3rd party lib
Make user_from optional to work with channels channels
Raise exception if Telegram times out on long-polling
*Special thanks to @jh0ker for all hard work*
**2015-11-10**
*Released 2.9.1*
- Add parameter ``network_delay`` to Bot.getUpdates for slow connections
**2015-11-10**
*Released 2.9*
- Emoji class now uses ``bytes_to_native_str`` from ``future`` 3rd party lib
- Make ``user_from`` optional to work with channels
- Raise exception if Telegram times out on long-polling
*Special thanks to @jh0ker for all hard work*
2015-10-08
Released 2.8.7
Type as optional for GroupChat class
**2015-10-08**
*Released 2.8.7*
- Type as optional for ``GroupChat`` class
2015-10-08
Released 2.8.6
Adds type to User and GroupChat classes (pre-release Telegram feature)
**2015-10-08**
*Released 2.8.6*
- Adds type to ``User`` and ``GroupChat`` classes (pre-release Telegram feature)
2015-09-24
Released 2.8.5
Handles HTTP Bad Gateway (503) errors on request
Fixes regression on Audio and Document for unicode fields
**2015-09-24**
*Released 2.8.5*
- Handles HTTP Bad Gateway (503) errors on request
- Fixes regression on ``Audio`` and ``Document`` for unicode fields
2015-09-20
Released 2.8.4
getFile and File.download is now fully supported
**2015-09-20**
*Released 2.8.4*
- ``getFile`` and ``File.download`` is now fully supported
2015-09-10
Released 2.8.3
Moved Bot._requestURL to its own class (telegram.utils.request)
Much better, such wow, Telegram Objects tests
Add consistency for str properties on Telegram Objects
Better design to test if chat_id is invalid
Add ability to set custom filename on Bot.sendDocument(..,filename='')
Fix Sticker as InputFile
Send JSON requests over urlencoded post data
Markdown support for Bot.sendMessage(..., parse_mode=ParseMode.MARKDOWN)
Refactor of TelegramError class (no more handling IOError or URLError)
**2015-09-10**
*Released 2.8.3*
- Moved ``Bot._requestURL`` to its own class (``telegram.utils.request``)
- Much better, such wow, Telegram Objects tests
- Add consistency for ``str`` properties on Telegram Objects
- Better design to test if ``chat_id`` is invalid
- Add ability to set custom filename on ``Bot.sendDocument(..,filename='')``
- Fix Sticker as ``InputFile``
- Send JSON requests over urlencoded post data
- Markdown support for ``Bot.sendMessage(..., parse_mode=ParseMode.MARKDOWN)``
- Refactor of ``TelegramError`` class (no more handling ``IOError`` or ``URLError``)
2015-09-05
Released 2.8.2
Fix regression on Telegram ReplyMarkup
Add certificate to is_inputfile method
**2015-09-05**
*Released 2.8.2*
- Fix regression on Telegram ReplyMarkup
- Add certificate to ``is_inputfile`` method
2015-09-05
Released 2.8.1
Fix regression on Telegram objects with thumb properties
**2015-09-05**
*Released 2.8.1*
- Fix regression on Telegram objects with thumb properties
2015-09-04
Released 2.8
TelegramError when chat_id is empty for send* methods
setWebhook now supports sending self-signed certificate
Huge redesign of existing Telegram classes
Added support for PyPy
Added docstring for existing classes
**2015-09-04**
*Released 2.8*
- TelegramError when ``chat_id`` is empty for send* methods
- ``setWebhook`` now supports sending self-signed certificate
- Huge redesign of existing Telegram classes
- Added support for PyPy
- Added docstring for existing classes
2015-08-19
Released 2.7.1
Fixed JSON serialization for message
**2015-08-19**
*Released 2.7.1*
- Fixed JSON serialization for ``message``
2015-08-17
Released 2.7
Added support for Voice object and sendVoice method
Due backward compatibility performer or/and title will be required for sendAudio
Fixed JSON serialization when forwarded message
**2015-08-17**
*Released 2.7*
- Added support for ``Voice`` object and ``sendVoice`` method
- Due backward compatibility performer or/and title will be required for ``sendAudio``
- Fixed JSON serialization when forwarded message
2015-08-15
Released 2.6.1
Fixed parsing image header issue on < Python 2.7.3
**2015-08-15**
*Released 2.6.1*
- Fixed parsing image header issue on < Python 2.7.3
2015-08-14
Released 2.6.0
Depreciation of require_authentication and clearCredentials methods
Giving AUTHORS the proper credits for their contribution for this project
Message.date and Message.forward_date are now datetime objects
**2015-08-14**
*Released 2.6.0*
- Depreciation of ``require_authentication`` and ``clearCredentials`` methods
- Giving ``AUTHORS`` the proper credits for their contribution for this project
- ``Message.date`` and ``Message.forward_date`` are now ``datetime`` objects
2015-08-12
Released 2.5.3
telegram.Bot now supports to be unpickled
**2015-08-12**
*Released 2.5.3*
- ``telegram.Bot`` now supports to be unpickled
2015-08-11
Released 2.5.2
New changes from Telegram Bot API have been applied
telegram.Bot now supports to be pickled
Return empty str instead None when message.text is empty
**2015-08-11**
*Released 2.5.2*
- New changes from Telegram Bot API have been applied
- ``telegram.Bot`` now supports to be pickled
- Return empty ``str`` instead ``None`` when ``message.text`` is empty
2015-08-10
Released 2.5.1
Moved from GPLv2 to LGPLv3
**2015-08-10**
*Released 2.5.1*
- Moved from GPLv2 to LGPLv3
2015-08-09
Released 2.5
Fixes logging calls in API
**2015-08-09**
*Released 2.5*
- Fixes logging calls in API
2015-08-08
Released 2.4
Fixes Emoji class for Python 3
PEP8 improvements
**2015-08-08**
*Released 2.4*
- Fixes ``Emoji`` class for Python 3
- ``PEP8`` improvements
2015-08-08
Released 2.3
Fixes ForceReply class
Remove logging.basicConfig from library
**2015-08-08**
*Released 2.3*
- Fixes ``ForceReply`` class
- Remove ``logging.basicConfig`` from library
2015-07-25
Released 2.2
Allows debug=True when initializing telegram.Bot
**2015-07-25**
*Released 2.2*
- Allows ``debug=True`` when initializing ``telegram.Bot``
2015-07-20
Released 2.1
Fix to_dict for Document and Video
**2015-07-20**
*Released 2.1*
- Fix ``to_dict`` for ``Document`` and ``Video``
2015-07-19
Released 2.0
Fixes bugs
Improves __str__ over to_json()
Creates abstractclass TelegramObject
**2015-07-19**
*Released 2.0*
- Fixes bugs
- Improves ``__str__`` over ``to_json()``
- Creates abstract class ``TelegramObject``
2015-07-15
Released 1.9
Python 3 officially supported
PEP8 improvements
**2015-07-15**
*Released 1.9*
- Python 3 officially supported
- ``PEP8`` improvements
2015-07-12
Released 1.8
Fixes crash when replying an unicode text message (special thanks to JRoot3D)
**2015-07-12**
*Released 1.8*
- Fixes crash when replying an unicode text message (special thanks to JRoot3D)
2015-07-11
Released 1.7
Fixes crash when username is not defined on chat (special thanks to JRoot3D)
**2015-07-11**
*Released 1.7*
- Fixes crash when ``username`` is not defined on ``chat`` (special thanks to JRoot3D)
2015-07-10
Released 1.6
Improvements for GAE support
**2015-07-10**
*Released 1.6*
- Improvements for GAE support
2015-07-10
Released 1.5
Fixes randomly unicode issues when using InputFile
**2015-07-10**
*Released 1.5*
- Fixes randomly unicode issues when using ``InputFile``
2015-07-10
Released 1.4
requests lib is no longer required
Google App Engine (GAE) is supported
**2015-07-10**
*Released 1.4*
- ``requests`` lib is no longer required
- Google App Engine (GAE) is supported
2015-07-10
Released 1.3
Added support to setWebhook (special thanks to macrojames)
**2015-07-10**
*Released 1.3*
- Added support to ``setWebhook`` (special thanks to macrojames)
2015-07-09
Released 1.2
CustomKeyboard classes now available
Emojis available
PEP8 improvements
**2015-07-09**
*Released 1.2*
- ``CustomKeyboard`` classes now available
- Emojis available
- ``PEP8`` improvements
2015-07-08
Released 1.1
PyPi package now available
**2015-07-08**
*Released 1.1*
- PyPi package now available
2015-07-08
Released 1.0
Initial checkin of python-telegram-bot
**2015-07-08**
*Released 1.0*
- Initial checkin of python-telegram-bot

View file

@ -60,7 +60,7 @@ author = u'Leandro Toledo'
# The short X.Y version.
version = '2.9'
# The full version, including alpha/beta/rc tags.
release = '2.9'
release = '2.9.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View file

@ -53,13 +53,13 @@ def echo(bot):
chat_id = update.message.chat_id
reply_text = update.message.text
if (reply_text):
if reply_text:
# Reply the message
bot.sendMessage(chat_id=chat_id,
text=reply_text)
# Updates global offset to get the new updates
LAST_UPDATE_ID = update.update_id + 1
# Updates global offset to get the new updates
LAST_UPDATE_ID = update.update_id + 1
if __name__ == '__main__':

View file

@ -26,7 +26,7 @@ def requirements():
setup(
name='python-telegram-bot',
version='2.9',
version='2.9.1',
author='Leandro Toledo',
author_email='leandrotoledodesouza@gmail.com',
license='LGPLv3',

View file

@ -649,7 +649,8 @@ class Bot(TelegramObject):
def getUpdates(self,
offset=None,
limit=100,
timeout=0):
timeout=0,
network_delay=2.):
"""Use this method to receive incoming updates using long polling.
Args:
@ -665,6 +666,11 @@ class Bot(TelegramObject):
timeout:
Timeout in seconds for long polling. Defaults to 0, i.e. usual
short polling.
network_delay:
Additional timeout in seconds to allow the response from Telegram
to take some time when using long polling. Defaults to 2, which
should be enough for most connections. Increase it if it takes very
long for data to be transmitted from and to the Telegram servers.
Returns:
A list of telegram.Update objects are returned.
@ -680,7 +686,7 @@ class Bot(TelegramObject):
if timeout:
data['timeout'] = timeout
result = request.post(url, data)
result = request.post(url, data, network_delay=network_delay)
if result:
self.logger.info(

View file

@ -20,6 +20,7 @@
"""This module contains methods to make POST and GET requests"""
import json
import socket
from ssl import SSLError
try:
@ -67,22 +68,26 @@ def get(url):
def post(url,
data):
data,
network_delay=2.):
"""Request an URL.
Args:
url:
The web location we want to retrieve.
data:
A dict of (str, unicode) key/value pairs.
network_delay:
Additional timeout in seconds to allow the response from Telegram to
take some time.
Returns:
A JSON object.
"""
# Add one second to the timeout of urlopen to allow data to be transferred
# over the network.
# Add time to the timeout of urlopen to allow data to be transferred over
# the network.
if 'timeout' in data:
timeout = data['timeout'] + 1.
timeout = data['timeout'] + network_delay
else:
timeout = None
@ -107,11 +112,11 @@ def post(url,
message = _parse(error.read())
raise TelegramError(message)
except SSLError as error:
if "The read operation timed out" == error.message:
except (SSLError, socket.timeout) as error:
if "operation timed out" in str(error):
raise TelegramError("Timed out")
raise TelegramError(error.message)
raise TelegramError(str(error))
return _parse(result)