def update_buffer(self): self.buffer.clear() maxx = self.window.getmaxyx()[1] c = 1 longest_metadata_string_len = 0 for n in self.timeline: if "direct" in self.timeline_type: user_string = "%s -> %s" % (n["sender"]["screen_name"], n["recipient"]["screen_name"]) source_msg = "" else: user_string = "%s" % (n["user"]["screen_name"]) raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) if "in_reply_to_status_id" in n and n[ "in_reply_to_status_id"] is not None: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" if "retweeted_status" in n: user_string = "%s [%s's RD]" % ( n["retweeted_status"]["user"]["screen_name"], n["user"]["screen_name"]) if "in_reply_to_status_id" in n["retweeted_status"]: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" datetime_notice = helpers.notice_datetime(n) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) metadata_string = time_msg + " " + user_string if config.config["show_source"]: metadata_string += " " + source_msg if len(metadata_string) > longest_metadata_string_len: longest_metadata_string_len = len(metadata_string) for n in self.timeline: from_user = None to_user = None repeating_user = None if "direct" in self.timeline_type: from_user = n["sender"]["screen_name"] to_user = n["recipient"]["screen_name"] source_msg = "" else: if "retweeted_status" in n: repeating_user = n["user"]["screen_name"] n = n["retweeted_status"] from_user = n["user"]["screen_name"] raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) repeat_msg = "" if n["in_reply_to_status_id"] is not None: source_msg += " [+]" datetime_notice = helpers.notice_datetime(n) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) for user in [ user for user in [from_user, to_user, repeating_user] if user is not None ]: if not user in config.session_store.user_cache: config.session_store.user_cache[user] = random.choice( identicurse.base_colours.items())[1] if "ic__paused_on" in n and c != 1: self.buffer.append([("-", identicurse.colour_fields["pause_line"])]) self.buffer.append([("", identicurse.colour_fields["none"])]) # Build the line line = [] if c < 10: cout = " " + str(c) else: cout = str(c) line.append((cout, identicurse.colour_fields["notice_count"])) if (c - 1) == self.chosen_one: line.append((' * ', identicurse.colour_fields["selector"])) else: line.append((' ' * 3, identicurse.colour_fields["selector"])) if config.config['compact_notices']: line.append((time_msg, identicurse.colour_fields["time"])) line.append((" ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append( (from_user, config.session_store.user_cache[from_user])) else: line.append((from_user, identicurse.colour_fields["username"])) user_length = len(from_user) if to_user is not None: line.append((" -> ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append( (to_user, config.session_store.user_cache[to_user])) else: line.append( (to_user, identicurse.colour_fields["username"])) user_length += (len(" -> ") + len(to_user)) if repeating_user is not None: if config.config["compact_notices"]: line.append((" [", identicurse.colour_fields["none"])) else: line.append( (" [ repeat by ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append( (repeating_user, config.session_store.user_cache[repeating_user])) else: line.append((repeating_user, identicurse.colour_fields["username"])) if config.config["compact_notices"]: line.append(("'s RD]", identicurse.colour_fields["none"])) user_length += (len(" [") + len(repeating_user) + len("'s RD]")) else: line.append((" ]", identicurse.colour_fields["none"])) user_length += (len(" [ repeat by ") + len(repeating_user) + len(" ]")) if not config.config['compact_notices']: if config.config["show_source"]: line.append( (' ' * (maxx - ((len(source_msg) + len(time_msg) + user_length + (6 + len(cout))))), identicurse.colour_fields["none"])) else: line.append((' ' * (maxx - ((len(time_msg) + user_length + (5 + len(cout))))), identicurse.colour_fields["none"])) line.append((time_msg, identicurse.colour_fields["time"])) if config.config["show_source"]: line.append((' ', identicurse.colour_fields["none"])) line.append( (source_msg, identicurse.colour_fields["source"])) self.buffer.append(line) line = [] else: detail_char = "" if (not config.config["show_source"]): if "in_reply_to_status_id" in n and n[ "in_reply_to_status_id"] is not None: detail_char = "+" elif "retweeted_status" in n: detail_char = "~" line.append((" %s" % (detail_char), identicurse.colour_fields["source"])) if config.config["show_source"]: line.append((" " + source_msg, identicurse.colour_fields["source"])) line.append((" " * ( (longest_metadata_string_len - (user_length + len(time_msg) + len(source_msg) + 2))), identicurse.colour_fields["none"])) else: if detail_char == "": line.append((" ", identicurse.colour_fields["none"])) line.append((" " * ((longest_metadata_string_len - (user_length + len(time_msg) + 1))), identicurse.colour_fields["none"])) line.append((" | ", identicurse.colour_fields["none"])) try: notice_entities = helpers.split_entities(n['text']) for entity in notice_entities: if len(entity['text']) > 0: if entity['type'] in ['user', 'group', 'tag']: entity_text_no_symbol = entity['text'][1:] cache = getattr(config.session_store, '%s_cache' % (entity['type'])) if not entity_text_no_symbol in cache: cache[entity_text_no_symbol] = random.choice( identicurse.base_colours.items())[1] if config.config['%s_rainbow' % (entity['type'])]: line.append((entity['text'], cache[entity_text_no_symbol])) else: if entity['type'] == "user": line.append(( entity['text'], identicurse.colour_fields["username"])) else: line.append((entity['text'], identicurse.colour_fields[ entity['type']])) else: line.append((entity['text'], identicurse.colour_fields["notice"])) self.buffer.append(line) except UnicodeDecodeError: self.buffer.append([ ("Caution: Terminal too shit to display this notice.", identicurse.colour_fields["warning"]) ]) if config.config["show_notice_links"]: line = [] base_url = helpers.base_url_regex.findall( self.conn.api_path)[0][0] if self.timeline_type in ["direct", "sentdirect"]: notice_link = "%s/message/%s" % (base_url, str(n["id"])) else: notice_link = "%s/notice/%s" % (base_url, str(n["id"])) line.append(("<%s>" % (notice_link), identicurse.colour_fields["notice_link"])) self.buffer.append(line) if not config.config['compact_notices']: self.buffer.append([]) c += 1
def update_buffer(self): self.buffer.clear() maxx = self.window.getmaxyx()[1] c = 1 longest_metadata_string_len = 0 for n in self.timeline: if "direct" in self.timeline_type: user_string = "%s -> %s" % (n["sender"]["screen_name"], n["recipient"]["screen_name"]) source_msg = "" else: user_string = "%s" % (n["user"]["screen_name"]) raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) if "in_reply_to_status_id" in n and n["in_reply_to_status_id"] is not None: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" if "retweeted_status" in n: user_string = "%s [%s's RD]" % (n["retweeted_status"]["user"]["screen_name"], n["user"]["screen_name"]) if "in_reply_to_status_id" in n["retweeted_status"]: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" datetime_notice = helpers.notice_datetime(n) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) metadata_string = time_msg + " " + user_string if config.config["show_source"]: metadata_string += " " + source_msg if len(metadata_string) > longest_metadata_string_len: longest_metadata_string_len = len(metadata_string) for n in self.timeline: from_user = None to_user = None repeating_user = None if "direct" in self.timeline_type: from_user = n["sender"]["screen_name"] to_user = n["recipient"]["screen_name"] source_msg = "" else: if "retweeted_status" in n: repeating_user = n["user"]["screen_name"] n = n["retweeted_status"] from_user = n["user"]["screen_name"] raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) repeat_msg = "" if n["in_reply_to_status_id"] is not None: source_msg += " [+]" datetime_notice = helpers.notice_datetime(n) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) for user in [user for user in [from_user, to_user, repeating_user] if user is not None]: if not user in config.session_store.user_cache: config.session_store.user_cache[user] = random.choice(identicurse.base_colours.items())[1] if "ic__paused_on" in n and c != 1: self.buffer.append([("-", identicurse.colour_fields["pause_line"])]) self.buffer.append([("", identicurse.colour_fields["none"])]) # Build the line line = [] if c < 10: cout = " " + str(c) else: cout = str(c) line.append((cout, identicurse.colour_fields["notice_count"])) if (c - 1) == self.chosen_one: line.append((" * ", identicurse.colour_fields["selector"])) else: line.append((" " * 3, identicurse.colour_fields["selector"])) if config.config["compact_notices"]: line.append((time_msg, identicurse.colour_fields["time"])) line.append((" ", identicurse.colour_fields["none"])) if config.config["user_rainbow"]: line.append((from_user, config.session_store.user_cache[from_user])) else: line.append((from_user, identicurse.colour_fields["username"])) user_length = len(from_user) if to_user is not None: line.append((" -> ", identicurse.colour_fields["none"])) if config.config["user_rainbow"]: line.append((to_user, config.session_store.user_cache[to_user])) else: line.append((to_user, identicurse.colour_fields["username"])) user_length += len(" -> ") + len(to_user) if repeating_user is not None: if config.config["compact_notices"]: line.append((" [", identicurse.colour_fields["none"])) else: line.append((" [ repeat by ", identicurse.colour_fields["none"])) if config.config["user_rainbow"]: line.append((repeating_user, config.session_store.user_cache[repeating_user])) else: line.append((repeating_user, identicurse.colour_fields["username"])) if config.config["compact_notices"]: line.append(("'s RD]", identicurse.colour_fields["none"])) user_length += len(" [") + len(repeating_user) + len("'s RD]") else: line.append((" ]", identicurse.colour_fields["none"])) user_length += len(" [ repeat by ") + len(repeating_user) + len(" ]") if not config.config["compact_notices"]: if config.config["show_source"]: line.append( ( " " * (maxx - ((len(source_msg) + len(time_msg) + user_length + (6 + len(cout))))), identicurse.colour_fields["none"], ) ) else: line.append( ( " " * (maxx - ((len(time_msg) + user_length + (5 + len(cout))))), identicurse.colour_fields["none"], ) ) line.append((time_msg, identicurse.colour_fields["time"])) if config.config["show_source"]: line.append((" ", identicurse.colour_fields["none"])) line.append((source_msg, identicurse.colour_fields["source"])) self.buffer.append(line) line = [] else: detail_char = "" if not config.config["show_source"]: if "in_reply_to_status_id" in n and n["in_reply_to_status_id"] is not None: detail_char = "+" elif "retweeted_status" in n: detail_char = "~" line.append((" %s" % (detail_char), identicurse.colour_fields["source"])) if config.config["show_source"]: line.append((" " + source_msg, identicurse.colour_fields["source"])) line.append( ( " " * ((longest_metadata_string_len - (user_length + len(time_msg) + len(source_msg) + 2))), identicurse.colour_fields["none"], ) ) else: if detail_char == "": line.append((" ", identicurse.colour_fields["none"])) line.append( ( " " * ((longest_metadata_string_len - (user_length + len(time_msg) + 1))), identicurse.colour_fields["none"], ) ) line.append((" | ", identicurse.colour_fields["none"])) try: notice_entities = helpers.split_entities(n["text"]) for entity in notice_entities: if len(entity["text"]) > 0: if entity["type"] in ["user", "group", "tag"]: entity_text_no_symbol = entity["text"][1:] cache = getattr(config.session_store, "%s_cache" % (entity["type"])) if not entity_text_no_symbol in cache: cache[entity_text_no_symbol] = random.choice(identicurse.base_colours.items())[1] if config.config["%s_rainbow" % (entity["type"])]: line.append((entity["text"], cache[entity_text_no_symbol])) else: if entity["type"] == "user": line.append((entity["text"], identicurse.colour_fields["username"])) else: line.append((entity["text"], identicurse.colour_fields[entity["type"]])) else: line.append((entity["text"], identicurse.colour_fields["notice"])) self.buffer.append(line) except UnicodeDecodeError: self.buffer.append( [("Caution: Terminal too shit to display this notice.", identicurse.colour_fields["warning"])] ) if config.config["show_notice_links"]: line = [] base_url = helpers.base_url_regex.findall(self.conn.api_path)[0][0] if self.timeline_type in ["direct", "sentdirect"]: notice_link = "%s/message/%s" % (base_url, str(n["id"])) else: notice_link = "%s/notice/%s" % (base_url, str(n["id"])) line.append(("<%s>" % (notice_link), identicurse.colour_fields["notice_link"])) self.buffer.append(line) if not config.config["compact_notices"]: self.buffer.append([]) c += 1
def update_buffer(self): self.buffer.clear() if self.timeline_type == "user": if self.profile is not None: for field in [ # display name, internal field name, skip a line after this field? ("Real Name", "name", True), ("Bio", "description", False), ("Location", "location", False), ("URL", "url", False), ("User ID", "id", False), ("Joined at", "created_at", True), ("Followed by", "followers_count", False), ("Following", "friends_count", False), ("Followed by you", "following", True), ("Favourites", "favourites_count", False), ("Notices", "statuses_count", False), ("Average daily notices", "notices_per_day", True) ]: if (self.profile[field[1]] is not None) and (self.profile[field[1]] != ""): line = [] line.append((field[0] + ":", identicurse.colour_fields['profile_fields'])) line.append((" ", identicurse.colour_fields['none'])) line.append((self.profile[field[1]], identicurse.colour_fields['profile_values'])) self.buffer.append(line) if field[2]: self.buffer.append([("", identicurse.colour_fields['none'])]) else: self.buffer.append([("There is no user called @%s on this instance." % (self.type_params['screen_name']), identicurse.colour_fields['none'])]) if self.timeline_type == "group": if self.profile is not None: for field in [ # display name, internal field name, skip a line after this field? ("Name", "fullname", True), ("Description", "description", False), ("Location", "location", False), ("Homepage", "homepage", False), ("Group ID", "id", False), ("Created at", "created", False), ("Members", "member_count", True), ]: if (self.profile[field[1]] is not None) and (self.profile[field[1]] != ""): line = [] line.append((field[0] + ":", identicurse.colour_fields['profile_fields'])) line.append((" ", identicurse.colour_fields['none'])) line.append((self.profile[field[1]], identicurse.colour_fields['profile_values'])) self.buffer.append(line) if field[2]: self.buffer.append([("", identicurse.colour_fields['none'])]) else: self.buffer.append([("There is no group called !%s on this instance." % (self.type_params['nickname']), identicurse.colour_fields['none'])]) maxx = self.window.getmaxyx()[1] c = 1 longest_metadata_string_len = 0 for n in self.timeline: if n["text"] is None: n["text"] = "" if "direct" in self.timeline_type: user_string = "%s -> %s" % (n["sender"]["screen_name"], n["recipient"]["screen_name"]) source_msg = "" else: atless_reply = False if "in_reply_to_screen_name" in n and n["in_reply_to_screen_name"] is not None: atless_reply = True for entity in helpers.split_entities(n["text"]): if entity["type"] == "user" and entity["text"][1:].lower() == n["in_reply_to_screen_name"].lower(): atless_reply = False break if atless_reply: if "user" in n: user_string = "%s" % (n["user"]["screen_name"]) else: user_string = "<no username>" user_string += " -> %s" % (n["in_reply_to_screen_name"]) else: if "user" in n: user_string = "%s" % (n["user"]["screen_name"]) else: user_string = "" if (n["source"] == "ostatus") and ("user" in n) and "statusnet_profile_url" in n["user"]: raw_source_msg = "from %s" % (helpers.domain_regex.findall(n["user"]["statusnet_profile_url"])[0][2]) else: raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) if "in_reply_to_status_id" in n and n["in_reply_to_status_id"] is not None: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" if "retweeted_status" in n: user_string = "%s [%s's RD]" % (n["retweeted_status"]["user"]["screen_name"], n["user"]["screen_name"]) if "in_reply_to_status_id" in n["retweeted_status"]: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" datetime_notice = helpers.normalise_datetime(n["created_at"]) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) metadata_string = time_msg + " " + user_string if config.config["show_source"]: metadata_string += " " + source_msg if len(metadata_string) > longest_metadata_string_len: longest_metadata_string_len = len(metadata_string) for n in self.timeline: if n["text"] is None: n["text"] = "" from_user = None to_user = None repeating_user = None if "direct" in self.timeline_type: from_user = n["sender"]["screen_name"] to_user = n["recipient"]["screen_name"] source_msg = "" else: if "retweeted_status" in n: repeating_user = n["user"]["screen_name"] n = n["retweeted_status"] if "user" in n: from_user = n["user"]["screen_name"] else: from_user = "******" atless_reply = False if "in_reply_to_screen_name" in n and n["in_reply_to_screen_name"] is not None: atless_reply = True for entity in helpers.split_entities(n["text"]): if entity["type"] == "user" and entity["text"][1:].lower() == n["in_reply_to_screen_name"].lower(): atless_reply = False break if atless_reply: to_user = n["in_reply_to_screen_name"] if (n["source"] == "ostatus") and ("user" in n) and "statusnet_profile_url" in n["user"]: raw_source_msg = "from %s" % (helpers.domain_regex.findall(n["user"]["statusnet_profile_url"])[0][2]) else: raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) repeat_msg = "" if n["in_reply_to_status_id"] is not None: source_msg += " [+]" datetime_notice = helpers.normalise_datetime(n["created_at"]) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) for user in [user for user in [from_user, to_user, repeating_user] if user is not None]: if not user in config.session_store.user_cache: config.session_store.user_cache[user] = helpers.colour_from_name([item[1] for item in identicurse.base_colours.items()], user.lower()) if "ic__paused_on" in n and c != 1: self.buffer.append([("-", identicurse.colour_fields["pause_line"])]) self.buffer.append([("", identicurse.colour_fields["none"])]) # Build the line line = [] if c < 10: cout = " " + str(c) else: cout = str(c) line.append((cout, identicurse.colour_fields["notice_count"])) if (c - 1) == self.chosen_one: line.append((' * ', identicurse.colour_fields["selector"])) else: line.append((' ' * 3, identicurse.colour_fields["selector"])) if config.config['compact_notices']: line.append((time_msg, identicurse.colour_fields["time"])) line.append((" ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append((from_user, config.session_store.user_cache[from_user])) else: line.append((from_user, identicurse.colour_fields["username"])) if from_user is not None: user_length = len(from_user) else: user_length = None if to_user is not None: line.append((" -> ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append((to_user, config.session_store.user_cache[to_user])) else: line.append((to_user, identicurse.colour_fields["username"])) user_length += len(" -> ") + len(to_user) if repeating_user is not None: if config.config["compact_notices"]: line.append((" [", identicurse.colour_fields["none"])) else: line.append((" [ repeat by ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append((repeating_user, config.session_store.user_cache[repeating_user])) else: line.append((repeating_user, identicurse.colour_fields["username"])) if config.config["compact_notices"]: line.append(("'s RD]", identicurse.colour_fields["none"])) user_length += len(" [") + len(repeating_user) + len("'s RD]") else: line.append((" ]", identicurse.colour_fields["none"])) user_length += len(" [ repeat by ") + len(repeating_user) + len(" ]") if not config.config['compact_notices']: if config.config["show_source"]: line.append((' ' * (maxx - ((len(source_msg) + len(time_msg) + user_length + (6 + len(cout))))), identicurse.colour_fields["none"])) else: line.append((' ' * (maxx - ((len(time_msg) + user_length + (5 + len(cout))))), identicurse.colour_fields["none"])) line.append((time_msg, identicurse.colour_fields["time"])) if config.config["show_source"]: line.append((' ', identicurse.colour_fields["none"])) line.append((source_msg, identicurse.colour_fields["source"])) self.buffer.append(line) line = [] else: detail_char = "" if (not config.config["show_source"]): if "in_reply_to_status_id" in n and n["in_reply_to_status_id"] is not None: detail_char = "+" elif "retweeted_status" in n: detail_char = "~" line.append((" %s" % (detail_char), identicurse.colour_fields["source"])) if config.config["show_source"]: line.append((" " + source_msg, identicurse.colour_fields["source"])) line.append((" "*((longest_metadata_string_len - (user_length + len(time_msg) + len(source_msg) + 2))), identicurse.colour_fields["none"])) else: if detail_char == "": line.append((" ", identicurse.colour_fields["none"])) line.append((" "*((longest_metadata_string_len - (user_length + len(time_msg) + 1))), identicurse.colour_fields["none"])) line.append((" | ", identicurse.colour_fields["none"])) try: min_x_offset = reduce((lambda acc_length, block: (acc_length if (len(block) < 3) else max(acc_length, block[2])) + len(block[0])), line, 0) # determine how far along the line items beginning now would be; this will be used so that wrapped lines get correct indentation notice_entities = helpers.split_entities(n['text'] or "") for entity in notice_entities: if len(entity['text']) > 0: if entity['type'] in ['user', 'group', 'tag']: entity_text_no_symbol = entity['text'][1:] cache = getattr(config.session_store, '%s_cache' % (entity['type'])) if not entity_text_no_symbol in cache: cache[entity_text_no_symbol] = helpers.colour_from_name([item[1] for item in identicurse.base_colours.items()], entity_text_no_symbol.lower()) if config.config['%s_rainbow' % (entity['type'])]: line.append((entity['text'], cache[entity_text_no_symbol], min_x_offset)) else: if entity['type'] == "user": line.append((entity['text'], identicurse.colour_fields["username"], min_x_offset)) else: line.append((entity['text'], identicurse.colour_fields[entity['type']], min_x_offset)) else: line.append((entity['text'], identicurse.colour_fields["notice"], min_x_offset)) self.buffer.append(line) except UnicodeDecodeError: self.buffer.append([("Caution: Terminal too shit to display this notice.", identicurse.colour_fields["warning"])]) if config.config["show_notice_links"]: line = [] base_url = helpers.base_url_regex.findall(self.conn.api_path)[0][0] if self.timeline_type in ["direct", "sentdirect"]: notice_link = "%s/message/%s" % (base_url, str(n["id"])) else: notice_link = "%s/notice/%s" % (base_url, str(n["id"])) line.append(("<%s>" % (notice_link), identicurse.colour_fields["notice_link"])) self.buffer.append(line) if not config.config['compact_notices']: self.buffer.append([]) c += 1
def update_buffer(self): self.buffer.clear() if self.timeline_type == "user": if self.profile is not None: for field in [ # display name, internal field name, skip a line after this field? ("Real Name", "name", True), ("Bio", "description", False), ("Location", "location", False), ("URL", "url", False), ("User ID", "id", False), ("Joined at", "created_at", True), ("Followed by", "followers_count", False), ("Following", "friends_count", False), ("Followed by you", "following", True), ("Favourites", "favourites_count", False), ("Notices", "statuses_count", False), ("Average daily notices", "notices_per_day", True) ]: if (self.profile[field[1]] is not None) and (self.profile[field[1]] != ""): line = [] line.append( (field[0] + ":", identicurse.colour_fields['profile_fields'])) line.append((" ", identicurse.colour_fields['none'])) line.append( (self.profile[field[1]], identicurse.colour_fields['profile_values'])) self.buffer.append(line) if field[2]: self.buffer.append([ ("", identicurse.colour_fields['none']) ]) else: self.buffer.append([ ("There is no user called @%s on this instance." % (self.type_params['screen_name']), identicurse.colour_fields['none']) ]) if self.timeline_type == "group": if self.profile is not None: for field in [ # display name, internal field name, skip a line after this field? ("Name", "fullname", True), ("Description", "description", False), ("Location", "location", False), ("Homepage", "homepage", False), ("Group ID", "id", False), ("Created at", "created", False), ("Members", "member_count", True), ]: if (self.profile[field[1]] is not None) and (self.profile[field[1]] != ""): line = [] line.append( (field[0] + ":", identicurse.colour_fields['profile_fields'])) line.append((" ", identicurse.colour_fields['none'])) line.append( (self.profile[field[1]], identicurse.colour_fields['profile_values'])) self.buffer.append(line) if field[2]: self.buffer.append([ ("", identicurse.colour_fields['none']) ]) else: self.buffer.append([ ("There is no group called !%s on this instance." % (self.type_params['nickname']), identicurse.colour_fields['none']) ]) maxx = self.window.getmaxyx()[1] c = 1 longest_metadata_string_len = 0 for n in self.timeline: if n["text"] is None: n["text"] = "" if "direct" in self.timeline_type: user_string = "%s -> %s" % (n["sender"]["screen_name"], n["recipient"]["screen_name"]) source_msg = "" else: atless_reply = False if "in_reply_to_screen_name" in n and n[ "in_reply_to_screen_name"] is not None: atless_reply = True for entity in helpers.split_entities(n["text"]): if entity[ "type"] == "user" and entity["text"][1:].lower( ) == n["in_reply_to_screen_name"].lower(): atless_reply = False break if atless_reply: if "user" in n: user_string = "%s" % (n["user"]["screen_name"]) else: user_string = "<no username>" user_string += " -> %s" % (n["in_reply_to_screen_name"]) else: if "user" in n: user_string = "%s" % (n["user"]["screen_name"]) else: user_string = "" if (n["source"] == "ostatus") and ( "user" in n) and "statusnet_profile_url" in n["user"]: raw_source_msg = "from %s" % (helpers.domain_regex.findall( n["user"]["statusnet_profile_url"])[0][2]) else: raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) if "in_reply_to_status_id" in n and n[ "in_reply_to_status_id"] is not None: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" if "retweeted_status" in n: user_string = "%s [%s's RD]" % ( n["retweeted_status"]["user"]["screen_name"], n["user"]["screen_name"]) if "in_reply_to_status_id" in n["retweeted_status"]: if not config.config["show_source"]: user_string += " +" else: source_msg += " [+]" datetime_notice = helpers.normalise_datetime(n["created_at"]) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) metadata_string = time_msg + " " + user_string if config.config["show_source"]: metadata_string += " " + source_msg if len(metadata_string) > longest_metadata_string_len: longest_metadata_string_len = len(metadata_string) for n in self.timeline: if n["text"] is None: n["text"] = "" from_user = None to_user = None repeating_user = None if "direct" in self.timeline_type: from_user = n["sender"]["screen_name"] to_user = n["recipient"]["screen_name"] source_msg = "" else: if "retweeted_status" in n: repeating_user = n["user"]["screen_name"] n = n["retweeted_status"] if "user" in n: from_user = n["user"]["screen_name"] else: from_user = "******" atless_reply = False if "in_reply_to_screen_name" in n and n[ "in_reply_to_screen_name"] is not None: atless_reply = True for entity in helpers.split_entities(n["text"]): if entity[ "type"] == "user" and entity["text"][1:].lower( ) == n["in_reply_to_screen_name"].lower(): atless_reply = False break if atless_reply: to_user = n["in_reply_to_screen_name"] if (n["source"] == "ostatus") and ( "user" in n) and "statusnet_profile_url" in n["user"]: raw_source_msg = "from %s" % (helpers.domain_regex.findall( n["user"]["statusnet_profile_url"])[0][2]) else: raw_source_msg = "from %s" % (n["source"]) source_msg = self.html_regex.sub("", raw_source_msg) repeat_msg = "" if n["in_reply_to_status_id"] is not None: source_msg += " [+]" datetime_notice = helpers.normalise_datetime(n["created_at"]) time_msg = helpers.format_time(helpers.time_since(datetime_notice), short_form=True) for user in [ user for user in [from_user, to_user, repeating_user] if user is not None ]: if not user in config.session_store.user_cache: config.session_store.user_cache[ user] = helpers.colour_from_name([ item[1] for item in identicurse.base_colours.items() ], user.lower()) if "ic__paused_on" in n and c != 1: self.buffer.append([("-", identicurse.colour_fields["pause_line"])]) self.buffer.append([("", identicurse.colour_fields["none"])]) # Build the line line = [] if c < 10: cout = " " + str(c) else: cout = str(c) line.append((cout, identicurse.colour_fields["notice_count"])) if (c - 1) == self.chosen_one: line.append((' * ', identicurse.colour_fields["selector"])) else: line.append((' ' * 3, identicurse.colour_fields["selector"])) if config.config['compact_notices']: line.append((time_msg, identicurse.colour_fields["time"])) line.append((" ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append( (from_user, config.session_store.user_cache[from_user])) else: line.append((from_user, identicurse.colour_fields["username"])) if from_user is not None: user_length = len(from_user) else: user_length = None if to_user is not None: line.append((" -> ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append( (to_user, config.session_store.user_cache[to_user])) else: line.append( (to_user, identicurse.colour_fields["username"])) user_length += len(" -> ") + len(to_user) if repeating_user is not None: if config.config["compact_notices"]: line.append((" [", identicurse.colour_fields["none"])) else: line.append( (" [ repeat by ", identicurse.colour_fields["none"])) if config.config['user_rainbow']: line.append( (repeating_user, config.session_store.user_cache[repeating_user])) else: line.append((repeating_user, identicurse.colour_fields["username"])) if config.config["compact_notices"]: line.append(("'s RD]", identicurse.colour_fields["none"])) user_length += len(" [") + len(repeating_user) + len( "'s RD]") else: line.append((" ]", identicurse.colour_fields["none"])) user_length += len(" [ repeat by ") + len( repeating_user) + len(" ]") if not config.config['compact_notices']: if config.config["show_source"]: line.append( (' ' * (maxx - ((len(source_msg) + len(time_msg) + user_length + (6 + len(cout))))), identicurse.colour_fields["none"])) else: line.append((' ' * (maxx - ((len(time_msg) + user_length + (5 + len(cout))))), identicurse.colour_fields["none"])) line.append((time_msg, identicurse.colour_fields["time"])) if config.config["show_source"]: line.append((' ', identicurse.colour_fields["none"])) line.append( (source_msg, identicurse.colour_fields["source"])) self.buffer.append(line) line = [] else: detail_char = "" if (not config.config["show_source"]): if "in_reply_to_status_id" in n and n[ "in_reply_to_status_id"] is not None: detail_char = "+" elif "retweeted_status" in n: detail_char = "~" line.append((" %s" % (detail_char), identicurse.colour_fields["source"])) if config.config["show_source"]: line.append((" " + source_msg, identicurse.colour_fields["source"])) line.append((" " * ( (longest_metadata_string_len - (user_length + len(time_msg) + len(source_msg) + 2))), identicurse.colour_fields["none"])) else: if detail_char == "": line.append((" ", identicurse.colour_fields["none"])) line.append((" " * ((longest_metadata_string_len - (user_length + len(time_msg) + 1))), identicurse.colour_fields["none"])) line.append((" | ", identicurse.colour_fields["none"])) try: min_x_offset = reduce( (lambda acc_length, block: (acc_length if (len(block) < 3) else max( acc_length, block[2])) + len(block[0])), line, 0 ) # determine how far along the line items beginning now would be; this will be used so that wrapped lines get correct indentation notice_entities = helpers.split_entities(n['text'] or "") for entity in notice_entities: if len(entity['text']) > 0: if entity['type'] in ['user', 'group', 'tag']: entity_text_no_symbol = entity['text'][1:] cache = getattr(config.session_store, '%s_cache' % (entity['type'])) if not entity_text_no_symbol in cache: cache[ entity_text_no_symbol] = helpers.colour_from_name( [ item[1] for item in identicurse.base_colours.items() ], entity_text_no_symbol.lower()) if config.config['%s_rainbow' % (entity['type'])]: line.append((entity['text'], cache[entity_text_no_symbol], min_x_offset)) else: if entity['type'] == "user": line.append( (entity['text'], identicurse.colour_fields["username"], min_x_offset)) else: line.append( (entity['text'], identicurse.colour_fields[ entity['type']], min_x_offset)) else: line.append((entity['text'], identicurse.colour_fields["notice"], min_x_offset)) self.buffer.append(line) except UnicodeDecodeError: self.buffer.append([ ("Caution: Terminal too shit to display this notice.", identicurse.colour_fields["warning"]) ]) if config.config["show_notice_links"]: line = [] base_url = helpers.base_url_regex.findall( self.conn.api_path)[0][0] if self.timeline_type in ["direct", "sentdirect"]: notice_link = "%s/message/%s" % (base_url, str(n["id"])) else: notice_link = "%s/notice/%s" % (base_url, str(n["id"])) line.append(("<%s>" % (notice_link), identicurse.colour_fields["notice_link"])) self.buffer.append(line) if not config.config['compact_notices']: self.buffer.append([]) c += 1