diff options
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/osint.go | 22 | ||||
| -rw-r--r-- | cmd/sl.go | 6 | ||||
| -rw-r--r-- | cmd/x.go | 65 |
3 files changed, 86 insertions, 7 deletions
diff --git a/cmd/osint.go b/cmd/osint.go index eb1ec50..33b5416 100644 --- a/cmd/osint.go +++ b/cmd/osint.go @@ -159,10 +159,9 @@ func runOsintUsernameCheck(cmd *cobra.Command, args []string) error { } func runOsintBSSIDLookup(cmd *cobra.Command, args []string) error { - apiKey, _ := cmd.Flags().GetString("api-key") - cfg := config.New().WithAPIKey(apiKey) + cfg := config.New() - c, err := client.New(cfg) + c, err := client.NewUnauthenticated(cfg) if err != nil { return err } @@ -183,10 +182,9 @@ func runOsintBSSIDLookup(cmd *cobra.Command, args []string) error { } func runOsintBreachForumSearch(cmd *cobra.Command, args []string) error { - apiKey, _ := cmd.Flags().GetString("api-key") - cfg := config.New().WithAPIKey(apiKey) + cfg := config.New() - c, err := client.New(cfg) + c, err := client.NewUnauthenticated(cfg) if err != nil { return err } @@ -231,6 +229,9 @@ func runOsintFilesSearch(cmd *cobra.Command, args []string) error { func runOsintBucketsSearch(cmd *cobra.Command, args []string) error { apiKey, _ := cmd.Flags().GetString("api-key") + if apiKey == "" { + return fmt.Errorf("API key required for buckets endpoint") + } cfg := config.New().WithAPIKey(apiKey) c, err := client.New(cfg) @@ -252,6 +253,9 @@ func runOsintBucketsSearch(cmd *cobra.Command, args []string) error { func runOsintBucketFilesSearch(cmd *cobra.Command, args []string) error { apiKey, _ := cmd.Flags().GetString("api-key") + if apiKey == "" { + return fmt.Errorf("API key required for bucket files endpoint") + } cfg := config.New().WithAPIKey(apiKey) c, err := client.New(cfg) @@ -276,6 +280,9 @@ func runOsintBucketFilesSearch(cmd *cobra.Command, args []string) error { func runOsintShortlinksSearch(cmd *cobra.Command, args []string) error { apiKey, _ := cmd.Flags().GetString("api-key") + if apiKey == "" { + return fmt.Errorf("API key required for shortlinks endpoint") + } cfg := config.New().WithAPIKey(apiKey) c, err := client.New(cfg) @@ -302,6 +309,9 @@ func runOsintShortlinksSearch(cmd *cobra.Command, args []string) error { func runOsintGeoSearch(cmd *cobra.Command, args []string) error { apiKey, _ := cmd.Flags().GetString("api-key") + if apiKey == "" { + return fmt.Errorf("API key required for geo endpoint (costs 1 credit)") + } cfg := config.New().WithAPIKey(apiKey) c, err := client.New(cfg) @@ -42,7 +42,11 @@ func runSLSearch(cmd *cobra.Command, args []string) error { Query: args[0], } params.MaxHits, _ = cmd.Flags().GetInt("max_hits") - params.SortBy, _ = cmd.Flags().GetString("sort_by") + sortBy, _ := cmd.Flags().GetString("sort_by") + if sortBy != "" && sortBy != "ingest_timestamp" && sortBy != "date_posted" { + return fmt.Errorf("invalid sort_by value: must be 'ingest_timestamp' or 'date_posted'") + } + params.SortBy = sortBy params.IngestStartDate, _ = cmd.Flags().GetString("ingest_start_date") params.IngestEndDate, _ = cmd.Flags().GetString("ingest_end_date") params.PostedStartDate, _ = cmd.Flags().GetString("posted_start_date") @@ -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 +} |
