post_to_twitter: handle 226 errors

Twitter rejects certain tweets with particular content that it
thinks is spam, and since it doesn't change over multiple
submissions, just skip them.
This commit is contained in:
joshua stein 2016-07-19 20:06:57 -05:00
parent c602b01965
commit 64a2411bea

View file

@ -63,8 +63,13 @@ Time.now - 1.days).order(:id).each_with_index do |s,x|
{ "status" => status })
begin
if res["id_str"].match(/\d+/)
if res["id_str"].to_s.match(/\d+/)
s.update_column("twitter_id", res["id_str"])
elsif res["errors"].select{|e| e["code"] == 226 }.any?
# twitter is rejecting the content of this message, skip it
s.update_column("twitter_id", 0)
puts "skipping: failed posting story #{s.id} (#{status.inspect}): " +
"#{res.inspect}\n"
else
raise
end