[英]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".我的推文看起来像:[“这是我在 twitter 上的推文示例”\\n] << 它包括符号和额外的“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有关此方法的更多信息(以及许多其他方法!),请访问: Ruby String docs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.