Search code examples
rubyfiletwitterreadfiletweets

how can i use ruby and twitter tweet from text file


I'm trying to tweet from a text file without getting the extra symbols.

My tweets looks like: ["This is a sample of my tweet on twitter"\n] << it includes the symbols and the extra "n".

What I'm trying to get is: This is a sample of what I want my tweet to look like. << no extra symbols.

My code:

def tweet
  file = File.open("tweets_from.txt","r")
  read = file.readlines.sample(1)
  client.update("#{read}").text
end

tweet

Thanks in advance for your help :)


Solution

  • It is enough to just change

    read = file.readlines.sample(1)
    

    to this:

    read = file.readlines.sample.chomp
    

    More about this method (and many other!) here: Ruby String docs