From 4c0aaf7c2e2a9109170ce691ef19498035654256 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Thu, 20 Mar 2014 11:41:33 -0500 Subject: [PATCH] fix story caching stuff once and for all --- extras/sponge.rb | 11 +++++------ extras/story_cacher.rb | 5 +++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/extras/sponge.rb b/extras/sponge.rb index 7318d5f..e0861b7 100644 --- a/extras/sponge.rb +++ b/extras/sponge.rb @@ -114,6 +114,7 @@ class Sponge end host = Net::HTTP.new(ip.to_s, uri.port) + host.read_timeout = self.timeout if self.debug host.set_debug_output $stdout end @@ -161,12 +162,10 @@ class Sponge end res = nil - Timeout.timeout(self.timeout) do - if method == :post - res = host.post(path, post_data, headers) - else - res = host.get(path, headers) - end + if method == :post + res = host.post(path, post_data, headers) + else + res = host.get(path, headers) end if res.get_fields("Set-Cookie") diff --git a/extras/story_cacher.rb b/extras/story_cacher.rb index 4335aca..e29f854 100644 --- a/extras/story_cacher.rb +++ b/extras/story_cacher.rb @@ -27,9 +27,14 @@ class StoryCacher if res.present? j = JSON.parse(res) + # turn newlines into double newlines, so they become paragraphs + j["text"].gsub!("\n", "\n\n") + while j["text"].match("\n\n\n") j["text"].gsub!("\n\n\n", "\n\n") end + + return j["text"] end rescue => e