summaryrefslogtreecommitdiffstats
path: root/cmd/x.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/x.go')
-rw-r--r--cmd/x.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/cmd/x.go b/cmd/x.go
index d0d3209..3164b23 100644
--- a/cmd/x.go
+++ b/cmd/x.go
@@ -48,12 +48,33 @@ var xNFLCmd = &cobra.Command{
RunE: runXNotableFollowers,
}
+var xRepliesCmd = &cobra.Command{
+ Use: "replies [tweet_id]",
+ Short: "Fetch all replies for a tweet",
+ Long: `Fetches all replies for a given tweet ID and streams results as NDJSON`,
+ Args: cobra.ExactArgs(1),
+ RunE: runXReplies,
+}
+
+var xSearchCmd = &cobra.Command{
+ Use: "search [query]",
+ Short: "Search for tweets matching a term",
+ Long: `Searches Twitter/X for tweets matching the given search term and streams results as NDJSON`,
+ Args: cobra.ExactArgs(1),
+ RunE: runXSearch,
+}
+
func init() {
rootCmd.AddCommand(xCmd)
xCmd.AddCommand(xHistoryCmd)
xCmd.AddCommand(xTweetsCmd)
xCmd.AddCommand(xFirstCmd)
xCmd.AddCommand(xNFLCmd)
+ xCmd.AddCommand(xRepliesCmd)
+ xCmd.AddCommand(xSearchCmd)
+
+ xRepliesCmd.Flags().Int("limit", 100, "Maximum number of replies to fetch")
+ xSearchCmd.Flags().Int("limit", 100, "Maximum number of tweets to fetch")
}
func runXHistorySearch(cmd *cobra.Command, args []string) error {
@@ -140,3 +161,47 @@ func runXNotableFollowers(cmd *cobra.Command, args []string) error {
return utils.PrintJSON(response)
}
+
+func runXReplies(cmd *cobra.Command, args []string) error {
+ apiKey, _ := cmd.Flags().GetString("api-key")
+ limit, _ := cmd.Flags().GetInt("limit")
+ cfg := config.New().WithAPIKey(apiKey)
+
+ c, err := client.New(cfg)
+ if err != nil {
+ return err
+ }
+
+ err = c.FetchRepliesStream(args[0], limit, func(result json.RawMessage) error {
+ fmt.Println(string(result))
+ return nil
+ })
+
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func runXSearch(cmd *cobra.Command, args []string) error {
+ apiKey, _ := cmd.Flags().GetString("api-key")
+ limit, _ := cmd.Flags().GetInt("limit")
+ cfg := config.New().WithAPIKey(apiKey)
+
+ c, err := client.New(cfg)
+ if err != nil {
+ return err
+ }
+
+ err = c.SearchTweetsStream(args[0], limit, func(result json.RawMessage) error {
+ fmt.Println(string(result))
+ return nil
+ })
+
+ if err != nil {
+ return err
+ }
+
+ return nil
+}