Skip to content

Commit

Permalink
added missing cfg.TelegramScraper check
Browse files Browse the repository at this point in the history
  • Loading branch information
jdutchak committed Aug 1, 2024
1 parent 36cf87d commit e03d9fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
30 changes: 23 additions & 7 deletions pkg/scrapers/twitter/tweets.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@ func ScrapeTweetsForSentiment(query string, count int, model string) (string, st

// Perform the search with the specified query and count
for tweetResult := range scraper.SearchTweets(context.Background(), query, count) {
tweet := TweetResult{
Tweet: &tweetResult.Tweet,
Error: tweetResult.Error,
var tweet TweetResult
if tweetResult.Error != nil {
tweet = TweetResult{
Tweet: nil,
Error: tweetResult.Error,
}
} else {
tweet = TweetResult{
Tweet: tweetResult.Tweet,

Check failure on line 96 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / test

cannot use tweetResult.Tweet (variable of type twitterscraper.Tweet) as *twitterscraper.Tweet value in struct literal

Check failure on line 96 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / test

cannot use tweetResult.Tweet (variable of type twitterscraper.Tweet) as *twitterscraper.Tweet value in struct literal

Check failure on line 96 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / build-pr

cannot use tweetResult.Tweet (variable of type twitterscraper.Tweet) as *twitterscraper.Tweet value in struct literal
Error: nil,
}
}
tweets = append(tweets, &tweet)
}
Expand All @@ -96,7 +104,7 @@ func ScrapeTweetsForSentiment(query string, count int, model string) (string, st
twitterScraperTweets := make([]*twitterscraper.TweetResult, len(tweets))
for i, tweet := range tweets {
twitterScraperTweets[i] = &twitterscraper.TweetResult{
Tweet: *tweet.Tweet,
Tweet: tweet.Tweet,

Check failure on line 107 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / test

cannot use tweet.Tweet (variable of type *twitterscraper.Tweet) as twitterscraper.Tweet value in struct literal

Check failure on line 107 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / test

cannot use tweet.Tweet (variable of type *twitterscraper.Tweet) as twitterscraper.Tweet value in struct literal

Check failure on line 107 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / build-pr

cannot use tweet.Tweet (variable of type *twitterscraper.Tweet) as twitterscraper.Tweet value in struct literal
Error: tweet.Error,
}
}
Expand Down Expand Up @@ -129,9 +137,17 @@ func ScrapeTweetsByQuery(query string, count int) ([]*TweetResult, error) {

// Perform the search with the specified query and count
for tweetResult := range scraper.SearchTweets(context.Background(), query, count) {
tweet := TweetResult{
Tweet: &tweetResult.Tweet,
Error: tweetResult.Error,
var tweet TweetResult
if tweetResult.Error != nil {
tweet = TweetResult{
Tweet: nil,
Error: tweetResult.Error,
}
} else {
tweet = TweetResult{
Tweet: tweetResult.Tweet,

Check failure on line 148 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / test

cannot use tweetResult.Tweet (variable of type twitterscraper.Tweet) as *twitterscraper.Tweet value in struct literal

Check failure on line 148 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / test

cannot use tweetResult.Tweet (variable of type twitterscraper.Tweet) as *twitterscraper.Tweet value in struct literal

Check failure on line 148 in pkg/scrapers/twitter/tweets.go

View workflow job for this annotation

GitHub Actions / build-pr

cannot use tweetResult.Tweet (variable of type twitterscraper.Tweet) as *twitterscraper.Tweet value in struct literal
Error: nil,
}
}
tweets = append(tweets, &tweet)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestScrapeTweetsWithSentimentByQuery(t *testing.T) {
twitterScraperTweets := make([]*twitterscraper.TweetResult, len(deserializedTweets))
for i, tweet := range deserializedTweets {
twitterScraperTweets[i] = &twitterscraper.TweetResult{
Tweet: *tweet,
Tweet: tweet,
Error: nil,
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/workers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (a *Worker) HandleWork(ctx actor.Context, m *messages.Work, node *masa.Orac
return
}
cfg := config.GetInstance()
if cfg.TwitterScraper || cfg.DiscordScraper || cfg.TwitterScraper || cfg.WebScraper {
if cfg.TelegramScraper || cfg.DiscordScraper || cfg.TwitterScraper || cfg.WebScraper {
ctx.Respond(&messages.Response{RequestId: workData["request_id"], Value: string(jsn)})
}
for _, pid := range getPeers(node) {
Expand Down
6 changes: 2 additions & 4 deletions pkg/workers/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ func SendWork(node *masa.OracleNode, m *pubsub2.Message) {
for _, p := range peers {
for _, addr := range p.Multiaddrs {
ipAddr, _ := addr.ValueForProtocol(multiaddr.P_IP4)

// @TODO add a limiter if a node 429s add them to a list and don't call them for n number of minutes
// re: Add feature timeout timestamps to nodeData and helper methods to do timeout checks

if (p.PeerId.String() != node.Host.ID().String()) &&
p.IsStaked &&
node.NodeTracker.GetNodeData(p.PeerId.String()).CanDoWork(pubsub.WorkerCategory(message.Type)) {
Expand Down Expand Up @@ -321,6 +317,8 @@ func SendWork(node *masa.OracleNode, m *pubsub2.Message) {
}
responseCollector <- msg
n++
// @TODO add a limiter if a node 429s add them to a list and don't call them for n number of minutes
// re: Add feature timeout timestamps to nodeData and helper methods to do timeout checks
// @note need to handle if we have thousands of workers this could take a very long time to complete
// here we cap n
if n == len(peers) || n == 100 {
Expand Down

0 comments on commit e03d9fc

Please sign in to comment.