简体   繁体   English

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

[英]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.

相关问题 来自文本文件的ruby tweet行 - ruby tweet line from text file Ruby Twitter,检索完整的推文文本 - Ruby Twitter, Retrieving Full Tweet Text 如何修复从Twitter URL中提取推文ID的正则表达式? - How can I fix this regex which extracts a tweet id from a Twitter URL? Rails4 如何使用来自带有 sferik / twitter gem 的网站的图片发推文? - Rails4 How can I tweet with a picture from a website with sferik / twitter gem? 使用twitter gem,如何从Twitter :: REST转发Twitter :: Tweet:Tweets.retweet? - With the twitter gem, how do I retweet a Twitter::Tweet from Twitter::REST:Tweets.retweet? 如何从twitter.com捕获响应? (红宝石+ Twitter宝石) - how can I capture response from twitter.com? ( ruby + twitter gem) 如何从twitter.com捕获** http响应**? (红宝石+ Twitter宝石) - how can I capture **http response** from twitter.com? ( ruby + twitter gem) 如何从 Twitter Gem Twitter 对象返回推文的完整 JSON - How to return full JSON of Tweet from Twitter Gem Twitter Object ruby / rails ruby​​ / rails如何使用Twitter API从(用户的)Twitter LIST获取所有推文? - ruby/rails ruby/rails How can I get all the tweets from Twitter LIST (of users) using the Twitter API? 使用Twitter Ruby Gem显示推文 - Display tweet using Twitter Ruby Gem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM