Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
janlelis committed May 26, 2011
1 parent 56c4b77 commit cda5da6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/harvester-new
Expand Up @@ -15,7 +15,7 @@ source = File.expand_path File.dirname(__FILE__) + '/..'
FileUtils.mkdir_p new
FileUtils.cp_r source + '/data/templates', new + '/templates'
FileUtils.cp source + '/collections.yaml', new + '/collections.yaml'
FileUtils.cp source + '/README', new + '/README'
FileUtils.cp source + '/README.rdoc', new + '/README'

# edit default options
c = YAML::load_file source + '/config.yaml'
Expand Down
1 change: 1 addition & 0 deletions data/sql/mysql/chart.sql
@@ -0,0 +1 @@
select date(items.date) as date,sources.collection from items left join sources on sources.rss=items.rss where date > now() - interval '14 days' and date < now() + interval '1 day' order by date
1 change: 1 addition & 0 deletions data/sql/postgresql/chart.sql
@@ -0,0 +1 @@
select date(items.date) as date,sources.collection from items left join sources on sources.rss=items.rss where date > now() - interval '14 days' and date < now() + interval '1 day' order by date
1 change: 1 addition & 0 deletions data/sql/sqlite3/chart.sql
@@ -0,0 +1 @@
select date(items.date) as date,sources.collection from items left join sources on sources.rss=items.rss where date > time('now', '-14 days') and date < time('now', '+1 day') order by date
3 changes: 2 additions & 1 deletion lib/harvester/chart.rb
@@ -1,6 +1,7 @@
# encoding: utf-8

require_relative '../harvester'
require_relative '../harvester/db'
require 'gruff'

class Harvester
Expand All @@ -11,7 +12,7 @@ def chart!
info "CHART"
task "generate chart" do
c = Chart::StatsPerCollection.new
@dbi.execute("select date(items.date) as date,sources.collection from items left join sources on sources.rss=items.rss where date > now() - interval '14 days' and date < now() + interval '1 day' order by date").each{ |date,collection|
@dbi.execute( File.read( sql_query(:chart) ) ).each{ |date,collection|
c.add_one(collection, Date.parse(date).day)
}
Chart.new(c).write File.join( @config['settings']['output'], '/chart.jpg' )
Expand Down
4 changes: 4 additions & 0 deletions lib/harvester/db.rb
Expand Up @@ -116,4 +116,8 @@ def update(rss_url, new_source, collection, response, rss_url_nice = rss_url)
def sql_queries(task)
Dir[ File.dirname(__FILE__) + "/../../data/sql/#{ @config['db']['driver'].downcase }/#{ task }*.sql" ].each
end

def sql_query(task)
File.dirname(__FILE__) + "/../../data/sql/#{ @config['db']['driver'].downcase }/#{ task }.sql"
end
end
4 changes: 2 additions & 2 deletions lib/harvester/fetch.rb
Expand Up @@ -75,7 +75,7 @@ def self.run(dbi, collections, settings, logger)
if http.response_header.status != 200
logger.warn rss_url_nice + "HTTP not OK, but: #{ http.response_header.status }"
elsif http.response.size > settings['size limit'].to_i
logger.warn rss_url_nice + "Got too big repsonse: #{response.size} bytes"
logger.warn rss_url_nice + "Got too big repsonse: #{ response.size } bytes"
else
yield rss_url, new_source, collection, http.response, rss_url_nice
end
Expand All @@ -91,6 +91,6 @@ def self.run(dbi, collections, settings, logger)
EM.stop
}
end
logger.info '[done] fetch using Eventmachine'
logger.info '[done ] fetch using Eventmachine'
end
end

0 comments on commit cda5da6

Please sign in to comment.