Skip to content

Commit

Permalink
Add include option
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Aug 10, 2022
1 parent 1a92c4f commit 73f17c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Flags:
--from string find tweets sent from a certain user
--geocode string find tweets sent from certain coordinates (e.g. 35.6851508,139.7526768,0.1km)
-h, --help help for get-old-tweets
--include strings include tweets by type of tweet (e.g. hashtags, retweets, replies)
--lang string find tweets by a certain language (e.g. en, es, fr)
-o, --out string output csv filename (required)
-q, --query string query text to search
Expand Down
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
to string
lang string
filters []string
includes []string
excludes []string
geocode string
url string
Expand All @@ -53,6 +54,7 @@ var rootCmd = &cobra.Command{
To: to,
Lang: lang,
Filters: filters,
Includes: includes,
Excludes: excludes,
Geocode: geocode,
Url: url,
Expand Down Expand Up @@ -98,6 +100,7 @@ func init() {
rootCmd.Flags().StringSliceVarP(&filters, "filter", "", []string{}, "find tweets by type of account or tweet (e.g. verified, follows, images, links)")
rootCmd.Flags().StringVarP(&from, "from", "", "", "find tweets sent from a certain user")
rootCmd.Flags().StringVarP(&geocode, "geocode", "", "", "find tweets sent from certain coordinates (e.g. 35.6851508,139.7526768,0.1km)")
rootCmd.Flags().StringSliceVarP(&includes, "include", "", []string{}, "include tweets by type of tweet (e.g. hashtags, retweets, replies)")
rootCmd.Flags().StringVarP(&lang, "lang", "", "", "find tweets by a certain language (e.g. en, es, fr)")
rootCmd.Flags().StringVarP(&out, "out", "o", "", "output csv filename (required)")
rootCmd.Flags().StringVarP(&text, "query", "q", "", "query text to search")
Expand Down
5 changes: 5 additions & 0 deletions twitter/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Query struct {
To string
Lang string
Filters []string
Includes []string
Excludes []string
Geocode string
Url string
Expand Down Expand Up @@ -62,6 +63,10 @@ func (q *Query) Encode() string {
ss = append(ss, "filter:"+filter)
}

for _, include := range q.Includes {
ss = append(ss, "include:"+include)
}

for _, exclude := range q.Excludes {
ss = append(ss, "exclude:"+exclude)
}
Expand Down
10 changes: 9 additions & 1 deletion twitter/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestEncode(t *testing.T) {
to string
lang string
filters []string
includes []string
excludes []string
geocode string
url string
Expand All @@ -43,6 +44,7 @@ func TestEncode(t *testing.T) {
to: "",
lang: "",
filters: []string{},
includes: []string{},
excludes: []string{},
geocode: "",
url: "",
Expand All @@ -56,10 +58,11 @@ func TestEncode(t *testing.T) {
to: "bar",
lang: "ja",
filters: []string{"verified", "links"},
includes: []string{"retweets", "nativeretweets"},
excludes: []string{"replies", "hashtags"},
geocode: "35.6851508,139.7526768,0.1km",
url: "www.example.com",
expected: "foo bar since:2020-09-06 until:2020-09-07 from:foo to:bar lang:ja filter:verified filter:links exclude:replies exclude:hashtags geocode:35.6851508,139.7526768,0.1km url:www.example.com",
expected: "foo bar since:2020-09-06 until:2020-09-07 from:foo to:bar lang:ja filter:verified filter:links include:retweets include:nativeretweets exclude:replies exclude:hashtags geocode:35.6851508,139.7526768,0.1km url:www.example.com",
},
}

Expand All @@ -73,6 +76,7 @@ func TestEncode(t *testing.T) {
To: e.to,
Lang: e.lang,
Filters: e.filters,
Includes: e.includes,
Excludes: e.excludes,
Geocode: e.geocode,
Url: e.url,
Expand All @@ -97,6 +101,7 @@ func TestIsEmpty(t *testing.T) {
to string
lang string
filters []string
includes []string
excludes []string
geocode string
url string
Expand All @@ -110,6 +115,7 @@ func TestIsEmpty(t *testing.T) {
to: "",
lang: "",
filters: []string{},
includes: []string{},
excludes: []string{},
geocode: "",
url: "",
Expand All @@ -123,6 +129,7 @@ func TestIsEmpty(t *testing.T) {
to: "bar",
lang: "ja",
filters: []string{"verified", "links"},
includes: []string{"retweets", "nativeretweets"},
excludes: []string{"replies", "hashtags"},
geocode: "35.6851508,139.7526768,0.1km",
url: "www.example.com",
Expand All @@ -140,6 +147,7 @@ func TestIsEmpty(t *testing.T) {
To: e.to,
Lang: e.lang,
Filters: e.filters,
Includes: e.includes,
Excludes: e.excludes,
Geocode: e.geocode,
Url: e.url,
Expand Down

0 comments on commit 73f17c5

Please sign in to comment.