Example #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)
        elif self.timeline_type == "group":
            raw_timeline = self.conn.statusnet_groups_timeline(
                group_id=self.type_params['group_id'],
                nickname=self.type_params['nickname'],
                count=get_count,
                page=self.page,
                since_id=last_id)
        elif self.timeline_type == "tag":
            raw_timeline = self.conn.statusnet_tags_timeline(
                tag=self.type_params['tag'],
                count=get_count,
                page=self.page,
                since_id=last_id)
        elif self.timeline_type == "sentdirect":
            raw_timeline = self.conn.direct_messages_sent(count=get_count,
                                                          page=self.page,
                                                          since_id=last_id)
        elif self.timeline_type == "public":
            raw_timeline = self.conn.statuses_public_timeline()
        elif self.timeline_type == "favourites":
            raw_timeline = self.conn.favorites(page=self.page,
                                               since_id=last_id)
        elif self.timeline_type == "search":
            raw_timeline = self.conn.search(self.type_params['query'],
                                            page=self.page,
                                            standardise=True,
                                            since_id=last_id)
        elif self.timeline_type == "context":
            raw_timeline = []
            if last_id == 0:  # don't run this if we've already filled the timeline
                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.notice_datetime(notice)
            notice["ic__from_web"] = True
            passes_filters = True
            if notice['id'] in old_ids:
                passes_filters = False
                continue
            for filter_item in config.config['filters']:
                if filter_item.lower() in notice['text'].lower():
                    passes_filters = False
                    break
            if passes_filters:
                if (not self.timeline_type in ["direct", "sentdirect"]
                    ) and notice["source"] == "ostatus" and config.config[
                        'expand_remote'] and "attachments" in notice:
                    import urllib2
                    for attachment in notice['attachments']:
                        if attachment['mimetype'] != "text/html":
                            continue
                        req = urllib2.Request(attachment['url'])
                        try:
                            page = urllib2.urlopen(req).read()
                            try:
                                notice['text'] = helpers.html_unescape_string(
                                    helpers.title_regex.findall(page)[0])
                            except IndexError:  # no title could be found
                                pass
                        except:  # link was broken
                            pass
                        break
                temp_timeline.append(notice)

        if self.timeline_type in [
                "direct", "mentions"
        ]:  # alert on changes to these. maybe config option later?
            if (len(self.timeline) > 0) and (
                    len(temp_timeline) > 0
            ):  # only fire when there's new stuff _and_ we've already got something in the timeline
                if config.config['notify'] == 'flash':
                    curses.flash()
                elif config.config['notify'] == 'beep':
                    curses.beep()

        if len(self.timeline) == 0:
            self.timeline = temp_timeline[:]
        else:
            self.timeline = temp_timeline + self.timeline
            if len(self.timeline) > get_count:  # truncate long timelines
                self.timeline = self.timeline[:get_count]

        self.timeline.sort(key=itemgetter('id'), reverse=True)

        self.search_highlight_line = -1

        self.update_buffer()
Example #2
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,
            )
        elif self.timeline_type == "group":
            raw_timeline = self.conn.statusnet_groups_timeline(
                group_id=self.type_params["group_id"],
                nickname=self.type_params["nickname"],
                count=get_count,
                page=self.page,
                since_id=last_id,
            )
        elif self.timeline_type == "tag":
            raw_timeline = self.conn.statusnet_tags_timeline(
                tag=self.type_params["tag"], count=get_count, page=self.page, since_id=last_id
            )
        elif self.timeline_type == "sentdirect":
            raw_timeline = self.conn.direct_messages_sent(count=get_count, page=self.page, since_id=last_id)
        elif self.timeline_type == "public":
            raw_timeline = self.conn.statuses_public_timeline()
        elif self.timeline_type == "favourites":
            raw_timeline = self.conn.favorites(page=self.page, since_id=last_id)
        elif self.timeline_type == "search":
            raw_timeline = self.conn.search(
                self.type_params["query"], page=self.page, standardise=True, since_id=last_id
            )
        elif self.timeline_type == "context":
            raw_timeline = []
            if last_id == 0:  # don't run this if we've already filled the timeline
                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.notice_datetime(notice)
            notice["ic__from_web"] = True
            passes_filters = True
            if notice["id"] in old_ids:
                passes_filters = False
                continue
            for filter_item in config.config["filters"]:
                if filter_item.lower() in notice["text"].lower():
                    passes_filters = False
                    break
            if passes_filters:
                if (
                    (not self.timeline_type in ["direct", "sentdirect"])
                    and notice["source"] == "ostatus"
                    and config.config["expand_remote"]
                    and "attachments" in notice
                ):
                    import urllib2

                    for attachment in notice["attachments"]:
                        if attachment["mimetype"] != "text/html":
                            continue
                        req = urllib2.Request(attachment["url"])
                        try:
                            page = urllib2.urlopen(req).read()
                            try:
                                notice["text"] = helpers.html_unescape_string(helpers.title_regex.findall(page)[0])
                            except IndexError:  # no title could be found
                                pass
                        except:  # link was broken
                            pass
                        break
                temp_timeline.append(notice)

        if self.timeline_type in ["direct", "mentions"]:  # alert on changes to these. maybe config option later?
            if (len(self.timeline) > 0) and (
                len(temp_timeline) > 0
            ):  # only fire when there's new stuff _and_ we've already got something in the timeline
                if config.config["notify"] == "flash":
                    curses.flash()
                elif config.config["notify"] == "beep":
                    curses.beep()

        if len(self.timeline) == 0:
            self.timeline = temp_timeline[:]
        else:
            self.timeline = temp_timeline + self.timeline
            if len(self.timeline) > get_count:  # truncate long timelines
                self.timeline = self.timeline[:get_count]

        self.timeline.sort(key=itemgetter("id"), reverse=True)

        self.search_highlight_line = -1

        self.update_buffer()
Example #3
0
            else:
                for filter_item in config.config['filters']:
                    if filter_item.lower() in notice['text'].lower():
                        passes_filters = False
                        break
            if passes_filters:
                if (not self.timeline_type in ["direct", "sentdirect"]) and notice["source"] == "ostatus" and config.config['expand_remote'] and "attachments" in notice:
                    import urllib2
                    for attachment in notice['attachments']:
                        if attachment['mimetype'] != "text/html":
                            continue
                        req = urllib2.Request(attachment['url'])
                        try:
                            page = urllib2.urlopen(req).read()
                            try:
                                notice['text'] = helpers.html_unescape_string(helpers.title_regex.findall(page)[0])
                            except IndexError:  # no title could be found
                                pass
                        except:  # link was broken
                            pass
                        break
                temp_timeline.append(notice)

        if self.timeline_type in ["direct", "mentions"]:  # alert on changes to these. maybe config option later?
            if (len(self.timeline) > 0) and (len(temp_timeline) > 0):  # only fire when there's new stuff _and_ we've already got something in the timeline
                if config.config['notify'] == 'flash':
                    curses.flash()
                elif config.config['notify'] == 'beep':
                    curses.beep()

        if len(self.timeline) == 0:
Example #4
0
                    if filter_item.lower() in notice['text'].lower():
                        passes_filters = False
                        break
            if passes_filters:
                if (not self.timeline_type in ["direct", "sentdirect"]
                    ) and notice["source"] == "ostatus" and config.config[
                        'expand_remote'] and "attachments" in notice:
                    import urllib2
                    for attachment in notice['attachments']:
                        if attachment['mimetype'] != "text/html":
                            continue
                        req = urllib2.Request(attachment['url'])
                        try:
                            page = urllib2.urlopen(req).read()
                            try:
                                notice['text'] = helpers.html_unescape_string(
                                    helpers.title_regex.findall(page)[0])
                            except IndexError:  # no title could be found
                                pass
                        except:  # link was broken
                            pass
                        break
                temp_timeline.append(notice)

        if self.timeline_type in [
                "direct", "mentions"
        ]:  # alert on changes to these. maybe config option later?
            if (len(self.timeline) > 0) and (
                    len(temp_timeline) > 0
            ):  # only fire when there's new stuff _and_ we've already got something in the timeline
                if config.config['notify'] == 'flash':
                    curses.flash()