def wget(self, data): data = decode_hybi(data)['payload'] if data == None: return False # Check if there's a header in the data if data.find("--KOP:") > -1: if self.wComplete == -1: verbose("Previous data was incomplete, new data already arrived", 0, 3) # Start splicing the header from the body self.wLength = data.partition("--KOP:")[2] data = self.wLength.partition(":POK--")[2] self.wLength = int(self.wLength.partition(":POK--")[0]) # If the length of the data matches the specified length, return the data if len(data) == self.wLength: self.wComplete = None self.wLength = None debug(data) # Return the completed data return data else: verbose("Length does not match. Data is " + str(len(data)) + " while we wanted " + str(self.wLength), 0, 3) self.wComplete = -1 self.wData = data else: verbose("Does not contain a KOP", 0, 3) # See if wData isn't none if self.wData: self.wData = self.wData + data if len(self.wData) == self.wLength: print "\r\nCompleted!!" self.wComplete = None self.wLength = None # Return the completed data return self.wData else: self.wComplete = -2 else: # If it is, this data got to us before any head, and we won't be able to piece it together with anything if data: verbose("Received stray data: " + data, 0, 3) else: verbose("Closing connection of user " + self.uid, 0, 2) self.closeClient() # Return false if this point has been reached return False
def taking_break(update, context, lunch=False): chat_id = update.effective_chat.id user_id = update.effective_user.id if not toolbox.user_is_in_group_or_admin(chat_id, user_id): return () timestamp = datetime.now().timestamp() break_users = sql.db.get_current_breaks() toolbox.debug(break_users) username = toolbox.list_user(user_id, mention=False) try: expected_length = int(context.args[0]) except: expected_length = 15 if lunch: expected_length = 30 for i in break_users: if i['user_id'] == user_id: break_type = break_duration_calculator(i['expected_length']) output=username+" ya está de "+break_type+" desde las "+\ datetime.fromtimestamp(i['start_time']).strftime("%H:%M:%S") output += toolbox.count_away_users(len(break_users)) context.bot.send_message(chat_id=chat_id, text=output, parse_mode="Markdown") return () else: # yo this was an accident but apparently you can have an else after a for loop? wtf break_type = break_duration_calculator(expected_length) sql.db.send_user_away( user_id=user_id, timestamp=timestamp, expected_length=expected_length, alarm_channel=chat_id, ) output=username+" se ha ido de "+break_type+" a las "+\ datetime.fromtimestamp(timestamp).strftime("%H:%M:%S") output += toolbox.count_away_users( len(break_users) + 1) #break user was only updated _before_ adding the current user. context.bot.send_message( chat_id=chat_id, text=output, parse_mode="Markdown" ) #, reply_to_message_id=update.message.message_id) rebuild_schedule() return ()
def closeClient(self): if(self.uid): self.updateWorld({'action': 'logoff'}) self.running = 0 # Loop through all the subthreads and close (join) them for c in self.threads: c.join() # Delete our queue from the dictionary rwQ.acquireRead() try: rwQ.acquireWrite() try: # Add a new queue to the array for the new thread debug('Globqueue length before deleting: ' + str(len(globQueue))) del globQueue[self.queueIndex] debug('Globqueue length after deleting: ' + str(len(globQueue))) finally: rwQ.release() finally: rwQ.release() # Delete our user from the dictionary if(self.uid): rwU.acquireRead() try: rwU.acquireWrite() try: del globUser[self.uid] finally: rwU.release() finally: rwU.release() self.client.close() verbose("Client disconnected", 0, 5)
def visualize(img, proc_param, _joints, verts, cam): cam_for_render, vert_shifted, joints_orig = vis_util.get_original( proc_param, verts, cam, _joints, img_size=img.shape[:2]) preimg = toolbox.premask(img, cam_for_render, vert_shifted, joints_orig) # toolbox.debug([img, preimg]) skel_img = vis_util.draw_skeleton(img, joints_orig) from muscles import parse_file_for_muscles muscles_imgs = parse_file_for_muscles(img) toolbox.debug(list(muscles_imgs.values())) x = toolbox.crop(preimg, toolbox.pad(toolbox.inject(joints_orig, [2, 3, 8, 9]), size=0), warped=True) y = toolbox.crop(preimg, toolbox.pad(toolbox.inject(joints_orig, [2, 3, 8, 9]), size=-20), warped=True) toolbox.debug([x, y, preimg])
def back(update, context): chat_id = update.effective_chat.id user_id = update.effective_user.id if not toolbox.user_is_in_group_or_admin(chat_id, user_id): return () timestamp = datetime.now().timestamp() break_users = sql.db.get_current_breaks() toolbox.debug(break_users) username = toolbox.list_user(user_id, mention=False) user_is_on_break = False for i in break_users: if i['user_id'] == user_id: sql.db.bring_user_back(i['id'], timestamp) break_type = break_duration_calculator(i['expected_length']) output=username+" ha vuelto de "+break_type+" a las "+\ datetime.fromtimestamp(timestamp).strftime("%H:%M:%S")+\ ", después de "+toolbox.seconds_to_string(timestamp-i['start_time']) output += toolbox.count_away_users( len(break_users) - 1) #one user was removed after checking context.bot.send_message(chat_id=chat_id, text=output, parse_mode="Markdown") rebuild_schedule() return () else: output = username + " no está de break." output += toolbox.count_away_users(len(break_users)) context.bot.send_message( chat_id=chat_id, text=output, parse_mode="Markdown" ) #, reply_to_message_id=update.message.message_id) return