def parse_status(status): _status = status.get('reblog') or status account = parse_account(_status['account']) content = list(format_content(_status['content'])) spoiler_text = list(format_content(_status['spoiler_text'])) if _status['spoiler_text'] else [] created_at = status['created_at'][:19].split('T') boosted_by = parse_account(status['account']) if status['reblog'] else None return { 'account': account, 'boosted_by': boosted_by, 'created_at': created_at, 'content': content, 'favourited': status.get('favourited'), 'favourites_count': _status['favourites_count'], 'id': status['id'], 'in_reply_to_id': _status.get('in_reply_to_id'), 'media_attachments': _status['media_attachments'], 'url': _status['url'], 'reblogged': status.get('reblogged'), 'reblogs_count': _status['reblogs_count'], 'replies_count': _status.get('replies_count', 0), 'spoiler_text': spoiler_text, 'sensitive': _status['sensitive'], 'show_sensitive': False, }
def print_instance(instance): print_out("<green>{}</green>".format(instance['title'])) print_out("<blue>{}</blue>".format(instance['uri'])) print_out("running Mastodon {}".format(instance['version'])) print_out("") description = instance['description'].strip() if not description: return lines = [line.strip() for line in format_content(description) if line.strip()] for line in lines: for l in wrap(line.strip()): print_out(l) print_out()
def parse_status(status): _status = status.get('reblog') or status account = parse_account(_status['account']) lines = list(format_content(_status['content'])) created_at = status['created_at'][:19].split('T') boosted_by = parse_account(status['account']) if status['reblog'] else None return { 'account': account, 'boosted_by': boosted_by, 'created_at': created_at, 'lines': lines, 'media_attachments': _status['media_attachments'], 'url': status['url'], }
def content_generator(self, status, reblogged_by): if reblogged_by: text = "♺ {} boosted".format(reblogged_by.display_name) yield ("pack", urwid.Text(("gray", text))) yield ("pack", urwid.AttrMap(urwid.Divider("-"), "gray")) if status.author.display_name: yield ("pack", urwid.Text(("green", status.author.display_name))) yield ("pack", urwid.Text(("yellow", status.author.account))) yield ("pack", urwid.Divider()) if status.data["spoiler_text"]: yield ("pack", urwid.Text(status.data["spoiler_text"])) yield ("pack", urwid.Divider()) # Show content warning if status.data["spoiler_text"] and not status.show_sensitive: yield ("pack", urwid.Text(("content_warning", "Marked as sensitive. Press S to view."))) else: for line in format_content(status.data["content"]): yield ("pack", urwid.Text(highlight_hashtags(line))) media = status.data["media_attachments"] if media: for m in media: yield ("pack", urwid.AttrMap(urwid.Divider("-"), "gray")) yield ("pack", urwid.Text([("bold", "Media attachment"), " (", m["type"], ")"])) if m["description"]: yield ("pack", urwid.Text(m["description"])) url = m.get("text_url") or m["url"] yield ("pack", urwid.Text(("link", url))) poll = status.data.get("poll") if poll: yield ("pack", urwid.Divider()) yield ("pack", self.build_linebox(self.poll_generator(poll))) card = status.data.get("card") if card: yield ("pack", urwid.Divider()) yield ("pack", self.build_linebox(self.card_generator(card))) application = status.data.get("application") or {} application = application.get("name") yield ("pack", urwid.AttrWrap(urwid.Divider("-"), "gray")) yield ("pack", urwid.Text([ ("gray", "⤶ {} ".format(status.data["replies_count"])), ("yellow" if status.reblogged else "gray", "♺ {} ".format(status.data["reblogs_count"])), ("yellow" if status.favourited else "gray", "★ {}".format(status.data["favourites_count"])), ("gray", " · {}".format(application) if application else ""), ])) # Push things to bottom yield ("weight", 1, urwid.SolidFill(" ")) options = [ "[B]oost", "[D]elete" if status.is_mine else "", "[F]avourite", "[V]iew", "[T]hread" if not self.in_thread else "", "[R]eply", "So[u]rce", "[H]elp", ] options = " ".join(o for o in options if o) options = highlight_keys(options, "cyan_bold", "cyan") yield ("pack", urwid.Text(options))