Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
🌀 Add auto refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
mskian committed Sep 19, 2020
1 parent 78440ba commit ed1b26a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 69 deletions.
76 changes: 42 additions & 34 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
const axios = require('axios');
const cheerio = require('cheerio');

// Update the Match URL Don't remove this line - https://cors-anywhere.herokuapp.com/
const liveurl = 'https://cors-anywhere.herokuapp.com/https://www.espncricinfo.com/series/8048/game/1216492/mumbai-indians-vs-chennai-super-kings-1st-match-indian-premier-league-2020-21';

function Getscore() {
// eslint-disable-next-line no-undef
const appNotice = $('.notice');
appNotice.html('<p class="has-text-centered">Fetching the Live Score 📦</p>');
const appNotice = $('.notice');
appNotice.html('<p class="has-text-centered">Fetching the Live Score 📦</p>');

axios({
method: 'get',
url: liveurl,
})
.then(
setTimeout(() => {
appNotice.empty();
}, 800),
)
.then(function(response) {
if (response.status == '200') {
const html = response.data;
const $ = cheerio.load(html);
let score = $('meta[property="og:title"]').attr('content');
console.log(score);
document.getElementById('response').innerHTML = '<div class="notification score is-link has-text-weight-bold">' + score + '</div>';
} else {
console.log(response.status);
}
axios({
method: 'get',
url: liveurl,
})
.catch(function(error) {
if (!error.response) {
console.log('Enter a Valid URL');
} else if (error.response.status == 429) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else if (error.response.status == 403) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else {
console.log('Hmm Something Went Wrong or HTTP Status Code is Missing');
}
});
.then(
setTimeout(() => {
appNotice.empty();
}, 800),
)
.then(function(response) {
if (response.status == '200') {
const html = response.data;
const $ = cheerio.load(html);
let score = $('meta[property="og:title"]').attr('content');
console.log(score);
document.getElementById('response').innerHTML = '<div class="notification score is-link has-text-weight-bold">' + score + '</div>';
} else {
console.log(response.status);
}
})
.catch(function(error) {
if (!error.response) {
console.log('Enter a Valid URL');
} else if (error.response.status == 429) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else if (error.response.status == 403) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else {
console.log('Hmm Something Went Wrong or HTTP Status Code is Missing');
}
});
}

Getscore();

// https://stackoverflow.com/questions/44282721/update-changing-json-data-on-web-site-without-refreshing
setInterval(Getscore, 60 * 1000);
76 changes: 42 additions & 34 deletions public/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,53 @@
const axios = require('axios');
const cheerio = require('cheerio');

// Update the Match URL Don't remove this line - https://cors-anywhere.herokuapp.com/
const liveurl = 'https://cors-anywhere.herokuapp.com/https://www.espncricinfo.com/series/8048/game/1216492/mumbai-indians-vs-chennai-super-kings-1st-match-indian-premier-league-2020-21';

function Getscore() {
// eslint-disable-next-line no-undef
const appNotice = $('.notice');
appNotice.html('<p class="has-text-centered">Fetching the Live Score 📦</p>');
const appNotice = $('.notice');
appNotice.html('<p class="has-text-centered">Fetching the Live Score 📦</p>');

axios({
method: 'get',
url: liveurl,
})
.then(
setTimeout(() => {
appNotice.empty();
}, 800),
)
.then(function(response) {
if (response.status == '200') {
const html = response.data;
const $ = cheerio.load(html);
let score = $('meta[property="og:title"]').attr('content');
console.log(score);
document.getElementById('response').innerHTML = '<div class="notification score is-link has-text-weight-bold">' + score + '</div>';
} else {
console.log(response.status);
}
axios({
method: 'get',
url: liveurl,
})
.catch(function(error) {
if (!error.response) {
console.log('Enter a Valid URL');
} else if (error.response.status == 429) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else if (error.response.status == 403) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else {
console.log('Hmm Something Went Wrong or HTTP Status Code is Missing');
}
});
.then(
setTimeout(() => {
appNotice.empty();
}, 800),
)
.then(function(response) {
if (response.status == '200') {
const html = response.data;
const $ = cheerio.load(html);
let score = $('meta[property="og:title"]').attr('content');
console.log(score);
document.getElementById('response').innerHTML = '<div class="notification score is-link has-text-weight-bold">' + score + '</div>';
} else {
console.log(response.status);
}
})
.catch(function(error) {
if (!error.response) {
console.log('Enter a Valid URL');
} else if (error.response.status == 429) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else if (error.response.status == 403) {
console.log(error.response.data);
document.getElementById('response').innerHTML = '<div class="notification is-danger">'+ error.response.data +'</div>';
} else {
console.log('Hmm Something Went Wrong or HTTP Status Code is Missing');
}
});
}

Getscore();

// https://stackoverflow.com/questions/44282721/update-changing-json-data-on-web-site-without-refreshing
setInterval(Getscore, 60 * 1000);

},{"axios":2,"cheerio":32}],2:[function(require,module,exports){
module.exports = require('./lib/axios');
Expand Down
2 changes: 1 addition & 1 deletion public/bundle.min.js

Large diffs are not rendered by default.

0 comments on commit ed1b26a

Please sign in to comment.