簡體   English   中英

我如何使用文本文件中的 ruby​​ 和 twitter 推文

[英]how can i use ruby and twitter tweet from text file

我正在嘗試從文本文件中發送推文而沒有獲得額外的符號。

我的推文看起來像:[“這是我在 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM