|
1 | 1 | import json as pyjson |
2 | | -from typing import Optional |
3 | | -from urllib.parse import quote |
4 | 2 |
|
5 | 3 | import click |
6 | 4 |
|
7 | | -from toot import api, http |
| 5 | +from toot import api |
8 | 6 | from toot.cli import Context, cli, json_option, pass_context |
9 | | -from toot.cli.validators import validate_positive |
10 | | -from toot.entities import Status, Tag, from_dict, from_response_list, from_responses_batched |
11 | | -from toot.output import get_continue, green, print_tag_list, print_timeline, yellow |
12 | | -from toot.utils import drop_empty_values, str_bool_nullable |
| 7 | +from toot.entities import Tag, from_dict |
| 8 | +from toot.output import print_tag_list |
13 | 9 |
|
14 | 10 |
|
15 | 11 | @cli.group() |
@@ -133,105 +129,3 @@ def unfeature(ctx: Context, tag: str, json: bool): |
133 | 129 | click.echo(response.text) |
134 | 130 | else: |
135 | 131 | click.secho(f"✓ Tag #{featured_tag['name']} is no longer featured", fg="green") |
136 | | - |
137 | | - |
138 | | -@tags.command() |
139 | | -@click.argument("tag_name") |
140 | | -@click.option( |
141 | | - "-l", |
142 | | - "--local", |
143 | | - is_flag=True, |
144 | | - help="Return only local statuses", |
145 | | -) |
146 | | -@click.option( |
147 | | - "-r", |
148 | | - "--remote", |
149 | | - is_flag=True, |
150 | | - help="Return only remote statuses", |
151 | | -) |
152 | | -@click.option( |
153 | | - "-m", |
154 | | - "--media", |
155 | | - is_flag=True, |
156 | | - help="Return only statuses with media attachments", |
157 | | -) |
158 | | -@click.option( |
159 | | - "-n", |
160 | | - "--limit", |
161 | | - type=int, |
162 | | - default=20, |
163 | | - help="Number of results to fetch per request [max: 40]", |
164 | | -) |
165 | | -@click.option( |
166 | | - "-p", |
167 | | - "--pager", |
168 | | - help="Page the results, optionally define how many results to show per page", |
169 | | - type=int, |
170 | | - callback=validate_positive, |
171 | | - is_flag=False, |
172 | | - flag_value=10, |
173 | | -) |
174 | | -@click.option( |
175 | | - "-c", |
176 | | - "--clear", |
177 | | - help="Clear the screen before printing", |
178 | | - is_flag=True, |
179 | | -) |
180 | | -@json_option |
181 | | -@pass_context |
182 | | -def timeline( |
183 | | - ctx: Context, |
184 | | - tag_name: str, |
185 | | - local: bool, |
186 | | - remote: bool, |
187 | | - media: bool, |
188 | | - limit: int, |
189 | | - pager: Optional[int], |
190 | | - clear: bool, |
191 | | - json: bool, |
192 | | -): |
193 | | - """View hashtag timeline""" |
194 | | - # TODO: Add `any`, `all`, and `none` params |
195 | | - # TODO: Add `max_id`, `since_id`, and `min_id` params |
196 | | - path = f"/api/v1/timelines/tag/{quote(tag_name)}" |
197 | | - |
198 | | - params = drop_empty_values( |
199 | | - { |
200 | | - "local": str_bool_nullable(local), |
201 | | - "remote": str_bool_nullable(remote), |
202 | | - "media": str_bool_nullable(media), |
203 | | - "limit": limit, |
204 | | - } |
205 | | - ) |
206 | | - |
207 | | - if json: |
208 | | - response = http.get(ctx.app, ctx.user, path, params) |
209 | | - click.echo(response.text) |
210 | | - return |
211 | | - |
212 | | - if pager: |
213 | | - first = True |
214 | | - printed_any = False |
215 | | - |
216 | | - responses = http.get_paged(ctx.app, ctx.user, path, params) |
217 | | - for page in from_responses_batched(responses, Status, pager): |
218 | | - if not first and not get_continue(): |
219 | | - break |
220 | | - if clear: |
221 | | - click.clear() |
222 | | - print_timeline(page) |
223 | | - first = False |
224 | | - printed_any = True |
225 | | - |
226 | | - if not printed_any: |
227 | | - click.echo("No statuses found containing the given tag") |
228 | | - return |
229 | | - |
230 | | - response = http.get(ctx.app, ctx.user, path, params) |
231 | | - statuses = from_response_list(Status, response) |
232 | | - if statuses: |
233 | | - print_timeline(statuses) |
234 | | - if len(statuses) == limit: |
235 | | - click.secho("There may be more results. Increase the --limit or use --pager to see the rest.", dim=True) |
236 | | - else: |
237 | | - click.echo("No statuses found containing the given tag") |
0 commit comments