Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
go-version: 1.17

- name: "Create release on GitHub"
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v5
with:
args: "release --rm-dist"
version: latest
Expand Down
2 changes: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ builds:

archives:
- format: zip
replacements:
darwin: macOS

checksum:
algorithm: sha256
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<a href="https://twitter.com/rizasabuncu">
<img src="https://img.shields.io/twitter/follow/rizasabuncu.svg?logo=twitter">
</a>

</p>

# Installation

wb requires **go1.17** to install successfully. Run the following command to get the repo -

```sh
Expand All @@ -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 <url> [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

<a href="https://www.buymeacoffee.com/rizasabuncu" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

* [ ] Timestamp selection


63 changes: 59 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <url> [flags]\n")
flag.PrintDefaults()
os.Exit(0)
}

var url string
if flag.NArg() > 0 {
url = flag.Arg(0)
} else {
Expand All @@ -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)
}
Expand Down