require 'open-uri'
require 'nokogiri'
require 'pry'
class ServiceSeeds
attr_accessor :doc, :status_array, :description, :delay_header, :output_hash
def initialize
@output_hash = Hash.new {|hash, key| hash[key] = {}}
@doc = Nokogiri::XML(open("http://web.mta.info/status/serviceStatus.txt"))
end
def descriptive_status
@doc.xpath('//subway//line').each do |line|
train_name = line.at_css("/name").text
train_status = line.at_css("status").text
@output_hash[train_name][:status] = train_status
super_descriptive = line.xpath("text")
html = Nokogiri::HTML(super_descriptive.text)
if train_status == "GOOD SERVICE"
super_descriptive = "On time"
else
html.css(".plannedWorkDetailLink").each do |detail|
planned_work = detail.children.text
@output_hash[train_name][:header] = planned_work
end
html.css(".plannedWorkDetail").each do |detail|
planned_work_detail = detail.children.text
@output_hash[train_name][:details] = planned_work_detail
end
html.css(".TitleDelay").each do |detail| # working with this
title_delay = detail.children.text
@output_hash[train_name][:title_delay] = title_delay
end
html.css(".TitleServiceChange").each do |detail|
title_service_change = detail.children.text
@output_hash[train_name][:service_change] = title_service_change
end
end
end
@output_hash
end
end
service = ServiceSeeds.new
puts "deleting old Service seeds"
Service.destroy_all
service.descriptive_status.each do |train_name, info|
Service.create(name: train_name, traffic: info[:status], description: info[:header], more_detail: info[:details])
end
puts "Updated service information"
<!--~~~~~~~~~~~~~~~~~~~~~~~~ Before ~~~~~~~~~~~~~~~~~~~~~~~~-->
<!-- Page Title -->
<% provide(:title, "Sign in")%>
<!-- Page Background -->
<!DOCTYPE html>
<html style="background: url(/assets/background1.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;"><!-- Signup Page Background -->
<!--~~~~~~~~~~~~~~~~~~~~~~~~ Sidebar ~~~~~~~~~~~~~~~~~~~~~~~~-->
<!--~~~~~~~~~~~~~~~~~~~~~~~~ Page Contents ~~~~~~~~~~~~~~~~~~~~~~~~-->
<!-- Sign Up -->
<div class="user-links">
Do not have an account? <%= link_to 'Sign up', new_user_registration_path, class:"no_ajaxify" %>
</div>
<div class="center" style="width: 310px;">
<!-- Cutter --><ol style="margin-top: 80px;"></ol>
<span id="Join-Ratafire">Sign in.</span>
<!-- Cutter --><ol style="margin-top: 18px;"></ol>
<div id="Signin-box">
<!-- Signin Form -->
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name),:html => {:class => "no_ajaxify"}) do |f| %>
<ol>
<%= f.text_field :email, class: "inputbox signupbox", placeholder: "Email" %>
</ol>
<ol>
<%= f.password_field :password, class: "inputbox signupbox", placeholder: "Password" %>
</ol>
<ul>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<%= link_to "Forgot password?", new_password_path(resource_name) %>
</ul>
<ol style="margin-top: 15px; padding-left: 157px;">
<%= f.submit "SIGN IN", class: "btn-submit btn-submit-small btn btn-small2 btn-small-blue" %>
</ol>
<% end %>
</div><!-- end of Signin-box -->
</div><!-- end of center-->
<!-- Footer -->
<div style="padding: 0px 20px 18px 0; margin-top: 287px;">
<%= render 'layouts/footer' %>
</div>
</html>
<!-- Signin Form -->
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :class => 'no_ajaxify'}) do |f| %>
<ol>
<%= f.text_field :email, class: "inputbox signupbox2", placeholder: "Email" %>
</ol>
<ol>
<%= f.password_field :password, class: "inputbox signupbox2", placeholder: "Password" %>
</ol>
<ol style="margin-top:15px;color:#999;margin-left:120px;">
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end %>
</ol>
<ol>
<%= link_to "Forgot your password?", new_password_path(resource_name), class:"no_ajaxify", style:"margin-left:150px;" %>
</ol>
<ol style="margin-top: -35px; padding-left: 418px;">
<div id="submit">
<%= f.submit "SIGN IN", class: "btn-submit btn-submit-small btn btn-small2 btn-small-blue" %>
</div>
</ol>
<div class="signupshow-signup" style="margin-top: -32px; margin-left: 180px;" id="signupshow-signup">
Sign Up
</div>
<% end %>