ruby 来自文本文件的推文行
ruby tweet line from text file
我的代码不会每隔一段时间从文件中发送推文,它只会在终端中打印,但不会在推特上打印。我也试图循环它,以便一旦完成 file.length 它的重复。感谢您的帮助。
require 'Twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
config.access_token = "..."
config.access_token_secret = "..."
end
blog_post = []
tweet_img = []
def post
File.open("tweets.txt") do rand |line|
line.each do |item|
tweets = item.chomp.split("\n")
#while client.update("#{}")
puts tweets
sleep(30)
#end
#puts blog_post.to_s, "\n\n"
end
end
end
puts client.update("#{post}").text
你给 Twitter 的来电:
client.update("#{post}").text
在你的循环之外,所以它只被调用一次。如果你想要每一行,它应该是:
def post
File.open("tweets.txt") do rand |line|
line.each do |item|
tweets = item.chomp.split("\n")
puts tweets
client.update("#{tweets}").text
sleep(30)
end
end
end
require 'Twitter'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
client = Twitter::REST::Client.new do |config|
config.consumer_key = "xxxx"
config.consumer_secret = "xxxx"
config.access_token = "xxxx"
config.access_token_secret = "xxxx"
end
file = File.open("tweets.txt")
ary = []
i = 0
file.each_line do |line|
ary[i] = line.chomp
i += 1
end
file.close
j = 0
i.times do
client.update("#{ary[j]}")
j += 1
sleep 10
end
我的代码不会每隔一段时间从文件中发送推文,它只会在终端中打印,但不会在推特上打印。我也试图循环它,以便一旦完成 file.length 它的重复。感谢您的帮助。
require 'Twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
config.access_token = "..."
config.access_token_secret = "..."
end
blog_post = []
tweet_img = []
def post
File.open("tweets.txt") do rand |line|
line.each do |item|
tweets = item.chomp.split("\n")
#while client.update("#{}")
puts tweets
sleep(30)
#end
#puts blog_post.to_s, "\n\n"
end
end
end
puts client.update("#{post}").text
你给 Twitter 的来电:
client.update("#{post}").text
在你的循环之外,所以它只被调用一次。如果你想要每一行,它应该是:
def post
File.open("tweets.txt") do rand |line|
line.each do |item|
tweets = item.chomp.split("\n")
puts tweets
client.update("#{tweets}").text
sleep(30)
end
end
end
require 'Twitter'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
client = Twitter::REST::Client.new do |config|
config.consumer_key = "xxxx"
config.consumer_secret = "xxxx"
config.access_token = "xxxx"
config.access_token_secret = "xxxx"
end
file = File.open("tweets.txt")
ary = []
i = 0
file.each_line do |line|
ary[i] = line.chomp
i += 1
end
file.close
j = 0
i.times do
client.update("#{ary[j]}")
j += 1
sleep 10
end