You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0 KiB

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