Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the API #13

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/fuel_price_scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.get_fuel_price(city, city_id, fuel_type)
if response_html.success?
Rails.logger.info "Successfully fetched #{fuel_type} price for #{city}"
parsed_page = Nokogiri::HTML(response_html)
return parsed_page.at_css('[class="price"]').children.to_s.strip.delete("^.0-9").to_f.round(2)
return parsed_page.at_css('[class="UCPrice"]').children.to_s.strip.delete("^.0-9").to_f.round(2)
else
raise HTTParty::Error("Received a non 200 response")
end
Expand Down
169 changes: 166 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,180 @@
<!DOCTYPE html>
<html>

<!-- Petrol, Diesel, Price -->
<head>
<title>FuelPricesIndia</title>

<meta name="description" content="Get the Latest Petrol price in India " />
<meta name="keywords" content="Bangalore Petrol Rate, Pune Petrol Rate, Bangalore Petrol Rate,Delhi,Mumbai,</option>
Chennai,Hyderabad,Chandigarh Petrol Prics" />
<meta name="author" content="metatags generator">
<meta name="robots" content="index, follow">
<meta name="revisit-after" content="1 days">
<title>Latest Fuel Price India</title>
<%= csrf_meta_tags %>

<%= stylesheet_link_tag "https://fonts.googleapis.com/icon?family=Material+Icons" %>
<%= stylesheet_link_tag "https://code.getmdl.io/1.3.0/material.indigo-pink.min.css" %>
<%= stylesheet_link_tag "http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" %>
<%= javascript_include_tag "https://code.getmdl.io/1.3.0/material.min.js" %>

<%= stylesheet_link_tag "http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" %>




<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
.by {
right: 0;
bottom: 0;
background-color: #ff4742;
background: -webkit-linear-gradient(right, #f85032, #ff4742);
background: linear-gradient(to left, #f85032, #ff4742);
color: #fff;
position: fixed;
font-weight: 500;
z-index: 970000;
border-top-left-radius: 0.2em;
padding: 0.5em;
}
.by:hover {
background-color: #fff !important;
color: #000 !important;
}
.by img {
border-radius: 0em !important;
width: 2.2em !important;
vertical-align: middle !important;
}
.by p {
margin: 0 !important;
vertical-align: middle !important;
display: inline !important;
margin-left: 0.5em !important;
font-weight: 700 !important;
}



.site-footer {
font-size: 12px;
margin-left: 2px;
margin-right: 2px;
}

button.mdl-button {
margin: 50px;
font-size: 20px;
width: 12em;
height: 3em;
}
/*SELECT ELEMENT WITH UNICODE SYMBOL: DOWN-ARROW (&#x25bc;)*/
select#city_name, select#fuelType
{
width : 185pt;
height : 40pt;
line-height : 40pt;
padding-right : 0pt;
text-indent : 4pt;
text-align : center;
vertical-align : middle;
box-shadow : inset 0 0 3px #606060;
border : 1px solid #acacac;
-moz-border-radius : 6px;
-webkit-border-radius : 6px;
border-radius : 6px;
-webkit-appearance : none;
-moz-appearance : none;
appearance : none; /*IMPORTANT*/
font-family : Arial, Calibri, Tahoma, Verdana;
font-size : 18pt;
font-weight : 500;
color : #F44336;
cursor : pointer;
outline : none;
}
select#city_name::-ms-expand {display: none;} /*FOR IE*/
select#city_name option
{
padding : 4px 10px 4px 10px;
font-size : 11pt;
font-weight : normal;
}
select#city_name option[selected]{ font-weight:bold}
select#city_name option:nth-child(even) { background-color:#f5f5f5; }
select#city_name:hover {font-weight: 700;}
select#city_name:focus {box-shadow: inset 0 0 5px #000099; font-weight: 600;}

/*LABEL FOR SELECT*/
label#lblSelect{ position: relative; display: inline-block;}
/*DOWNWARD ARROW (25bc)*/
label#lblSelect::after
{
content : "\25bc";
position : absolute;
top : 0;
right : 0;
bottom : 0;
width : 20pt;
line-height : 40pt;
vertical-align : middle;
text-align : center;
background : #000099;
color : #fefefe;
-moz-border-radius : 0 6px 6px 0;
-webkit-border-radius : 0 6px 6px 0;
border-radius : 0 6px 6px 0;
pointer-events : none;
}

img
{
width:100px;
}

span
{
color: #666
font-size: 12px
display: block
position: absolute
bottom: 10px
position: absolute
width: 90%
left: 50%
top: 45%
bottom: auto
right: auto
transform: translateX(-50%) translateY(-50%)
text-align: center
}

.fa
{
color: #E90606
margin: 0 3px
font-size: 10px
animation: pound .35s infinite alternate
-webkit-animation: pound .35s infinite
}
</style>


</head>

<body>
<%= yield %>
</body>
<footer> <center>
<span>
</span>
<br>
<br>

</footer>
</html>
33 changes: 14 additions & 19 deletions app/views/main/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<center>
<h4>Latest Fuel Price</h4>
<%= select_tag 'city_name', options_for_select(City.city_list) %>
<%= select_tag 'fuelType', options_for_select(Fuel::TYPE.values) %>
<br>
<br>
<br>
<button class="btn btn-default" id="submit" onclick="fetchVal()">Fetch Price</button>
<br>

<h4>Latest Fuel Price India</h4>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<%= select_tag 'city_name', options_for_select(City.city_list), {:class => 'mdl-textfield__input'} %>
<br>
<%= select_tag 'fuelType', options_for_select(["Petrol", "Diesel"]) , {:class => 'mdl-textfield__input'} %>
</div>
<h3 id="result">

<br>
<h5><p id="result"></h5>
</center>
<h1><button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" id="submit" onclick="fetchVal()">Fetch Price</button></h2>

</center>
<script>
function fetchVal() {
$("#result").text("Fetching latest value for you...");
Expand All @@ -22,16 +22,11 @@ function fetchVal() {
type: "GET",
dataType: "JSON",
data: jsonData,
url: "price?city=" + city + "&fuel_type=" + fuelType,
url: "main/" + city + "/" + fuelType + "/price",
success: function(data){
if(data[fuelType] == null){
$("#result").text("Data not available at this time.");
} else {
$("#result").text("Latest " + fuelType + " price for " + data['city'] + " is Rs. " + data[fuelType]);
}
},
error: function(data){
$("#result").text("Data not available at this time.");
// alert(data['val']);
$("#result").text("Latest " + fuelType + " price for " + data['city'] + " is ₹ " + data['price']);
// $('#result').val(objectStr);
}
});
}
Expand Down