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

Commit

Permalink
Merge pull request #12 from renatocfrancisco/feat-new-topsters
Browse files Browse the repository at this point in the history
restaurar script para novo site topsters
  • Loading branch information
renatocfrancisco authored May 2, 2024
2 parents afeda9f + 29252c2 commit f704b98
Show file tree
Hide file tree
Showing 8 changed files with 2,039 additions and 1,776 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js",
"program": "${workspaceFolder}\\topsters-download.js",
"args": ["-y"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
[![StandWithPalestine](https://raw.githubusercontent.com/Safouene1/support-palestine-banner/master/StandWithPalestine.svg)](https://techforpalestine.org/learn-more)

Puppeteer script for downloading chart from [**topsters**](https://www.neverendingchartrendering.org/). Because why not.
Puppeteer script for downloading chart from [**topsters**](https://topsters.org/). Because why not.

[**Download zip file**](https://github.com/renatocfrancisco/topsters-download/archive/refs/heads/main.zip), get the [**latest release**](https://github.com/renatocfrancisco/topsters-download/releases/latest) or use:

Expand Down
164 changes: 164 additions & 0 deletions js/inquirerInputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import input from '@inquirer/input'
import confirm from '@inquirer/confirm'
import select from '@inquirer/select'

export async function inputUsername (obj = {}) {
return await input({
message: 'Enter your last.fm username',
default: obj.username ? obj.username : 'renatocfrancisc',
validate: (value) => {
const pass = value.match(/^[a-zA-Z0-9]+$/)
if (pass) {
return true
}
}
})
}

async function selectPeriod () {
return await select({
message: 'Select the period of the chart',
choices: [
{
name: 'a week',
value: '7day'
},
{
name: '1 month',
value: '1month'
},
{
name: '3 months',
value: '3month'
},
{
name: '6 months',
value: '6month'
},
{
name: '12 months',
value: '12month'
},
{
name: 'overall',
value: 'overall'
}
]
})
}

async function selectSize () {
return await select({
message: 'Select the size of the chart',
choices: [
{
name: 'collage',
value: '25'
},
{
name: '40',
value: '40'
},
{
name: '42',
value: '42'
},
{
name: '100',
value: '100'
}
]
})
}

export async function confirmPeriod (obj = {}) {
return await confirm({
message: `Do you want to select the period of the chart? default: ${obj.period ? obj.period : 'a week'}`,
default: false
}).then(async (answer) => {
if (answer) {
return await selectPeriod()
} else {
return obj.period ? obj.period : '7day'
}
})
}

function nameSize (size) {
switch (size) {
case '25':
return 'collage'
default:
return size
}
}

export async function confirmSize (obj = {}) {
return await confirm({
message: `Do you want to select the size of the chart? default: ${obj.size ? nameSize(obj.size) : '42'}`,
default: false
}).then(async (answer) => {
if (answer) {
return await selectSize()
} else {
return obj.size ? obj.size : '42'
}
})
}

export async function inputRows (obj = {}) {
return await input({
message: 'Select the number of rows (1-12)',
default: obj.rows ? obj.rows : '5',
validate: (value) => {
const pass = value.match(/^[0-9]+$/)
if (pass) {
return true
}

return 'Please enter a valid number'
}
})
}

export async function inputColumns (obj = {}) {
return await input({
message: 'Select the number of columns (1-12)',
default: obj.columns ? obj.columns : '5',
validate: (value) => {
const pass = value.match(/^[0-9]+$/)
if (pass) {
return true
}

return 'Please enter a valid number'
}
})
}

export async function inputPadding (obj = {}) {
return await input({
message: 'Select the padding of the chart (0-150)',
default: obj.gap ? obj.gap : '6',
validate: (value) => {
const pass = value.match(/^[0-9]+$/)
if (pass) {
return true
}
}
})
}

export async function confirmAlbumTitles (obj = {}) {
return await confirm({
message: 'Do you want to display the album titles?',
default: obj.albumTitles ? obj.albumTitles : false
})
}

export async function confirmNumbered () {
return await confirm({
message: 'Do you want to display the album numbers?',
default: false
})
}
5 changes: 5 additions & 0 deletions js/puppeteerOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const options = {
headless: 'new',
defaultViewport: null,
args: ['--no-sandbox', '--start-maximized']
}
18 changes: 18 additions & 0 deletions js/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const navList = '#app > div > div.sidebar > div.tabbed-sidebar-block > ul > li'

const selectors = {
importTab: `${navList}:nth-child(3) > button`,
usernameInput: '#lastFmUsername',
periodSelect: '#lastFmPeriodDropdown',
importButton: '#lastfmImportButton',
optionsTab: `${navList}:nth-child(2) > button`,
titlesCheck: '#display-titles',
widthInput: '#x-axis',
heightInput: '#y-axis',
gapInput: '#gap',
titleInput: '#title',
numbersCheck: '#show-numbers',
downloadButton: '#top-bar > button'
}

export default selectors
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "topsters-download",
"version": "1.5.2",
"version": "2.0.0",
"description": "Puppeteer script for downloading chart from topsters.",
"main": "topsters-download.js",
"private": true,
Expand All @@ -12,10 +12,10 @@
"author": "renatocfrancisco",
"license": "Unlicense",
"dependencies": {
"@inquirer/confirm": "^3.1.1",
"@inquirer/input": "^2.1.1",
"@inquirer/select": "^2.2.1",
"puppeteer": "^22.6.2"
"@inquirer/confirm": "^3.1.6",
"@inquirer/input": "^2.1.6",
"@inquirer/select": "^2.3.2",
"puppeteer": "^22.7.1"
},
"devDependencies": {
"eslint": "^8.57.0",
Expand Down
Loading

0 comments on commit f704b98

Please sign in to comment.