Skip to content

Commit

Permalink
Add url option
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Aug 9, 2022
1 parent 01cd395 commit 249f8e2
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 @@ -28,6 +28,7 @@ Flags:
--to string find tweets sent in reply to a certain user
--top find top tweets
--until string find tweets until a certain day (e.g. 2020-09-06)
--url string find tweets containing a certain url (e.g. www.example.com)
--user-agent string set custom user-agent
-v, --version version for get-old-tweets
```
Expand Down
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
lang string
filter string
geocode string
url string
top bool
userAgent string
)
Expand All @@ -52,6 +53,7 @@ var rootCmd = &cobra.Command{
Lang: lang,
Filter: filter,
Geocode: geocode,
Url: url,
}
if q.IsEmpty() {
fmt.Fprintln(os.Stderr, "Error: One or more queries are required")
Expand Down Expand Up @@ -100,6 +102,7 @@ func init() {
rootCmd.Flags().StringVarP(&to, "to", "", "", "find tweets sent in reply to a certain user")
rootCmd.Flags().BoolVarP(&top, "top", "", false, "find top tweets")
rootCmd.Flags().StringVarP(&until, "until", "", "", "find tweets until a certain day (e.g. 2020-09-06)")
rootCmd.Flags().StringVarP(&url, "url", "", "", "find tweets containing a certain url (e.g. www.example.com)")
rootCmd.Flags().StringVarP(&userAgent, "user-agent", "", "", "set custom user-agent")
rootCmd.MarkFlagRequired("out")
}
Expand Down
5 changes: 5 additions & 0 deletions twitter/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Query struct {
Lang string
Filter string
Geocode string
Url string
}

func (q *Query) Encode() string {
Expand Down Expand Up @@ -64,6 +65,10 @@ func (q *Query) Encode() string {
ss = append(ss, "geocode:"+q.Geocode)
}

if len(q.Url) != 0 {
ss = append(ss, "url:"+q.Url)
}

return strings.Join(ss[:], " ")
}

Expand Down
10 changes: 9 additions & 1 deletion twitter/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestEncode(t *testing.T) {
lang string
filter string
geocode string
url string
expected string
}{
"none": {
Expand All @@ -42,6 +43,7 @@ func TestEncode(t *testing.T) {
lang: "",
filter: "",
geocode: "",
url: "",
expected: "",
},
"all": {
Expand All @@ -53,7 +55,8 @@ func TestEncode(t *testing.T) {
lang: "ja",
filter: "verified",
geocode: "35.6851508,139.7526768,0.1km",
expected: "foo bar since:2020-09-06 until:2020-09-07 from:foo to:bar lang:ja filter:verified 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 geocode:35.6851508,139.7526768,0.1km url:www.example.com",
},
}

Expand All @@ -68,6 +71,7 @@ func TestEncode(t *testing.T) {
Lang: e.lang,
Filter: e.filter,
Geocode: e.geocode,
Url: e.url,
}

actual := q.Encode()
Expand All @@ -90,6 +94,7 @@ func TestIsEmpty(t *testing.T) {
lang string
filter string
geocode string
url string
expected bool
}{
"none": {
Expand All @@ -101,6 +106,7 @@ func TestIsEmpty(t *testing.T) {
lang: "",
filter: "",
geocode: "",
url: "",
expected: true,
},
"all": {
Expand All @@ -112,6 +118,7 @@ func TestIsEmpty(t *testing.T) {
lang: "ja",
filter: "verified",
geocode: "35.6851508,139.7526768,0.1km",
url: "www.example.com",
expected: false,
},
}
Expand All @@ -127,6 +134,7 @@ func TestIsEmpty(t *testing.T) {
Lang: e.lang,
Filter: e.filter,
Geocode: e.geocode,
Url: e.url,
}

actual := q.IsEmpty()
Expand Down

0 comments on commit 249f8e2

Please sign in to comment.