argos/optionTweetRandom.go
optionTweetRandom.goRaw
1package main
2
3import (
4 "bufio"
5 "fmt"
6 "os"
7 "strconv"
8 "strings"
9
10 "github.com/dghubble/go-twitter/twitter"
11)
12
13func postTweet(client *twitter.Client, content string) {
14 tweet, httpResp, err := client.Statuses.Update(content, nil)
15 if err != nil {
16 fmt.Println(err)
17 }
18 if httpResp.Status != "200 OK" {
19 c.Red("error: " + httpResp.Status)
20 }
21 fmt.Print("tweet posted: ")
22 c.Green(tweet.Text)
23}
24func tweetRandom(client *twitter.Client, nTweets int, screenName string) {
25 fmt.Println("Starting to publish " + strconv.Itoa(nTweets) + " tweets")
26
27 tweets := getTweets(client, screenName, 1)
28 fmt.Println("the selected account have more than " + strconv.Itoa(len(tweets)))
29
30 for i := 0; i < nTweets && i < len(tweets); i++ {
31 postTweet(client, tweets[i].Text)
32 waitTime(1)
33 }
34
35}
36
37func optionTweetRandom(client *twitter.Client) {
38 c.Red("ATTENTION!")
39 c.Purple("Publishing tweets from a bot can be banned by twitter!")
40 c.Cyan("Twitter can consider your account an spam account")
41 c.Red("Maybe you can publish the random tweets by hand")
42 c.Red("how many tweets to publish?")
43 newcommand := bufio.NewReader(os.Stdin)
44 answer, _ := newcommand.ReadString('\n')
45 answer = strings.TrimSpace(answer)
46 fmt.Print("Number of tweets to publish: ")
47 c.Purple(answer)
48 nTweets, err := strconv.Atoi(answer)
49 if err != nil {
50 fmt.Println("incorrect entry, need a positive number")
51 }
52
53 fmt.Print("entry @username of a twitter account, the content of the tweets will be from the account tweets: @")
54 newcommand = bufio.NewReader(os.Stdin)
55 screenName, _ := newcommand.ReadString('\n')
56 screenName = strings.TrimSpace(screenName)
57 fmt.Print("user to get tweets content: @")
58 c.Purple(screenName)
59
60 c.Red("Are you sure? [y/n]")
61 newcommand = bufio.NewReader(os.Stdin)
62 answer, _ = newcommand.ReadString('\n')
63 answer = strings.TrimSpace(answer)
64 switch answer {
65 case "y":
66 fmt.Println("ok, you are sure")
67 tweetRandom(client, nTweets, screenName)
68 break
69 default:
70 fmt.Println("Operation cancelled")
71 break
72 }
73}