-
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.
- Loading branch information
Showing
7 changed files
with
144 additions
and
36 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "task", | ||
srcs = [ | ||
"collector.go", | ||
"task.go", | ||
], | ||
importpath = "github.com/its-my-data/doubak/task", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//proto", | ||
"@com_github_gocolly_colly_v2//:colly", | ||
], | ||
) |
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,42 @@ | ||
package task | ||
|
||
import ( | ||
"flag" | ||
"github.com/gocolly/colly/v2" | ||
p "github.com/its-my-data/doubak/proto" | ||
"log" | ||
) | ||
|
||
// Collector contains the information used by the collector. | ||
type Collector struct { | ||
user string | ||
categories []string | ||
} | ||
|
||
// NewCollector returns a new collector task and initialise it. | ||
func NewCollector(categories []string) *Collector { | ||
return &Collector{ | ||
user: flag.Lookup(p.Flag_categories.String()).Value.(flag.Getter).Get().(string), | ||
categories: categories, | ||
} | ||
} | ||
|
||
// Precheck validates the flags. | ||
func (task *Collector) Precheck() error { | ||
// TODO: check user existance, etc. | ||
return nil | ||
} | ||
|
||
// Execute starts the collection. | ||
func (task *Collector) Execute() error { | ||
// TODO: update the implementation. | ||
c := colly.NewCollector() | ||
c.OnHTML("a[href]", func(e *colly.HTMLElement) { | ||
log.Println("Found ULR: ", e.Attr("href")) | ||
}) | ||
c.OnRequest(func(r *colly.Request) { | ||
log.Println("Visiting", r.URL) | ||
}) | ||
c.Visit("http://douban.com/") | ||
return nil | ||
} |
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,10 @@ | ||
package task | ||
|
||
// BaseInterface defines the interface of each type of task. | ||
type BaseInterface interface { | ||
// Checking flag combinations, validities, etc. | ||
Precheck() error | ||
|
||
// Execute the task. | ||
Execute() error | ||
} |