Skip to content

Commit

Permalink
agregar fechas a acciones, blood was shed, #50
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjcsr committed Jun 10, 2014
1 parent e01454f commit 35e4633
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
8 changes: 8 additions & 0 deletions db/migrate/20140610002450_add_dates_to_acciones.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@
#
# 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"
t.text "desc"
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"
t.boolean "recurrente"
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|
Expand Down
20 changes: 18 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 35e4633

Please sign in to comment.