arnaucube
arnaucube/argosPublic Self-hosted repository
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		c.Purple("maybe twitter has blocked the account, CTRL+C, wait 15 minutes and try again")
21	}
22	fmt.Print("tweet posted: ")
23	c.Green(tweet.Text)
24}
25func tweetRandom(client *twitter.Client, nTweets int, screenName string) {
26	fmt.Println("Starting to publish " + strconv.Itoa(nTweets) + " tweets")
27
28	tweets := getTweets(client, screenName, 1)
29	fmt.Println("the selected account have more than " + strconv.Itoa(len(tweets)))
30
31	for i := 0; i < nTweets && i < len(tweets); i++ {
32		postTweet(client, tweets[i].Text)
33		waitTime(1)
34	}
35
36}
37
38func optionTweetRandom(client *twitter.Client) {
39	c.Red("ATTENTION!")
40	c.Purple("Publishing tweets from a bot can be banned by twitter!")
41	c.Cyan("Twitter can consider your account an spam account")
42	c.Red("Maybe you can publish the random tweets by hand")
43	c.Red("how many tweets to publish?")
44	newcommand := bufio.NewReader(os.Stdin)
45	answer, _ := newcommand.ReadString('\n')
46	answer = strings.TrimSpace(answer)
47	fmt.Print("Number of tweets to publish: ")
48	c.Purple(answer)
49	nTweets, err := strconv.Atoi(answer)
50	if err != nil {
51		fmt.Println("incorrect entry, need a positive number")
52	}
53
54	fmt.Print("entry @username of a twitter account, the content of the tweets will be from the account tweets: @")
55	newcommand = bufio.NewReader(os.Stdin)
56	screenName, _ := newcommand.ReadString('\n')
57	screenName = strings.TrimSpace(screenName)
58	fmt.Print("user to get tweets content: @")
59	c.Purple(screenName)
60
61	c.Red("Are you sure? [y/n]")
62	newcommand = bufio.NewReader(os.Stdin)
63	answer, _ = newcommand.ReadString('\n')
64	answer = strings.TrimSpace(answer)
65	switch answer {
66	case "y":
67		fmt.Println("ok, you are sure")
68		tweetRandom(client, nTweets, screenName)
69		break
70	default:
71		fmt.Println("Operation cancelled")
72		break
73	}
74}