Permalink
Browse files

Added logger.

  • Loading branch information...
carlo committed Mar 22, 2010
1 parent 83dfbd2 commit 2dee9f16dd46830fde8941c3444d0d7ecfa009ae
Showing with 17 additions and 43 deletions.
  1. +11 −5 config.ru
  2. +6 −38 mobipocket.rb
View
@@ -1,17 +1,23 @@
require "appengine-rack"
+require "appengine-apis/memcache"
+require "appengine-apis/logger"
+require "mobipocket"
+require "epub"
+
AppEngine::Rack.configure_app(
:application => "ephemera-conv",
- :version => 2
+ :version => 5
)
-require "mobipocket"
-require "epub"
+
+CACHE = AppEngine::Memcache.new
+CACHE_TIME = 300 # sec
+LOGGER = AppEngine::Logger.new
+
get "/" do
"ephemera-conv. Yeeeeah, baby."
end
-CACHE = AppEngine::Memcache.new
-CACHE_TIME = 300 # sec
run Sinatra::Application
View
@@ -1,7 +1,6 @@
require "sinatra"
require "dm-core"
require "mobi"
-require "appengine-apis/memcache"
helpers do
@@ -13,19 +12,15 @@ def new_exth(type, data)
def send_book(book)
- content_type 'application/octet-stream'
- response['Content-Disposition'] = 'inline'
+ content_type "application/octet-stream"
+ response['Content-Disposition'] = "inline"
halt book
end
end
get "/mobi" do
- CACHE.set("lol", "omg", 3)
- # puts request.env['REMOTE_ADDR'].inspect
- STDERR.puts mc.get("lol")
-
"mobi"
end
@@ -41,19 +36,20 @@ def send_book(book)
end
key = [ request.env['REMOTE_ADDR'], name ].join("-")
+
if book = CACHE.get(key)
- STDERR.puts "Cached request! FILE: #{name.inspect}; SITE: #{site}; TITLE: #{title}."
+ LOGGER.info("Cached request! FILE: #{name.inspect}; SITE: #{site}; TITLE: #{title}.")
send_book(book)
else
- STDERR.puts "New request! FILE: #{name.inspect}; SITE: #{site}; TITLE: #{title}."
+ LOGGER.info("New request! FILE: #{name.inspect}; SITE: #{site}; TITLE: #{title}.")
while html = tmpfile.read(65536)
mobi = Mobi.new
mobi.content = html
mobi.name = title
mobi.title = title
- mobi.header.type = "NEWS" # "HTML"
+ mobi.header.type = "NEWS"
mobi.header.encoding = "UTF-8"
mobi.header.extended_headers << new_exth( 100, site )
mobi.header.extended_headers.each {|eh| mobi.header.exth_length += eh.length }
@@ -69,31 +65,3 @@ def send_book(book)
end
end
end
-
-
-
-
-
-=begin
-
-tmp_file = "_test/szde.html"
-mobi_file = "_test/test.mobi"
-
-
-mobi = Mobi.new
-mobi.content = File.read(tmp_file)
-mobi.name = "Politik kompakt: \"Afghanistan-Konflikt nicht zu gewinnen\""
-mobi.title = mobi.name
-
-mobi.header.type = "NEWS" # "HTML"
-mobi.header.encoding = "UTF-8"
-mobi.header.extended_headers << new_exth( 100, "sueddeutsche.de" )
-mobi.header.extended_headers.each do |eh|
- mobi.header.exth_length += eh.length
-end
-
-mobi.header.exth_count = mobi.header.extended_headers.size
-
-mobi.write_file(mobi_file)
-
-=end

0 comments on commit 2dee9f1

Please sign in to comment.