117def _get_posts(json):
118 results = []
119
120 for result in json["posts"]:
121 user = result['creator'].get('display_name', result['creator']['name'])
122
123 thumbnail = None
124 if result['post'].get('thumbnail_url'):
125 thumbnail = result['post']['thumbnail_url'] + '?format=webp&thumbnail=208'
126
127 metadata = (
128 f"▲ {result['counts']['upvotes']} ▼ {result['counts']['downvotes']}"
129 f" | {gettext('user')}: {user}"
130 f" | {gettext('comments')}: {result['counts']['comments']}"
131 f" | {gettext('community')}: {result['community']['title']}"
132 )
133
134 content = result['post'].get('body', '').strip()
135 if content:
136 content = markdown_to_text(content)
137
138 results.append(
139 {
140 'url': result['post']['ap_id'],
141 'title': result['post']['name'],
142 'content': content,
143 'thumbnail': thumbnail,
144 'publishedDate': datetime.strptime(result['post']['published'][:19], '%Y-%m-%dT%H:%M:%S'),
145 'metadata': metadata,
146 }
147 )
148
149 return results
150
151