Skip to content

Commit

Permalink
Merge pull request #49 from hurricanemark/Phase2-BaselineToSeriousWorks
Browse files Browse the repository at this point in the history
Phase2 baseline to serious works
  • Loading branch information
hurricanemark authored Nov 7, 2022
2 parents 227b7fb + 145f8e3 commit 294e86c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,15 @@ function getWeatherBitDailyForecast(city){
// console.log(uriWeatherBitStr);
try {
request(uriWeatherBitStr, async function (err, response, body) {
console.log(response.statusCode);

if (response.statusCode == 429) {
console.log("WARNING: You have exceeded your API call limit with weatherbit.io!");
resolve(null);
}
if (response.statusCode == 403) {
console.log("WARNING: Free plan limit is used up. Data will be available again on the 3rd of next month.");
retCode = JSON.parse(body);
resolve(retCode);
}
if (response.statusCode == 200) {
retCode = await JSON.parse(body);
resolve(retCode);
Expand Down Expand Up @@ -362,8 +365,12 @@ async function gatherWeatheBits(city) {
]);


// Check is the service trial expired
if (dailyForecast.error === 'API key not valid, or not yet activated.') {
return { locale: city, alertStatus: 403, alertData: null, curStatus: 403, curData: null, foreStatus: 403, foreData: null, airqStatus: 403, airqData: null, error: 'Free plan has reached its limit. Data will be available again on the 3rd of next month.' };
}
// Make sure all promisses fulfilled.
if (dailyForecast !== null && alerts !== null && airQuality !== null && currentConditions !== null ) {
else if (dailyForecast !== null && alerts !== null && airQuality !== null && currentConditions !== null ) {
let currentHour = new Date().getHours();
let aStatus = 200;
let aData = alerts;
Expand Down
7 changes: 7 additions & 0 deletions views/pages/weatherbit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<div class="jumbotron jumbotron-fluid" style="padding:10px 5px 15px 20px;">
<% if( typeof(error)==="undefined" || curStatus===400 ){ %>
<p style="color:gray"> Waiting for data.</p>
<% } else if ( typeof(error)!="undefined" && curStatus===403 ) { %>
<p style="color:gray">We apologize. <%= error %></p>
<% } else { %>
<p style="color:gray"><strong>City</strong>: <%= curData.city_name %> , <%= curData.state_code %>
Expand Down Expand Up @@ -122,8 +124,11 @@
<div class="col-sm-6">
<h5>Current Air Quality</h5>
<div class="jumbotron jumbotron-fluid" style="padding:10px 5px 15px 20px;">

<% if( typeof(error)==="undefined" || airqStatus===400 ) { %>
<p style="color:gray"> Waiting for data.</p>
<% } else if ( typeof(error)!="undefined" && airqStatus===403 ) { %>
<p style="color:gray"> <%= error %></p>
<% } else { %>
<p style="color:gray"><strong>Local hourly</strong>: <%= airqData.timestamp_local.split('T')[1] %>
</p>
Expand Down Expand Up @@ -222,6 +227,8 @@
<div class="jumbotron jumbotron-fluid" style="padding:10px 5px 15px 20px; overflow-x:auto;">
<% if( typeof(error)==="undefined" || foreStatus===400 ){ %>
<p style="color:gray"> Waiting for data.</p>
<% } else if ( typeof(error)!="undefined" && foreStatus===403 ) { %>
<p style="color:gray"> <%= error %></p>
<% } else { %>
<div style="color:rgb(18, 83, 175);"><%= trendingTemperature(foreData.data) %></div>
<table class="styled-table">
Expand Down

0 comments on commit 294e86c

Please sign in to comment.