mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
commit
357815b102
16 changed files with 87 additions and 69 deletions
23
README.rst
23
README.rst
|
@ -16,6 +16,10 @@ Table of contents
|
|||
|
||||
- `Status`_
|
||||
|
||||
1. `Telegram API support`_
|
||||
|
||||
2. `Python Version support`_
|
||||
|
||||
- `Installing`_
|
||||
|
||||
- `Getting the code`_
|
||||
|
@ -32,12 +36,16 @@ Table of contents
|
|||
_`Introduction`
|
||||
===============
|
||||
|
||||
This library provides a pure Python interface for the `Telegram Bot API <https://core.telegram.org/bots/api>`_. It works with Python versions from 2.6+. Python 3 support is under development. It also works with `Google App Engine <https://cloud.google.com/appengine>`_ (billing has to be enabled for fully Socket API support).
|
||||
This library provides a pure Python interface for the `Telegram Bot API <https://core.telegram.org/bots/api>`_. It works with Python versions from 2.6+. It also works with `Google App Engine <https://cloud.google.com/appengine>`_ (billing has to be enabled for fully Socket API support).
|
||||
|
||||
=========
|
||||
_`Status`
|
||||
=========
|
||||
|
||||
-----------------------
|
||||
_`Telegram API support`
|
||||
-----------------------
|
||||
|
||||
========================= ============
|
||||
Telegram Bot API Method *Supported?*
|
||||
========================= ============
|
||||
|
@ -56,6 +64,19 @@ getUserProfilePhotos Yes
|
|||
setWebhook Yes
|
||||
========================= ============
|
||||
|
||||
-------------------------
|
||||
_`Python Version support`
|
||||
-------------------------
|
||||
|
||||
============== ============
|
||||
Python Version *Supported?*
|
||||
============== ============
|
||||
2.6 Yes
|
||||
2.7 Yes
|
||||
3.3 Yes
|
||||
3.4 Yes
|
||||
============== ============
|
||||
|
||||
=============
|
||||
_`Installing`
|
||||
=============
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Audio(object):
|
||||
class Audio(Base):
|
||||
def __init__(self,
|
||||
file_id,
|
||||
duration,
|
||||
|
@ -30,6 +31,3 @@ class Audio(object):
|
|||
if self.file_size:
|
||||
json_data['file_size'] = self.file_size
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Contact(object):
|
||||
class Contact(Base):
|
||||
def __init__(self,
|
||||
phone_number,
|
||||
first_name,
|
||||
|
@ -29,7 +30,4 @@ class Contact(object):
|
|||
json_data['last_name'] = self.last_name
|
||||
if self.user_id:
|
||||
json_data['user_id'] = self.user_id
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Document(object):
|
||||
class Document(Base):
|
||||
def __init__(self,
|
||||
file_id,
|
||||
thumb,
|
||||
|
@ -40,7 +41,4 @@ class Document(object):
|
|||
json_data['mime_type'] = self.mime_type
|
||||
if self.file_size:
|
||||
json_data['file_size'] = self.file_size
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -21,7 +21,4 @@ class ForceReply(ReplyMarkup):
|
|||
json_data = {'force_reply': self.force_reply}
|
||||
if self.selective:
|
||||
json_data['selective'] = self.selective
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class GroupChat(object):
|
||||
class GroupChat(Base):
|
||||
def __init__(self,
|
||||
id,
|
||||
title):
|
||||
|
@ -19,7 +20,4 @@ class GroupChat(object):
|
|||
def to_json(self):
|
||||
json_data = {'id': self.id,
|
||||
'title': self.title}
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Location(object):
|
||||
class Location(Base):
|
||||
def __init__(self,
|
||||
longitude,
|
||||
latitude):
|
||||
|
@ -19,7 +20,4 @@ class Location(object):
|
|||
def to_json(self):
|
||||
json_data = {'longitude': self.longitude,
|
||||
'latitude': self.latitude}
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Message(object):
|
||||
class Message(Base):
|
||||
def __init__(self,
|
||||
message_id,
|
||||
from_user,
|
||||
|
@ -202,7 +203,4 @@ class Message(object):
|
|||
json_data['delete_chat_photo'] = self.delete_chat_photo
|
||||
if self.group_chat_created:
|
||||
json_data['group_chat_created'] = self.group_chat_created
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class PhotoSize(object):
|
||||
class PhotoSize(Base):
|
||||
def __init__(self,
|
||||
file_id,
|
||||
width,
|
||||
|
@ -28,7 +29,4 @@ class PhotoSize(object):
|
|||
'height': self.height}
|
||||
if self.file_size:
|
||||
json_data['file_size'] = self.file_size
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -1,9 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class ReplyMarkup(object):
|
||||
class ReplyMarkup(Base):
|
||||
def to_json(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
raise NotImplementedError
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Sticker(object):
|
||||
class Sticker(Base):
|
||||
def __init__(self,
|
||||
file_id,
|
||||
width,
|
||||
|
@ -38,7 +39,4 @@ class Sticker(object):
|
|||
'thumb': self.thumb.to_json()}
|
||||
if self.file_size:
|
||||
json_data['file_size'] = self.file_size
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
26
telegram/telegram_boject_base.py
Normal file
26
telegram/telegram_boject_base.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
from telegram import TelegramError
|
||||
|
||||
|
||||
class Base(object):
|
||||
|
||||
"""Base class for most telegram object"""
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
|
||||
def __getitem__(self, item):
|
||||
try:
|
||||
return self.__dict__[item]
|
||||
except KeyError as e:
|
||||
raise TelegramError(str(e))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def to_json(self):
|
||||
pass
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Update(object):
|
||||
class Update(Base):
|
||||
def __init__(self,
|
||||
update_id,
|
||||
message=None):
|
||||
|
@ -26,7 +27,4 @@ class Update(object):
|
|||
json_data = {'update_id': self.update_id}
|
||||
if self.message:
|
||||
json_data['message'] = self.message.to_json()
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class User(object):
|
||||
class User(Base):
|
||||
def __init__(self,
|
||||
id,
|
||||
first_name,
|
||||
|
@ -37,7 +38,4 @@ class User(object):
|
|||
json_data['last_name'] = self.last_name
|
||||
if self.username:
|
||||
json_data['username'] = self.username
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class UserProfilePhotos(object):
|
||||
class UserProfilePhotos(Base):
|
||||
def __init__(self,
|
||||
total_count,
|
||||
photos):
|
||||
|
@ -32,7 +33,4 @@ class UserProfilePhotos(object):
|
|||
json_data['photos'] = []
|
||||
for photo in self.photos:
|
||||
json_data['photos'].append([x.to_json() for x in photo])
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
|
||||
import json
|
||||
from .telegram_boject_base import Base
|
||||
|
||||
|
||||
class Video(object):
|
||||
class Video(Base):
|
||||
def __init__(self,
|
||||
file_id,
|
||||
width,
|
||||
|
@ -52,7 +53,4 @@ class Video(object):
|
|||
json_data['file_size'] = self.file_size
|
||||
if self.caption:
|
||||
json_data['caption'] = self.caption
|
||||
return json.dumps(json_data)
|
||||
|
||||
def __str__(self):
|
||||
return self.to_json()
|
||||
return json.dumps(json_data)
|
Loading…
Reference in a new issue