【发布时间】:2017-08-13 13:59:25
【问题描述】:
我制作了一个很棒的 Twitter 机器人,可以使用本教程进行 CrossFit 锻炼: http://www.katelyndinkgrave.com/ruby/2016/01/31/civ-game-generator-twitterbot.html
但是,不断重复发布;每次运行脚本时如何让它只发布一次?
模型是:
class Wod < ApplicationRecord
def initialize
@wod_type = WOD_TYPES.sample
@time = time
@rounds = rounds
...
end
I've omitted code not relevant to the post...
def print_wod
if @wod_type == "EMOM"
"#{@wod_type} #{@time}:\n\n" +
"#{@sets}\n\n" +
"#{bbweight}" +
"#{kbweight}" +
"#{height}" +
"#{slamweight}" +
"#{wallweight}" +
"\nFind more at: https://GymBull.com\n"
else
"#{@rounds}#{@wod_type}#{@time}:\n\n" +
"#{@sets}\n\n" +
"#{bbweight}" +
"#{kbweight}" +
"#{height}" +
"#{slamweight}" +
"#{wallweight}" +
"\nFind more at: https://GymBull.com\n"
end
end
end
机器人脚本使用 (rails r app/models/bot.rb) 运行:
require 'twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["CONSUMER_KEY"]
config.consumer_secret = ENV["CONSUMER_SECRET"]
config.access_token = ENV["ACCESS_TOKEN"]
config.access_token_secret = ENV["ACCESS_TOKEN_SECRET"]
end
wod = Wod.new
client.update(wod.print_wod)
提前谢谢你
【问题讨论】:
标签: ruby-on-rails ruby post twitter bots