def send_message(self, id, msg, reply = None, keyboard = None): '''Sends a message to the given chat!''' url = self.url + 'sendMessage' data = {'chat_id' : str(id), 'text' : msg.encode('utf-8')} if reply != None: data['reply_to_message_id'] = str(reply) if keyboard != None: data['reply_markup'] = json.dumps(keyboard, ensure_ascii=False).encode('utf-8').replace(', "', ',"') connection.send_request(url, data = data, headers = self.headers)
def __init__(self, symbol, chart_type, interval_type, unit, range_type, range_value, session=""): self.changed = False self.data = [] self.df = None key = _getDictionaryKey(symbol, chart_type, interval_type, unit, range_type, range_value, session) request_data = { 'id': key, 'symbol': symbol, 'chart_type':chart_type, 'interval_type': interval_type, 'interval_value': unit, 'range_type' : range_type, 'range_value' : range_value, 'session' : session } self.request = request_data subject = send_request(request_data) obs = _Observer(self) subject.subscribe(obs) self.data_subject = subject #subject.subscribe(lambda x: print("Original subscriber value is {0}".format(x))) #subject.subscribe(lambda x: store(x))
def query_messages(self): '''Searches for message updates!''' url = self.url + 'getUpdates' data = {'offset': self.lastid} status, headers, result = connection.send_request(url, data = data,\ headers = self.headers) try: result = json.loads(result) except ValueError: return False, {} for m in result['result']: if m['update_id'] >= self.lastid: self.lastid = m['update_id'] + 1 return result['ok'], result['result']
def send_chat_action(self, id, action): url = self.url + 'sendChatAction' data = {'chat_id' : str(id), 'action': str(action)} connection.send_request(url, data = data, headers = self.headers)