def get_command(self): path_to_file = os.getcwd() file_with_id = path_to_file + "/update_id_file.txt" with open(file_with_id, 'r') as myfile: last_id = myfile.read() myfile.close() offset = int(last_id) offset = int(offset) - 1 values = {} values['offset'] = offset values['limit'] = '5' data = urllib.urlencode(values) response = urllib2.Request(self.update_url, data) response = urllib2.urlopen(response) block_from_json_response = response.read() self.json_response = json.loads(block_from_json_response) last_update_id_from_json = self.json_response['result'][-1][ 'update_id'] last_user_id = self.json_response['result'][-1]['message']['from'][ 'id'] update_id_array = [] for key in self.json_response['result']: update_id_array.append(key['update_id']) path_to_file = os.getcwd() file_with_id = path_to_file + "/update_id_file.txt" if os.path.exists(file_with_id): with open(file_with_id, 'r+') as myfile: last_update_id = myfile.read() if int(last_update_id) == int(last_update_id_from_json): myfile.close() else: myfile.read() myfile.seek(0) myfile.write(str(last_update_id_from_json)) myfile.close() command = self.json_response['result'][-1]['message'][ 'text'] system = SystemUtils() if last_user_id == self.user_id: if command == BotApi.info_command: inf = system.get_info_server(command) information = inf.to_string() self.send_message(command, information) elif command == BotApi.help_command: self.send_message(command, '') elif command == BotApi.load_command: load = system.get_load_server(command) self.send_message(command, load) elif command == BotApi.mem_command: mem = system.get_mem_server(command) self.send_message(command, mem) else: self.send_message(command, '') print "Nothing to send, error command has been entered" else: print "sad" else: print "File: " + file_with_id + " doesn't exist"