我如何使用文本文件中的 ruby 和 twitter 推文
how can i use ruby and twitter tweet from text file
我正在尝试从文本文件发推文,但没有得到额外的符号。
我的推文看起来像:
["This is a sample of my tweet on twitter"\n] << 它包括符号和额外的 "n".
我想得到的是:
这是我希望我的推文看起来像的示例。 << 没有多余的符号。
我的代码:
def tweet
file = File.open("tweets_from.txt","r")
read = file.readlines.sample(1)
client.update("#{read}").text
end
tweet
提前感谢您的帮助:)
read = file.readlines.map(&:chomp).sample
client.update(read).text
改一下就够了
read = file.readlines.sample(1)
对此:
read = file.readlines.sample.chomp
有关此方法(以及许多其他方法!)的更多信息,请点击此处:Ruby String docs
我正在尝试从文本文件发推文,但没有得到额外的符号。
我的推文看起来像: ["This is a sample of my tweet on twitter"\n] << 它包括符号和额外的 "n".
我想得到的是: 这是我希望我的推文看起来像的示例。 << 没有多余的符号。
我的代码:
def tweet
file = File.open("tweets_from.txt","r")
read = file.readlines.sample(1)
client.update("#{read}").text
end
tweet
提前感谢您的帮助:)
read = file.readlines.map(&:chomp).sample
client.update(read).text
改一下就够了
read = file.readlines.sample(1)
对此:
read = file.readlines.sample.chomp
有关此方法(以及许多其他方法!)的更多信息,请点击此处:Ruby String docs