01234567890123456789012345678901234567890123456789012345678901234567890123456789
52495250525152525253525452555256525752585259526052615262526352645265526652675268 526952705271527252735274527552765277527852795280 528152825283528452855286528752885289529052915292529352945295529652975298529953005301 | <----SKIPPED LINES----> curl.setopt(pycurl.READDATA, body_as_file_object) curl.setopt(pycurl.POSTFIELDSIZE, len(body_as_json_string)) failure_message = '' try: curl.perform() except pycurl.error as e: failure_message = 'curl.perform() failed with message %s' % e Log('curl.perform() failed with message %s' % e) error_code = True else: # you may want to check HTTP response code, e.g. status_code = curl.getinfo(pycurl.RESPONSE_CODE) if status_code != 200: Log('Server returned HTTP status code %d for message %s' % (status_code, s)) error_code = True curl.close() UpdateStatusLight(GPIO_ERROR_VESTABOARD_CONNECTION, error_code, failure_message) def PersonalMessage(configuration, message_queue): if 'clear_board' in configuration: RemoveSetting(configuration, 'clear_board') message_queue.append((FLAG_MSG_CLEAR, '')) minute_of_day = MinuteOfDay() if ( not message_queue and 'personal_message_enabled' in configuration and configuration['personal_message'] and minute_of_day <= configuration['personal_off_time'] and minute_of_day > configuration['personal_on_time'] + 1): message = configuration['personal_message'].split('\n') message_queue.append((FLAG_MSG_PERSONAL, message)) def ManageMessageQueue(message_queue, next_message_time, configuration): """Check time & if appropriate, display next message from queue. Args: message_queue: FIFO list of message tuples of (message type, message string). next_message_time: epoch at which next message should be displayed configuration: dictionary of configuration attributes. Returns: Next_message_time, potentially updated if a message has been displayed, or unchanged if no message was displayed. """ if message_queue and (time.time() >= next_message_time or SIMULATION): if SIMULATION: # drain the queue because the messages come so fast messages_to_display = list(message_queue) # passed by reference, so clear it out since we drained it to the display del message_queue[:] <----SKIPPED LINES----> |
01234567890123456789012345678901234567890123456789012345678901234567890123456789
52495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346 | <----SKIPPED LINES----> curl.setopt(pycurl.READDATA, body_as_file_object) curl.setopt(pycurl.POSTFIELDSIZE, len(body_as_json_string)) failure_message = '' try: curl.perform() except pycurl.error as e: failure_message = 'curl.perform() failed with message %s' % e Log('curl.perform() failed with message %s' % e) error_code = True else: # you may want to check HTTP response code, e.g. status_code = curl.getinfo(pycurl.RESPONSE_CODE) if status_code != 200: Log('Server returned HTTP status code %d for message %s' % (status_code, s)) error_code = True curl.close() UpdateStatusLight(GPIO_ERROR_VESTABOARD_CONNECTION, error_code, failure_message) def TruncateEscapedLine(s): s = s.upper() character_mapping = { '[': '(', '<': '(', ']': ')', '>': ')', '|': '/', '\\': '/'} for c in character_mapping: s = s.replace(c, character_mapping[c]) l = 0 valid_characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$()-+&=;:''"%,./?' validated_s = '' valid_escape_values = list(range(70)) open_escape_char = '{' close_escape_char = '}' pointer = 0 while pointer < len(s) and l < SPLITFLAP_CHARS_PER_LINE: if s[pointer] in valid_characters: validated_s += s[pointer] l += 1 pointer += 1 elif s[pointer] == open_escape_char: end = s.find(close_escape_char, pointer) if end == -1: # open escape did not close pointer = len(s) else: try: escape_value = int(s[pointer+1:end]) except ValueError: escape_value = None if escape_value in valid_escape_values: validated_s += s[pointer:end+1] l += 1 pointer = end else: pointer += 1 return validated_s def PersonalMessage(configuration, message_queue): if 'clear_board' in configuration: RemoveSetting(configuration, 'clear_board') message_queue.append((FLAG_MSG_CLEAR, '')) minute_of_day = MinuteOfDay() if ( not message_queue and 'personal_message_enabled' in configuration and configuration['personal_message'] and minute_of_day <= configuration['personal_off_time'] and minute_of_day > configuration['personal_on_time'] + 1): message = configuration['personal_message'] lines = [TruncateEscapedLine(l) for l in message.split('\n')] message_queue.append((FLAG_MSG_PERSONAL, lines)) def ManageMessageQueue(message_queue, next_message_time, configuration): """Check time & if appropriate, display next message from queue. Args: message_queue: FIFO list of message tuples of (message type, message string). next_message_time: epoch at which next message should be displayed configuration: dictionary of configuration attributes. Returns: Next_message_time, potentially updated if a message has been displayed, or unchanged if no message was displayed. """ if message_queue and (time.time() >= next_message_time or SIMULATION): if SIMULATION: # drain the queue because the messages come so fast messages_to_display = list(message_queue) # passed by reference, so clear it out since we drained it to the display del message_queue[:] <----SKIPPED LINES----> |