diff --git a/README.md b/README.md index 59caa52..8b97792 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,10 @@ +

# Installation - wb requires **go1.17** to install successfully. Run the following command to get the repo - ```sh @@ -24,14 +24,40 @@ go install github.com/riza/wb@latest # Usage +### Quick ```sh echo "https://akamai.airbnb.com/robots.txt"|wb ``` + ```sh wb https://akamai.airbnb.com/robots.txt ``` -# TODOs +### Advanced +```sh +Usage: + wb [flags] + + -all + get all snapshots + -date string + get snapshot for a specific date + -help + show help + -no-banner + hide banner + -snapshots + get all snapshots +``` + +## Advanced Usage Scenarios +```sh +$ under construct +``` + +## Donate + +Buy Me A Coffee -* [ ] Timestamp selection + diff --git a/main.go b/main.go index bf04f31..f2735c4 100644 --- a/main.go +++ b/main.go @@ -13,15 +13,37 @@ import ( ) const ( + version = "0.0.4" + wbSnapshotApiURL = "https://web.archive.org/cdx/search/xd?output=json&url=%s&fl=timestamp,original&collapse=digest&gzip=false&filter=statuscode:200" wbFileURL = "https://web.archive.org/web/%sid_/%s" + + parseTimeLayout = "20060102150405" + viewTimeLayout = "2006-01-02 15:04:05" ) -func main() { - var url string +var ( + flagSnapshots = flag.Bool("snapshots", false, "get all snapshots") + flagDate = flag.String("date", "", "get snapshot for a specific date") + flagGetAllSnapshots = flag.Bool("all", false, "get all snapshots") + flagHelp = flag.Bool("help", false, "show help") + flagNoBanner = flag.Bool("no-banner", false, "hide banner") +) +func main() { flag.Parse() + if !*flagNoBanner { + fmt.Printf("🪄 wb / v%s\n----\n", version) + } + + if *flagHelp { + fmt.Println("Usage: \n wb [flags]\n") + flag.PrintDefaults() + os.Exit(0) + } + + var url string if flag.NArg() > 0 { url = flag.Arg(0) } else { @@ -44,8 +66,41 @@ func main() { log.Fatalf("failed to snapshots: %s\n", err) } - lastSnapshot := snapshots[len(snapshots)-1] - snapshotContent, err := getSnapshotContent(client, lastSnapshot[0], lastSnapshot[1]) + if *flagSnapshots { + fmt.Println("Snapshots for", url) + for _, s := range snapshots { + parsedTime, err := time.Parse(parseTimeLayout, s[0]) + if err != nil { + log.Fatalf("failed to parse time: %s\n", err) + } + fmt.Printf("* %s | %s | %s\n", s[0], parsedTime.Format(viewTimeLayout), s[1]) + } + os.Exit(0) + } + + selectedSnapshot := snapshots[len(snapshots)-1] + if *flagDate != "" { + for _, s := range snapshots { + if s[0] == *flagDate { + selectedSnapshot = s + break + } + } + } + + if *flagGetAllSnapshots { + for _, s := range snapshots { + snapshotContent, err := getSnapshotContent(client, s[0], s[1]) + if err != nil { + log.Fatalf("failed to read input: %s\n", err) + } + + io.Copy(os.Stdout, snapshotContent) + } + os.Exit(0) + } + + snapshotContent, err := getSnapshotContent(client, selectedSnapshot[0], selectedSnapshot[1]) if err != nil { log.Fatalf("failed to read input: %s\n", err) }