Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Add max tweets number to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-nicola committed Mar 23, 2021
1 parent 48bf1a7 commit e178d3b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type TweetsFetchingConfiguration struct {
SleepingTime time.Duration `yaml:"sleeping_time"`
OmitTweetsPublishedBeforeEnabled bool `yaml:"omit_tweets_published_before_enabled"`
OmitTweetsPublishedBefore time.Time `yaml:"omit_tweets_published_before"`
MaxTweetsNumber int `yaml:"max_tweets_number"`
NewWebResourceRoutingKey string `yaml:"new_web_resource_routing_key"`
NewTweetRoutingKey string `yaml:"new_tweet_routing_key"`
NewWebArticleRoutingKey string `yaml:"new_web_article_routing_key"`
Expand Down
1 change: 1 addition & 0 deletions pkg/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestFromYAMLFile(t *testing.T) {
SleepingTime: 5 * time.Minute,
OmitTweetsPublishedBeforeEnabled: true,
OmitTweetsPublishedBefore: omitPublishedBefore,
MaxTweetsNumber: 3200,
NewWebResourceRoutingKey: "",
NewTweetRoutingKey: "new_tweet",
NewWebArticleRoutingKey: "new_web_article",
Expand Down
6 changes: 2 additions & 4 deletions pkg/tasks/tweetsfetching/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type Worker struct {
scraper *twitterscraper.Scraper
}

const maxTweetsNumber = 50

func NewWorker(
config configuration.Configuration,
db *gorm.DB,
Expand Down Expand Up @@ -72,9 +70,9 @@ func (w *Worker) processTwitterSource(logger zerolog.Logger, ts *models.TwitterS

switch ts.Type {
case models.UserTwitterSource:
ch = w.scraper.GetTweets(context.Background(), ts.Value, maxTweetsNumber)
ch = w.scraper.GetTweets(context.Background(), ts.Value, w.config.TweetsFetching.MaxTweetsNumber)
case models.SearchTwitterSource:
ch = w.scraper.SearchTweets(context.Background(), ts.Value, maxTweetsNumber)
ch = w.scraper.SearchTweets(context.Background(), ts.Value, w.config.TweetsFetching.MaxTweetsNumber)
default:
return fmt.Errorf("unexpected twitter-source type %#v", ts.Type)
}
Expand Down
1 change: 1 addition & 0 deletions sample-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tweets_fetching:
sleeping_time: 5m
omit_tweets_published_before_enabled: true
omit_tweets_published_before: '2020-12-01T00:00:00Z'
max_tweets_number: 3200
new_web_resource_routing_key: ''
new_tweet_routing_key: 'new_tweet'
new_web_article_routing_key: 'new_web_article'
Expand Down

0 comments on commit e178d3b

Please sign in to comment.