class MessageHandler: def __init__(self): self.api = ApiServer() def read_messages(self, profile_id): r = self.api.get('profile/{0}/messages'.format(profile_id)) return json.loads(r.text) def read_message_thread(self, profile_id, profile_id2): r = self.api.get('profile/{0}/messages/{1}.'.format(profile_id, profile_id2)) return json.loads(r.text) def send_message(self, profile_id, profile_id2, message): p = { 'messageBody': message } r = self.api.post( 'profile/{0}/messages/{1}.'.format(profile_id, profile_id2), params=p ) return json.loads(r.text)
from util import import_env, log if __name__ == "__main__": import_env() mqtt = Mqtt() telegram = Telegram() telegram.start() temp_command = Temp(telegram=telegram, mqtt=mqtt) cams_command = Cams(telegram=telegram) cry_command = Cry(telegram=telegram, mqtt=mqtt) set_command = Set(telegram=telegram, mqtt=mqtt) api_server = ApiServer(telegram=telegram) api_server.start() mail_server = MailServer() mail_server.start() try: while True: time.sleep(1) except KeyboardInterrupt: log("[main] Stopping all") telegram.stop = True mail_server.stop() api_server.stop()
def __init__(self): self.api = ApiServer()
def __init__(self, reactor): self.reactor = reactor self.endpoint_api = TCP4ServerEndpoint(self.reactor, 9000) self.endpoint_api.listen(ApiServer())
def request_handler(sender, **kwargs): request = kwargs['instance'] if not request or request.status: return ApiServer().process_request(request)