chore: Add ScrapeURL flag for CLI to scrape website URL to markdown using Jina AI

This commit is contained in:
Noam Siegel 2024-08-21 10:44:57 -07:00
parent a81e5be74b
commit c7449c68b7
2 changed files with 40 additions and 22 deletions

View File

@ -3,6 +3,7 @@ package cli
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
@ -94,6 +95,21 @@ func Cli() (message string, err error) {
return
}
// Check for ScrapeURL flag first
if currentFlags.ScrapeURL != "" {
fmt.Println("ScrapeURL flag is set") // Debug print
url := currentFlags.ScrapeURL
curlCommand := fmt.Sprintf("curl https://r.jina.ai/%s", url)
fmt.Println("Executing command:", curlCommand) // Debug print
if err := exec.Command("sh", "-c", curlCommand).Run(); err != nil {
return "", fmt.Errorf("failed to run curl command: %w", err)
}
fmt.Println("Curl command executed successfully") // Debug print
os.Exit(0)
} else {
fmt.Println("ScrapeURL flag is not set") // Debug print
}
// if the interactive flag is set, run the interactive function
// if currentFlags.Interactive {
// interactive.Interactive()

View File

@ -34,6 +34,8 @@ type Flags struct {
Output string `short:"o" long:"output" description:"Output to file" default:""`
LatestPatterns string `short:"n" long:"latest" description:"Number of latest patterns to list" default:"0"`
ChangeDefaultModel bool `short:"d" long:"changeDefaultModel" description:"Change default pattern"`
ScrapeURL string `short:"u" long:"scrape_url" description:"Scrape website URL to markdown using Jina AI"`
}
// Init Initialize flags. returns a Flags struct and an error