-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
1ea5f38
commit 5719332
Showing
7 changed files
with
316 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package config | ||
|
||
// GetScraperEndpoint get the Scraper Endpoint | ||
func GetScraperEndpoint() string { | ||
return getenv("SCRAPER_ENDPOINT", "http://127.0.0.1:3000") | ||
} |
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 |
---|---|---|
|
@@ -17,4 +17,5 @@ type Favorite struct { | |
// Favorite item type | ||
const ( | ||
ItemTypeMarket = "market" | ||
ItemTypeTimeline = "timeline" | ||
) |
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,48 @@ | ||
package scraper | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Covertness/ally/pkg/config" | ||
"github.com/imroc/req" | ||
) | ||
|
||
var ins *Scraper | ||
|
||
// Init create the FTX connection | ||
func Init() *Scraper { | ||
ins = New(config.GetScraperEndpoint()) | ||
return ins | ||
} | ||
|
||
// GetInstance get the Scraper instance | ||
func GetInstance() *Scraper { | ||
return ins | ||
} | ||
|
||
// New create a new instance | ||
func New(endpoint string) *Scraper { | ||
return &Scraper{ | ||
Endpoint: endpoint, | ||
} | ||
} | ||
|
||
func (s *Scraper) get(path string) (*req.Resp, error) { | ||
url := fmt.Sprintf("%s%s", | ||
s.Endpoint, path, | ||
) | ||
|
||
r, err := req.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if r.Response().StatusCode != 200 { | ||
return nil, fmt.Errorf("http code %d", r.Response().StatusCode) | ||
} | ||
return r, nil | ||
} | ||
|
||
// Scraper instance connect to the internal service scraper | ||
type Scraper struct { | ||
Endpoint string | ||
} |
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,46 @@ | ||
package scraper | ||
|
||
import "fmt" | ||
|
||
// WeiBoSearch search keyword on WeiBo | ||
func(s *Scraper) WeiBoSearch(keyword string) ([]*WeiBoSearchItem, error) { | ||
path := fmt.Sprintf("/weibo/search/%s", keyword) | ||
r, err := s.get(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var resp []*WeiBoSearchItem | ||
err = r.ToJSON(&resp) | ||
|
||
return resp, err | ||
} | ||
|
||
// WeiBoSearchItem the item of search result | ||
type WeiBoSearchItem struct { | ||
ID string | ||
Name string | ||
} | ||
|
||
// WeiBoTimeline get news of a specified user on WeiBo | ||
func(s *Scraper) WeiBoTimeline(userID string) ([]*WeiBoTimelineItem, error) { | ||
path := fmt.Sprintf("/weibo/%s", userID) | ||
r, err := s.get(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var resp []*WeiBoTimelineItem | ||
err = r.ToJSON(&resp) | ||
|
||
return resp, err | ||
} | ||
|
||
// WeiBoTimelineItem the item of timeline | ||
type WeiBoTimelineItem struct { | ||
Name string | ||
Text string | ||
Timestamp string | ||
ID string | ||
Link string | ||
} |
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,24 @@ | ||
package timeline | ||
|
||
import "time" | ||
|
||
// Timeline timeline item | ||
type Timeline struct { | ||
ID uint `gorm:"primary_key"` | ||
CreatedAt time.Time `gorm:"not null"` | ||
UpdatedAt time.Time `gorm:"not null"` | ||
|
||
Provider string `gorm:"unique_index:uix_timelines_provider_type_custom_id;not null"` | ||
Type string `gorm:"unique_index:uix_timelines_provider_type_custom_id;not null"` | ||
CustomID string `gorm:"unique_index:uix_timelines_provider_type_custom_id;not null"` | ||
} | ||
|
||
// Timeline provider | ||
const ( | ||
ProviderWeiBo = "weibo" | ||
) | ||
|
||
// Timeline type | ||
const ( | ||
TypeUser = "user" | ||
) |
Oops, something went wrong.