Exemplo n.º 1
0
    def build_from_json(jmessage):
        """

        :param jmessage: A dictionary that contains JSON-parsed object
        :type jmessage: dict
        :rtype: Message
        """
        msgfrom = User.build_from_json(jmessage['from'])
        chat = Chat.build_from_json(jmessage['chat'])
        message = Message(int(jmessage['message_id']), msgfrom, int(jmessage['date']), chat)
        if 'forward_from' in jmessage.keys():
            message.set_forward_from(User.build_from_json(jmessage['forward_from']))
        if 'forward_date' in jmessage.keys():
            message.set_forward_date(int(jmessage['forward_date']))
        if 'reply_to_message' in jmessage.keys():
            message.set_reply_to_message(Message.build_from_json(jmessage['reply_to_message']))
        if 'text' in jmessage.keys():
            message.set_text(jmessage['text'])
        if 'audio' in jmessage.keys():
            message.set_audio(Audio.build_from_json(jmessage['audio']))
        if 'document' in jmessage.keys():
            message.set_document(Document.build_from_json(jmessage['document']))
        if 'photo' in jmessage.keys():
            message.set_photo(Message.__extract_ph_array(jmessage['photo']))
        if 'sticker' in jmessage.keys():
            message.set_sticker(Sticker.build_from_json(jmessage['sticker']))
        if 'video' in jmessage.keys():
            message.set_video(Video.build_from_json(jmessage['video']))
        if 'voice' in jmessage.keys():
            message.set_voice(Voice.build_from_json(jmessage['voice']))
        if 'caption' in jmessage.keys():
            message.set_caption(jmessage['caption'])
        if 'contact' in jmessage.keys():
            message.set_contact(Contact.build_from_json(jmessage['contact']))
        if 'location' in jmessage.keys():
            message.set_location(Location.build_from_json(jmessage['location']))
        if 'new_chat_participant' in jmessage.keys():
            message.set_new_chat_participant(User.build_from_json(jmessage['new_chat_participant']))
        if 'left_chat_participant' in jmessage.keys():
            message.set_left_chat_participant(User.build_from_json(jmessage['left_chat_participant']))
        if 'new_chat_title' in jmessage.keys():
            message.set_new_chat_title(jmessage['new_chat_title'])
        if 'new_chat_photo' in jmessage.keys():
            message.set_new_chat_photo(Message.__extract_ph_array(jmessage['new_chat_photo']))
        if 'delete_chat_photo' in jmessage.keys():
            message.set_delete_chat_photo()
        if 'group_chat_created' in jmessage.keys():
            message.set_group_chat_created()
        return message
Exemplo n.º 2
0
    def get_me(self):
        """
        A simple method for testing your bot's auth token.
        Requires no parameters.
        Returns basic information about the bot in form of a User object.

        :rtype: User
        """
        query = self.endpoint + "getMe"
        data = TbotPy.__urlopen(query)
        return User.build_from_json(json.loads(data)['result'])
Exemplo n.º 3
0
from flask import Flask, Blueprint, render_template, redirect, abort, request, session, flash
from jinja2 import TemplateNotFound
from conf_basic import app_config, database_config

from Object.User import User
from Object.Blog import Blogs
from Object.DataBase import DataBase

app = Flask(__name__)
app.config.from_object(__name__)
app.config.update(
    dict(DATABASEROOT=app.root_path + app_config['DataBaseRoot'],
         LOGIN=app_config['Login']))

db = DataBase(app.root_path + "\config.ini")
user = User(db)
blogs = Blogs(db)

#app.register_blueprint(app)

#app = Blueprint('app', __name__)

# Error message for invalid login
LOGIN_USER_PASS_ERROR = "User name or Password are not match to our record"
SERVER_UNVALIABLE = "Server Out Of Server"
SIGN_UP_PASSWORD_NOT_MATCH = "The password you enter does not match"
SIGN_UP_USERNAME_TAKEN = "The user name you enter has been used"
PROFILE_PASSWORD_NOT_MATCH = "The password you enter does not match"
PROFILE_PASSWORD_OLD_NOT_MATHC = "The old password not correct"