Ejemplo n.º 1
0
    def update(self):
        self.update_name()

        if self.paused:
            self.update_buffer()
            return

        get_count = config.config['notice_limit']

        if self.prev_page != self.page:
            self.timeline = []

        last_id = 0
        if len(self.timeline) > 0:
            for notice in self.timeline:
                if notice["ic__from_web"]:  # don't consider inserted posts latest
                    last_id = notice['id']
                    break

        if self.timeline_type == "home":
            raw_timeline = self.conn.statuses_home_timeline(count=get_count, page=self.page, since_id=last_id)
        elif self.timeline_type == "mentions":
            raw_timeline = self.conn.statuses_mentions(count=get_count, page=self.page, since_id=last_id)
        elif self.timeline_type == "direct":
            raw_timeline = self.conn.direct_messages(count=get_count, page=self.page, since_id=last_id)
        elif self.timeline_type == "user":
            raw_timeline = self.conn.statuses_user_timeline(user_id=self.type_params['user_id'], screen_name=self.type_params['screen_name'], count=get_count, page=self.page, since_id=last_id)
            try:
                self.profile = self.conn.users_show(screen_name=self.type_params['screen_name'])
                # numerical fields, convert them to strings to make the buffer code more clean
                for field in ['id', 'created_at', 'followers_count', 'friends_count', 'favourites_count', 'statuses_count']:
                    self.profile[field] = str(self.profile[field])

                # special handling for following
                if self.profile['following']:
                    self.profile['following'] = "Yes"
                else:
                    self.profile['following'] = "No"

                # create this field specially
                datetime_joined = helpers.normalise_datetime(self.profile['created_at'])
                days_since_join = helpers.single_unit(helpers.time_since(datetime_joined), "days")['days']
                self.profile['notices_per_day'] = "%0.2f" % (float(self.profile['statuses_count']) / days_since_join)

            except StatusNetError, e:
                if e.errcode == 404:
                    self.profile = None
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
                    next_id = self.type_params['notice_id']
                    while next_id is not None:
                        notice = self.conn.statuses_show(id=next_id)
                        raw_timeline.append(notice)
                        if "retweeted_status" in notice:
                            next_id = notice['retweeted_status']['id']
                        else:
                            next_id = notice['in_reply_to_status_id']

        self.prev_page = self.page

        temp_timeline = []
        old_ids = [n['id'] for n in self.timeline]

        for notice in raw_timeline:
            notice["ic__raw_datetime"] = helpers.normalise_datetime(notice['created_at'])
            notice["ic__from_web"] = True
            passes_filters = True
            if notice['id'] in old_ids:
                passes_filters = False
                continue
            if hasattr(config.session_store, "muted_conversations") and notice['statusnet_conversation_id'] in config.session_store.muted_conversations:
                passes_filters = False
                continue
            if config.config["hide_activities"] and ("source" in notice) and (notice["source"] == "activity"):
                passes_filters = False
                continue
            if config.config["filter_mode"] == "regex":
                for filter_item in config.config['filters']:
                    if filter_item.search(notice['text']) is not None:
                        passes_filters = False
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    def update(self):
        self.update_name()

        if self.paused:
            self.update_buffer()
            return

        get_count = config.config['notice_limit']

        if self.prev_page != self.page:
            self.timeline = []

        last_id = 0
        if len(self.timeline) > 0:
            for notice in self.timeline:
                if notice[
                        "ic__from_web"]:  # don't consider inserted posts latest
                    last_id = notice['id']
                    break

        if self.timeline_type == "home":
            raw_timeline = self.conn.statuses_home_timeline(count=get_count,
                                                            page=self.page,
                                                            since_id=last_id)
        elif self.timeline_type == "mentions":
            raw_timeline = self.conn.statuses_mentions(count=get_count,
                                                       page=self.page,
                                                       since_id=last_id)
        elif self.timeline_type == "direct":
            raw_timeline = self.conn.direct_messages(count=get_count,
                                                     page=self.page,
                                                     since_id=last_id)
        elif self.timeline_type == "user":
            raw_timeline = self.conn.statuses_user_timeline(
                user_id=self.type_params['user_id'],
                screen_name=self.type_params['screen_name'],
                count=get_count,
                page=self.page,
                since_id=last_id)
            try:
                self.profile = self.conn.users_show(
                    screen_name=self.type_params['screen_name'])
                # numerical fields, convert them to strings to make the buffer code more clean
                for field in [
                        'id', 'created_at', 'followers_count', 'friends_count',
                        'favourites_count', 'statuses_count'
                ]:
                    self.profile[field] = str(self.profile[field])

                # special handling for following
                if self.profile['following']:
                    self.profile['following'] = "Yes"
                else:
                    self.profile['following'] = "No"

                # create this field specially
                datetime_joined = helpers.normalise_datetime(
                    self.profile['created_at'])
                days_since_join = helpers.single_unit(
                    helpers.time_since(datetime_joined), "days")['days']
                self.profile['notices_per_day'] = "%0.2f" % (
                    float(self.profile['statuses_count']) / days_since_join)

            except StatusNetError, e:
                if e.errcode == 404:
                    self.profile = None
Ejemplo n.º 6
0
                    next_id = self.type_params['notice_id']
                    while next_id is not None:
                        notice = self.conn.statuses_show(id=next_id)
                        raw_timeline.append(notice)
                        if "retweeted_status" in notice:
                            next_id = notice['retweeted_status']['id']
                        else:
                            next_id = notice['in_reply_to_status_id']

        self.prev_page = self.page

        temp_timeline = []
        old_ids = [n['id'] for n in self.timeline]

        for notice in raw_timeline:
            notice["ic__raw_datetime"] = helpers.normalise_datetime(
                notice['created_at'])
            notice["ic__from_web"] = True
            passes_filters = True
            if notice['id'] in old_ids:
                passes_filters = False
                continue
            if hasattr(config.session_store, "muted_conversations") and notice[
                    'statusnet_conversation_id'] in config.session_store.muted_conversations:
                passes_filters = False
                continue
            if config.config["hide_activities"] and ("source" in notice) and (
                    notice["source"] == "activity"):
                passes_filters = False
                continue
            if config.config["filter_mode"] == "regex":
                for filter_item in config.config['filters']: