简体   繁体   中英

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 :)

read = file.readlines.map(&:chomp).sample
client.update(read).text

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM