twitter-cli 0.6.6__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/PKG-INFO +1 -1
  2. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/pyproject.toml +1 -1
  3. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_cli.py +64 -0
  4. twitter_cli-0.7.0/tests/test_search.py +86 -0
  5. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/cli.py +56 -6
  6. twitter_cli-0.7.0/twitter_cli/search.py +79 -0
  7. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  8. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  9. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/.github/workflows/ci.yml +0 -0
  10. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/.github/workflows/publish-clawhub.yml +0 -0
  11. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/.github/workflows/publish.yml +0 -0
  12. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/.gitignore +0 -0
  13. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/LICENSE +0 -0
  14. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/README.md +0 -0
  15. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/SCHEMA.md +0 -0
  16. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/SKILL.md +0 -0
  17. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/config.yaml +0 -0
  18. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/conftest.py +0 -0
  19. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/fixtures/followers_page.json +0 -0
  20. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/fixtures/home_timeline.json +0 -0
  21. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/fixtures/list_timeline.json +0 -0
  22. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/fixtures/search_timeline.json +0 -0
  23. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/fixtures/tweet_detail.json +0 -0
  24. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_auth.py +0 -0
  25. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_client.py +0 -0
  26. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_config.py +0 -0
  27. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_config_normalization.py +0 -0
  28. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_filter.py +0 -0
  29. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_parser_fixtures.py +0 -0
  30. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_serialization.py +0 -0
  31. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/tests/test_smoke.py +0 -0
  32. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/__init__.py +0 -0
  33. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/auth.py +0 -0
  34. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/client.py +0 -0
  35. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/config.py +0 -0
  36. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/constants.py +0 -0
  37. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/exceptions.py +0 -0
  38. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/filter.py +0 -0
  39. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/formatter.py +0 -0
  40. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/graphql.py +0 -0
  41. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/models.py +0 -0
  42. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/output.py +0 -0
  43. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/parser.py +0 -0
  44. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/twitter_cli/serialization.py +0 -0
  45. {twitter_cli-0.6.6 → twitter_cli-0.7.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter-cli
3
- Version: 0.6.6
3
+ Version: 0.7.0
4
4
  Summary: A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal
5
5
  Project-URL: Homepage, https://github.com/jackwener/twitter-cli
6
6
  Project-URL: Repository, https://github.com/jackwener/twitter-cli
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "twitter-cli"
7
- version = "0.6.6"
7
+ version = "0.7.0"
8
8
  description = "A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -425,6 +425,70 @@ def test_cli_unfollow_command(monkeypatch) -> None:
425
425
  assert actions == [("unfollow", "42")]
426
426
 
427
427
 
428
+ def test_cli_search_advanced_options(monkeypatch) -> None:
429
+ captured = {}
430
+
431
+ class FakeClient:
432
+ def fetch_search(self, query: str, count: int, product: str):
433
+ captured["query"] = query
434
+ captured["product"] = product
435
+ return []
436
+
437
+ monkeypatch.setattr("twitter_cli.cli._get_client", lambda config=None: FakeClient())
438
+ monkeypatch.setattr(
439
+ "twitter_cli.cli.load_config",
440
+ lambda: {"fetch": {"count": 50}, "filter": {}, "rateLimit": {}},
441
+ )
442
+ runner = CliRunner()
443
+
444
+ result = runner.invoke(cli, [
445
+ "search", "python",
446
+ "--from", "elonmusk",
447
+ "--lang", "en",
448
+ "--since", "2026-01-01",
449
+ "--has", "links",
450
+ "--exclude", "retweets",
451
+ "--min-likes", "100",
452
+ "-t", "Latest",
453
+ "--json",
454
+ ])
455
+
456
+ assert result.exit_code == 0, f"search failed: {result.output}"
457
+ assert captured["query"] == (
458
+ "python from:elonmusk lang:en since:2026-01-01 "
459
+ "filter:links -filter:retweets min_faves:100"
460
+ )
461
+ assert captured["product"] == "Latest"
462
+
463
+
464
+ def test_cli_search_operators_only_no_query(monkeypatch) -> None:
465
+ captured = {}
466
+
467
+ class FakeClient:
468
+ def fetch_search(self, query: str, count: int, product: str):
469
+ captured["query"] = query
470
+ return []
471
+
472
+ monkeypatch.setattr("twitter_cli.cli._get_client", lambda config=None: FakeClient())
473
+ monkeypatch.setattr(
474
+ "twitter_cli.cli.load_config",
475
+ lambda: {"fetch": {"count": 50}, "filter": {}, "rateLimit": {}},
476
+ )
477
+ runner = CliRunner()
478
+
479
+ result = runner.invoke(cli, ["search", "--from", "bbc", "--json"])
480
+ assert result.exit_code == 0, f"search failed: {result.output}"
481
+ assert captured["query"] == "from:bbc"
482
+
483
+
484
+ def test_cli_search_empty_query_no_options() -> None:
485
+ runner = CliRunner()
486
+
487
+ result = runner.invoke(cli, ["search"])
488
+ assert result.exit_code != 0
489
+ assert "Provide a QUERY" in result.output
490
+
491
+
428
492
  def test_cli_compact_mode(tmp_path, tweet_factory) -> None:
429
493
  json_path = tmp_path / "tweets.json"
430
494
  json_path.write_text(tweets_to_json([tweet_factory("1")]), encoding="utf-8")
@@ -0,0 +1,86 @@
1
+ """Unit tests for the advanced search query builder."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from twitter_cli.search import build_search_query
6
+
7
+
8
+ class TestBuildSearchQuery:
9
+ def test_plain_query(self) -> None:
10
+ assert build_search_query("python") == "python"
11
+
12
+ def test_empty_query(self) -> None:
13
+ assert build_search_query("") == ""
14
+
15
+ def test_from_user(self) -> None:
16
+ assert build_search_query("AI", from_user="elonmusk") == "AI from:elonmusk"
17
+
18
+ def test_from_user_strips_at(self) -> None:
19
+ assert build_search_query("AI", from_user="@elonmusk") == "AI from:elonmusk"
20
+
21
+ def test_to_user(self) -> None:
22
+ assert build_search_query("hello", to_user="jack") == "hello to:jack"
23
+
24
+ def test_lang(self) -> None:
25
+ assert build_search_query("news", lang="fr") == "news lang:fr"
26
+
27
+ def test_since(self) -> None:
28
+ assert build_search_query("python", since="2026-01-01") == "python since:2026-01-01"
29
+
30
+ def test_until(self) -> None:
31
+ assert build_search_query("python", until="2026-03-01") == "python until:2026-03-01"
32
+
33
+ def test_date_range(self) -> None:
34
+ result = build_search_query("rust", since="2026-01-01", until="2026-03-01")
35
+ assert result == "rust since:2026-01-01 until:2026-03-01"
36
+
37
+ def test_has_links(self) -> None:
38
+ assert build_search_query("python", has=["links"]) == "python filter:links"
39
+
40
+ def test_has_multiple(self) -> None:
41
+ result = build_search_query("art", has=["images", "videos"])
42
+ assert result == "art filter:images filter:videos"
43
+
44
+ def test_exclude_retweets(self) -> None:
45
+ assert build_search_query("news", exclude=["retweets"]) == "news -filter:retweets"
46
+
47
+ def test_exclude_replies(self) -> None:
48
+ assert build_search_query("news", exclude=["replies"]) == "news -filter:replies"
49
+
50
+ def test_exclude_multiple(self) -> None:
51
+ result = build_search_query("news", exclude=["retweets", "replies"])
52
+ assert result == "news -filter:retweets -filter:replies"
53
+
54
+ def test_min_likes(self) -> None:
55
+ assert build_search_query("python", min_likes=100) == "python min_faves:100"
56
+
57
+ def test_min_retweets(self) -> None:
58
+ assert build_search_query("python", min_retweets=50) == "python min_retweets:50"
59
+
60
+ def test_combined_operators(self) -> None:
61
+ result = build_search_query(
62
+ "machine learning",
63
+ from_user="openai",
64
+ lang="en",
65
+ since="2026-01-01",
66
+ has=["links"],
67
+ min_likes=50,
68
+ exclude=["retweets"],
69
+ )
70
+ assert result == (
71
+ "machine learning from:openai lang:en since:2026-01-01 "
72
+ "filter:links -filter:retweets min_faves:50"
73
+ )
74
+
75
+ def test_operators_only_no_query(self) -> None:
76
+ result = build_search_query("", from_user="elonmusk", since="2026-03-01")
77
+ assert result == "from:elonmusk since:2026-03-01"
78
+
79
+ def test_whitespace_query_trimmed(self) -> None:
80
+ assert build_search_query(" python ", lang="en") == "python lang:en"
81
+
82
+ def test_empty_has_list(self) -> None:
83
+ assert build_search_query("test", has=[]) == "test"
84
+
85
+ def test_empty_exclude_list(self) -> None:
86
+ assert build_search_query("test", exclude=[]) == "test"
@@ -5,6 +5,7 @@ Read commands:
5
5
  twitter feed -t following # following feed
6
6
  twitter bookmarks # bookmarks
7
7
  twitter search "query" # search tweets
8
+ twitter search "query" --from user # advanced search
8
9
  twitter user elonmusk # user profile
9
10
  twitter user-posts elonmusk # user tweets
10
11
  twitter likes elonmusk # user likes
@@ -87,6 +88,8 @@ logger = logging.getLogger(__name__)
87
88
  console = Console(stderr=True)
88
89
  FEED_TYPES = ["for-you", "following"]
89
90
  SEARCH_PRODUCTS = ["Top", "Latest", "Photos", "Videos"]
91
+ SEARCH_HAS_CHOICES = ["links", "images", "videos", "media"]
92
+ SEARCH_EXCLUDE_CHOICES = ["retweets", "replies", "links"]
90
93
 
91
94
 
92
95
  def _agent_user_profile(profile: UserProfile) -> dict:
@@ -537,7 +540,7 @@ def user_posts(ctx, screen_name, max_count, as_json, as_yaml, output_file, full_
537
540
 
538
541
 
539
542
  @cli.command()
540
- @click.argument("query")
543
+ @click.argument("query", default="")
541
544
  @click.option(
542
545
  "--type",
543
546
  "-t",
@@ -546,23 +549,70 @@ def user_posts(ctx, screen_name, max_count, as_json, as_yaml, output_file, full_
546
549
  default="Top",
547
550
  help="Search tab: Top, Latest, Photos, or Videos.",
548
551
  )
552
+ @click.option("--from", "from_user", type=str, default=None, help="Only tweets from this user.")
553
+ @click.option("--to", "to_user", type=str, default=None, help="Only tweets directed at this user.")
554
+ @click.option("--lang", type=str, default=None, help="Filter by language (ISO code, e.g. en, fr, ja).")
555
+ @click.option("--since", type=str, default=None, help="Tweets since date (YYYY-MM-DD).")
556
+ @click.option("--until", type=str, default=None, help="Tweets until date (YYYY-MM-DD).")
557
+ @click.option(
558
+ "--has",
559
+ type=click.Choice(SEARCH_HAS_CHOICES, case_sensitive=False),
560
+ multiple=True,
561
+ help="Require content type (links, images, videos, media). Repeatable.",
562
+ )
563
+ @click.option(
564
+ "--exclude",
565
+ type=click.Choice(SEARCH_EXCLUDE_CHOICES, case_sensitive=False),
566
+ multiple=True,
567
+ help="Exclude content type (retweets, replies, links). Repeatable.",
568
+ )
569
+ @click.option("--min-likes", type=int, default=None, help="Minimum number of likes.")
570
+ @click.option("--min-retweets", type=int, default=None, help="Minimum number of retweets.")
549
571
  @click.option("--max", "-n", "max_count", type=int, default=None, help="Max number of tweets to fetch.")
550
572
  @structured_output_options
551
573
  @click.option("--output", "-o", "output_file", type=str, default=None, help="Save tweets to JSON file.")
552
574
  @click.option("--filter", "do_filter", is_flag=True, help="Enable score-based filtering.")
553
575
  @click.option("--full-text", is_flag=True, help="Show full tweet text in table output.")
554
576
  @click.pass_context
555
- def search(ctx, query, product, max_count, as_json, as_yaml, output_file, do_filter, full_text):
556
- # type: (Any, str, str, int, bool, bool, Optional[str], bool, bool) -> None
557
- """Search tweets by QUERY string."""
577
+ def search(ctx, query, product, from_user, to_user, lang, since, until, has, exclude, min_likes, min_retweets, max_count, as_json, as_yaml, output_file, do_filter, full_text):
578
+ # type: (Any, str, str, Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], tuple, tuple, Optional[int], Optional[int], int, bool, bool, Optional[str], bool, bool) -> None
579
+ """Search tweets by QUERY string with optional advanced filters.
580
+
581
+ QUERY is the search keywords (optional when using advanced filters).
582
+
583
+ Advanced search examples:
584
+
585
+ \b
586
+ twitter search "python" --from elonmusk
587
+ twitter search "AI" --lang en --since 2026-01-01
588
+ twitter search "rust" --has links --min-likes 100
589
+ twitter search --from bbc --exclude retweets
590
+ """
591
+ from .search import build_search_query
592
+
593
+ composed_query = build_search_query(
594
+ query,
595
+ from_user=from_user,
596
+ to_user=to_user,
597
+ lang=lang,
598
+ since=since,
599
+ until=until,
600
+ has=list(has) if has else None,
601
+ exclude=list(exclude) if exclude else None,
602
+ min_likes=min_likes,
603
+ min_retweets=min_retweets,
604
+ )
605
+ if not composed_query:
606
+ raise click.UsageError("Provide a QUERY or at least one advanced filter (e.g. --from, --lang).")
607
+
558
608
  compact = ctx.obj.get("compact", False)
559
609
  config = load_config()
560
610
  def _run():
561
611
  rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml, compact=compact)
562
612
  client = _get_client_for_output(config, quiet=not rich_output)
563
613
  _fetch_and_display(
564
- lambda count: client.fetch_search(query, count, product),
565
- "'%s' (%s)" % (query, product), "🔍", max_count, as_json, as_yaml, output_file, do_filter, config,
614
+ lambda count: client.fetch_search(composed_query, count, product),
615
+ "'%s' (%s)" % (composed_query, product), "🔍", max_count, as_json, as_yaml, output_file, do_filter, config,
566
616
  compact=compact, full_text=full_text,
567
617
  )
568
618
  _run_guarded(_run)
@@ -0,0 +1,79 @@
1
+ """Advanced search query builder.
2
+
3
+ Composes Twitter search operators into a raw query string for the
4
+ SearchTimeline GraphQL endpoint.
5
+
6
+ Reference: https://help.x.com/en/using-x/x-advanced-search
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import List, Optional, Sequence
12
+
13
+
14
+ def build_search_query(
15
+ query: str = "",
16
+ *,
17
+ from_user: Optional[str] = None,
18
+ to_user: Optional[str] = None,
19
+ lang: Optional[str] = None,
20
+ since: Optional[str] = None,
21
+ until: Optional[str] = None,
22
+ has: Optional[Sequence[str]] = None,
23
+ exclude: Optional[Sequence[str]] = None,
24
+ min_likes: Optional[int] = None,
25
+ min_retweets: Optional[int] = None,
26
+ ) -> str:
27
+ """Build an advanced search query string.
28
+
29
+ Args:
30
+ query: Base search keywords.
31
+ from_user: Only tweets from this user (screen_name).
32
+ to_user: Only tweets directed at this user.
33
+ lang: ISO 639-1 language code (e.g. "en", "fr", "ja").
34
+ since: Start date in YYYY-MM-DD format.
35
+ until: End date in YYYY-MM-DD format.
36
+ has: List of content types to require. Accepted values:
37
+ "links", "images", "videos", "media".
38
+ exclude: List of content types to exclude. Accepted values:
39
+ "retweets", "replies", "links".
40
+ min_likes: Minimum number of likes (faves).
41
+ min_retweets: Minimum number of retweets.
42
+
43
+ Returns:
44
+ Composed query string ready for the rawQuery API parameter.
45
+ """
46
+ parts: List[str] = []
47
+
48
+ if query and query.strip():
49
+ parts.append(query.strip())
50
+
51
+ if from_user:
52
+ parts.append("from:%s" % from_user.lstrip("@"))
53
+ if to_user:
54
+ parts.append("to:%s" % to_user.lstrip("@"))
55
+ if lang:
56
+ parts.append("lang:%s" % lang)
57
+ if since:
58
+ parts.append("since:%s" % since)
59
+ if until:
60
+ parts.append("until:%s" % until)
61
+ if has:
62
+ for item in has:
63
+ parts.append("filter:%s" % item)
64
+ if exclude:
65
+ for item in exclude:
66
+ if item == "retweets":
67
+ parts.append("-filter:retweets")
68
+ elif item == "replies":
69
+ parts.append("-filter:replies")
70
+ elif item == "links":
71
+ parts.append("-filter:links")
72
+ else:
73
+ parts.append("-filter:%s" % item)
74
+ if min_likes is not None:
75
+ parts.append("min_faves:%d" % min_likes)
76
+ if min_retweets is not None:
77
+ parts.append("min_retweets:%d" % min_retweets)
78
+
79
+ return " ".join(parts)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes