From 35e4633687ab2f3b86b0a9bef299d388d254d92f Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 9 Jun 2014 21:22:02 -0500 Subject: [PATCH] agregar fechas a acciones, blood was shed, #50 --- .../20140610002450_add_dates_to_acciones.rb | 8 ++++++++ db/schema.rb | 10 +++++++--- db/seeds.rb | 20 +++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20140610002450_add_dates_to_acciones.rb diff --git a/db/migrate/20140610002450_add_dates_to_acciones.rb b/db/migrate/20140610002450_add_dates_to_acciones.rb new file mode 100644 index 0000000..ed39fce --- /dev/null +++ b/db/migrate/20140610002450_add_dates_to_acciones.rb @@ -0,0 +1,8 @@ +class AddDatesToAcciones < ActiveRecord::Migration + def change + add_column :acciones, :fecha_inicio, :date + add_column :acciones, :fecha_fin, :date + add_column :acciones, :hora_inicio, :time + add_column :acciones, :hora_fin, :time + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c7c8f1..4be964e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140605160019) do +ActiveRecord::Schema.define(version: 20140610002450) do create_table "acciones", force: true do |t| t.string "name" @@ -19,8 +19,8 @@ t.integer "points" t.datetime "created_at" t.datetime "updated_at" - t.integer "level", default: 1 - t.boolean "canjeable", default: false + t.integer "level", default: 1 + t.boolean "canjeable", default: false t.string "code" t.string "lugar" t.string "promotor" @@ -28,6 +28,10 @@ t.string "fecha" t.string "horario" t.string "url" + t.date "fecha_inicio" + t.date "fecha_fin" + t.time "hora_inicio" + t.time "hora_fin" end create_table "badge_relationships", force: true do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 3c94fce..fd02bf1 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -95,17 +95,33 @@ def get_urls(events_url, dates) json = JSON.parse(request.body) html = Nokogiri::HTML(json["html"]) html.remove_namespaces! - html.css('a.url').each do |node| + html.css('div.hentry').each do |node| accion_saludable = Accion.new() - get_event node["href"], accion_saludable + get_event node.css('a.url').attr('href').value, accion_saludable accion_saludable.url = node['href'] accion_saludable.code = "AAAA-BBBB" accion_saludable.canjeable = true accion_saludable.recurrente = false accion_saludable.points = 10 + fecha_inicio = node.css('span.dtstart').css('span.value-title').attr('title').value + fecha_fin = node.css('span.dtend').css('span.value-title').attr('title').value rescue nil + puts accion_saludable.name + fi = DateTime.parse(fecha_inicio) + accion_saludable.fecha_inicio = fi + accion_saludable.hora_inicio = fi + if fecha_fin + ff = DateTime.parse(fecha_fin) + accion_saludable.fecha_fin = ff + accion_saludable.hora_fin = ff + else + accion_saludable.fecha_fin = fi + accion_saludable.hora_fin = fi + end accion_saludable.promotor = "INDEPORTE" + puts accion_saludable accion_saludable.save! puts '########' + end end