-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix makefile + .gitignore bins + fourchan graph mostly complete
missing add depth field and other formatting of messages
- Loading branch information
Showing
9 changed files
with
327 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
GO_FILES = $(shell find . -type f -name '*.go') | ||
GO_FILES := $(shell find . -type f -name '*.go') | ||
BINARIES := twitterview hackerview redditview fourchanview | ||
|
||
.PHONY: all install clean test | ||
|
||
all: twitterview hackerview redditview | ||
all: $(BINARIES) | ||
|
||
hackerview: | ||
redditview: | ||
twitterview: $(GO_FILES) | ||
$(BINARIES): $(GO_FILES) | ||
go build -v -ldflags="-s -w" ./cmd/$@ | ||
ls -lh $@ | ||
|
||
install: hackerview twitterview redditview | ||
mv hackerview $(HOME)/go/bin/ | ||
mv twitterview $(HOME)/go/bin/ | ||
mv redditview $(HOME)/go/bin/ | ||
install: $(BINARIES); | ||
mv $(BINARIES) $(HOME)/go/bin/ | ||
|
||
clean: ; go clean -x ./... | ||
test: ; go test -vet=all -v -race ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/azimut/cli-view/internal/fourchan" | ||
"github.com/fatih/color" | ||
) | ||
|
||
type options struct { | ||
timeout time.Duration | ||
useColors bool | ||
userAgent string | ||
width int | ||
} | ||
|
||
var opts options | ||
|
||
func init() { | ||
flag.BoolVar(&opts.useColors, "C", true, "use colors") | ||
flag.IntVar(&opts.width, "w", 80, "fixed with") // TODO: use opts.width | ||
} | ||
|
||
func usage() { | ||
fmt.Printf("Usage: %s [OPTIONS] URL ...\n", os.Args[0]) | ||
flag.PrintDefaults() | ||
} | ||
|
||
func run(args []string, stdout io.Writer) error { | ||
flag.Parse() | ||
flag.Usage = usage | ||
color.NoColor = !opts.useColors | ||
if flag.NArg() != 1 { | ||
flag.Usage() | ||
return errors.New("missing URL argument") | ||
} | ||
url := flag.Args()[0] | ||
thread, err := fourchan.Fetch(url) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(thread) | ||
return nil | ||
} | ||
|
||
func main() { | ||
err := run(os.Args, os.Stdout) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package fourchan | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/moshee/go-4chan-api/api" | ||
) | ||
|
||
var testOp = &api.Post{ | ||
Comment: "OP plaintext", | ||
Id: 92834152, | ||
Subject: "my op subject", | ||
Time: time.Now(), | ||
} | ||
|
||
var testThread = &api.Thread{ | ||
Board: "g", | ||
OP: testOp, | ||
Posts: []*api.Post{ | ||
testOp, | ||
{ | ||
Subject: "same thread SINGLE reply (to OP) and a link", | ||
Comment: `<a href="#p92834152" class="quotelink">>>92834152</a><br>Yes https://jetbra.in/s`, | ||
Id: 92835905, | ||
Time: time.Now(), | ||
// File: &api.File{ | ||
// Ext: ".jpg", | ||
// Name: "1653870571633", | ||
// }, | ||
}, | ||
// PLACEHOLDER FOR ONE THAT has an empty comment, AND only has an attachment | ||
// { | ||
// Subject: "same thread SINGLE reply and a link", | ||
// Comment: ``, | ||
// Id: 92835905, | ||
// Time: time.Now(), | ||
// File: &api.File{ | ||
// Ext: ".jpg", | ||
// Name: "1653870571633", | ||
// }, | ||
// }, | ||
{ | ||
Subject: "same thread SINGLE reply, and non linked reply to OP", | ||
Comment: `No YOU<br><br><a href="#p92835905" class="quotelink">>>92835905</a><br>Yes https://jetbra.in/s`, | ||
Id: 92835911, | ||
Time: time.Now(), | ||
}, | ||
{ | ||
Subject: "plaintext comment", | ||
Comment: "hey whats up", | ||
Id: 92838633, | ||
Time: time.Now(), | ||
}, | ||
{ | ||
Subject: "same thread 2 replies", | ||
Comment: `<a href="#p92834152" class="quotelink">>>92834152</a><br>paying for free software?<br><br><a href="#p92835905" class="quotelink">>>92835905</a><br>based`, | ||
Id: 92838617, | ||
Time: time.Now(), | ||
}, | ||
{ | ||
Subject: "same thread 2 replies, with the same message ", | ||
Comment: `<a href="#p92834152" class="quotelink">>>92834152</a><br><a href="#p92835905" class="quotelink">>>92835905</a><br>based`, | ||
Id: 92838699, | ||
Time: time.Now(), | ||
}, | ||
{ | ||
Subject: "same thread 3 replies", | ||
Comment: `<a href="#p92834152" class="quotelink">>>92834152</a><br>paying for free software?<br><br><a href="#p92835905" class="quotelink">>>92835905</a><br>based<br><br><a href="#p92838617" class="quotelink">>>92838617</a><br>paying for free software?<br><br>`, | ||
Id: 92838617, | ||
Time: time.Now(), | ||
}, | ||
}, | ||
} | ||
|
||
func TestOp(t *testing.T) { | ||
thread := toThread(testThread) | ||
got := thread.op.id | ||
expected := 92834152 | ||
if got != expected { | ||
t.Errorf("got %d expected %d", got, expected) | ||
} | ||
} | ||
|
||
// func TestExplodePost(t *testing.T) { | ||
// post := Post{ | ||
// comment: `<a href="#p92834152" class="quotelink">>>92834152</a><br>Yes https://jetbra.in/s`, | ||
// created: time.Now(), | ||
// } | ||
// posts := explodePost(post) | ||
// fmt.Println(posts) | ||
// } | ||
|
||
func TestNParents(t *testing.T) { | ||
thread := toThread(testThread) | ||
got := len(thread.posts) | ||
expected := 6 | ||
if got != expected { | ||
t.Errorf("got %d expected %d", got, expected) | ||
} | ||
} | ||
|
||
func TestGetParentId(t *testing.T) { | ||
findings := map[string]int{ | ||
`<a href="/g/thread/92865685#p92866880" class="quotelink">>>92866880</a> <br>`: 0, | ||
`<a href="#p92834152" class="quotelink">>>92834152</a><br>`: 92834152, | ||
`<a href="#p92834152" class="quotelink">>>92834152</a> <br>`: 92834152, | ||
``: 0, | ||
} | ||
for finding, expected := range findings { | ||
got := getParentId(finding) | ||
if expected != got { | ||
t.Errorf("got %d expected %d", got, expected) | ||
} | ||
} | ||
} |
Oops, something went wrong.