Created
March 31, 2020 04:00
-
-
Save daltonmenezes/34012ec5d23d0071874d3da910d7226a to your computer and use it in GitHub Desktop.
Scraping GitHub status servers with javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch('https://www.githubstatus.com/') | |
.then(res => res.text()) | |
.then(text => { | |
const parser = new DOMParser() | |
const dom = parser.parseFromString(text, 'text/html') | |
const status = Array.from( | |
dom.querySelectorAll("div.component-inner-container.showcased span.component-status"), | |
el => { | |
const alias = { | |
'status-green': 'normal', | |
'status-yellow': 'degraded', | |
'status-orange': 'degraded', | |
'status-red': 'incident' | |
} | |
const status = el.parentElement.classList[1] | |
return alias[status] | |
} | |
) | |
const fields = { | |
operations: '', | |
apiRequests: '', | |
webhooks: '', | |
issuesPRsProjects: '', | |
actions: '', | |
packages: '', | |
pages: '' | |
} | |
return Object.keys(fields).reduce((acc, key, index) => { | |
return acc = { | |
...acc, | |
[key]: status[index] | |
} | |
}, {}) | |
}) | |
.then(console.log) | |
/* | |
{ | |
operations: "normal" | |
apiRequests: "normal" | |
webhooks: "normal" | |
issuesPRsProjects: "normal" | |
actions: "normal" | |
packages: "normal" | |
pages: "normal" | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment