argos/main.go
main.goRaw
1package main
2
3import (
4 "bufio"
5 "encoding/json"
6 "fmt"
7 "io/ioutil"
8 "os"
9 "strings"
10
11 "github.com/dghubble/go-twitter/twitter"
12 "github.com/dghubble/oauth1"
13)
14
15type Config struct {
16 Consumer_key string `json:"consumer_key"`
17 Consumer_secret string `json:"consumer_secret"`
18 Access_token_key string `json:"access_token_key"`
19 Access_token_secret string `json:"access_token_secret"`
20}
21
22func readConfigTokensAndConnect() (client *twitter.Client) {
23 var config Config
24 file, e := ioutil.ReadFile("twitterConfig.json")
25 if e != nil {
26 fmt.Println("error:", e)
27 }
28 content := string(file)
29 json.Unmarshal([]byte(content), &config)
30 //fmt.Printf("%+v\n", config)
31 fmt.Println("twitterConfig.json read comlete")
32
33 fmt.Print("connecting to twitter api --> ")
34 configu := oauth1.NewConfig(config.Consumer_key, config.Consumer_secret)
35 token := oauth1.NewToken(config.Access_token_key, config.Access_token_secret)
36 httpClient := configu.Client(oauth1.NoContext, token)
37 // twitter client
38 client = twitter.NewClient(httpClient)
39
40 fmt.Println("connection successfull")
41
42 return client
43}
44
45func analyzeUsername(client *twitter.Client) {
46 newcommand := bufio.NewReader(os.Stdin)
47 fmt.Print("enter username: @")
48 username, _ := newcommand.ReadString('\n')
49 username = strings.TrimSpace(username)
50 fmt.Println("user selected: " + username)
51
52 // Home Timeline
53 user, resp, err := client.Users.Show(&twitter.UserShowParams{
54 ScreenName: username,
55 })
56 if err != nil {
57 fmt.Println("error:", err)
58 }
59 fmt.Println("%+v\n", user)
60 fmt.Println(resp)
61}
62
63func main() {
64 fmt.Println("---------------")
65 fmt.Println("Tweets and favs delete script. Starting.")
66 fmt.Println("Reading twitterConfig.json file")
67 client := readConfigTokensAndConnect()
68
69 fmt.Println("---------------")
70 newcommand := bufio.NewReader(os.Stdin)
71 fmt.Print("Please select command number:")
72 options := `
73 1 - Analyze username
74 0 - Exit script
75option to select: `
76 for {
77 fmt.Print(options)
78 option, _ := newcommand.ReadString('\n')
79 option = strings.TrimSpace(option)
80
81 switch option {
82 case "1":
83 fmt.Println("selected 1 - Analyze username")
84 analyzeUsername(client)
85 break
86 case "2":
87 fmt.Println("selected 2 - Delete all Favs")
88 break
89 case "3":
90 fmt.Println("selected 3 - Delete all Tweets and Favs")
91 break
92 case "0":
93 fmt.Println("selected 0 - exit script")
94 os.Exit(3)
95 break
96 default:
97 fmt.Println("Invalid option")
98 break
99 }
100 }
101}