@ -0,0 +1,50 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"bufio" |
|||
"fmt" |
|||
"os" |
|||
"strings" |
|||
|
|||
"github.com/dghubble/go-twitter/twitter" |
|||
) |
|||
|
|||
type Tweet struct { |
|||
text string `json: "Text"` |
|||
} |
|||
|
|||
var words = make(map[string]int) |
|||
|
|||
func mapWords(text string) { |
|||
s := strings.Split(text, " ") |
|||
|
|||
for _, v := range s { |
|||
if _, ok := words[v]; ok { |
|||
words[v] = words[v] + 1 |
|||
} else { |
|||
words[v] = 1 |
|||
} |
|||
} |
|||
} |
|||
|
|||
func analyzeUsername(client *twitter.Client) { |
|||
newcommand := bufio.NewReader(os.Stdin) |
|||
fmt.Print("enter username: @") |
|||
username, _ := newcommand.ReadString('\n') |
|||
username = strings.TrimSpace(username) |
|||
fmt.Println("user selected: " + username) |
|||
|
|||
fmt.Println("-----------------------") |
|||
|
|||
tweets, _, _ := client.Timelines.UserTimeline(&twitter.UserTimelineParams{ |
|||
ScreenName: username, |
|||
Count: 200, |
|||
}) |
|||
|
|||
for _, v := range tweets { |
|||
mapWords(v.Text) |
|||
} |
|||
|
|||
fmt.Println(len(words)) |
|||
_ = sortMap(words) |
|||
} |
@ -0,0 +1,40 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"fmt" |
|||
"io/ioutil" |
|||
|
|||
"github.com/dghubble/go-twitter/twitter" |
|||
"github.com/dghubble/oauth1" |
|||
) |
|||
|
|||
type Config struct { |
|||
Consumer_key string `json:"consumer_key"` |
|||
Consumer_secret string `json:"consumer_secret"` |
|||
Access_token_key string `json:"access_token_key"` |
|||
Access_token_secret string `json:"access_token_secret"` |
|||
} |
|||
|
|||
func readConfigTokensAndConnect() (client *twitter.Client) { |
|||
var config Config |
|||
file, e := ioutil.ReadFile("twitterConfig.json") |
|||
if e != nil { |
|||
fmt.Println("error:", e) |
|||
} |
|||
content := string(file) |
|||
json.Unmarshal([]byte(content), &config) |
|||
//fmt.Printf("%+v\n", config)
|
|||
fmt.Println("twitterConfig.json read comlete") |
|||
|
|||
fmt.Print("connecting to twitter api --> ") |
|||
configu := oauth1.NewConfig(config.Consumer_key, config.Consumer_secret) |
|||
token := oauth1.NewToken(config.Access_token_key, config.Access_token_secret) |
|||
httpClient := configu.Client(oauth1.NoContext, token) |
|||
// twitter client
|
|||
client = twitter.NewClient(httpClient) |
|||
|
|||
fmt.Println("connection successfull") |
|||
|
|||
return client |
|||
} |
@ -0,0 +1,26 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"sort" |
|||
) |
|||
|
|||
func sortMap(m map[string]int) map[int][]string { |
|||
n := map[int][]string{} |
|||
var a []int |
|||
for k, v := range m { |
|||
if v > 2 { |
|||
n[v] = append(n[v], k) |
|||
} |
|||
} |
|||
for k := range n { |
|||
a = append(a, k) |
|||
} |
|||
sort.Sort(sort.Reverse(sort.IntSlice(a))) |
|||
for _, k := range a { |
|||
for _, s := range n[k] { |
|||
fmt.Printf("%s, %d\n", s, k) |
|||
} |
|||
} |
|||
return n |
|||
} |