mirror of
https://github.com/He4eT/fuzzsoma.git
synced 2026-05-04 17:27:23 +00:00
index.js: init
This commit is contained in:
parent
285c27feab
commit
987c0e4814
1 changed files with 23 additions and 1 deletions
24
index.js
24
index.js
|
|
@ -1,3 +1,25 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
console.log(1234)
|
||||
const xml2js = require('xml2js')
|
||||
|
||||
const channelsUrl = 'https://somafm.com/channels.xml'
|
||||
|
||||
const download = (url) =>
|
||||
fetch(url)
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return response.text()
|
||||
} else {
|
||||
throw new Error(`Failed to download XML. Status: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
})
|
||||
|
||||
download(channelsUrl)
|
||||
.then(xml2js.parseStringPromise)
|
||||
.then((json) => json.channels.channel)
|
||||
.then((channels) => channels.map((channel) => ({
|
||||
title: `${channel.title[0]} — ${channel.description[0]}`,
|
||||
value: channel.highestpls[0]['_'],
|
||||
})))
|
||||
.then((x) => console.log(x))
|
||||
.catch((error) => console.error('Error:', error.message))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue