Ricardo Bassete

Ricardo Bassete

// Name: Search Game in Steam Charts
// Description: Search Game in https://steamcharts.com/
// Author: Ricardo Gonçalves Bassete
import "@johnlindquist/kit"
import cheerio from 'cheerio'
import axios from 'axios'
import { Choice } from "@johnlindquist/kit"
interface Game {
name: string
link: string
img: string
currentPlayers: string
monthAvg: string
monthGain: string
monthGainPercent: string
}
async function searchGames(keyword: string) {
const baseURL = 'https://steamcharts.com'
const searchURL = `${baseURL}/search/?q=${keyword.toLowerCase().replaceAll(' ', '+')}`
const { data } = await axios.get(searchURL)
const $ = cheerio.load(data)
const result: Game[] = $('tr').get().map(el => {
const tr = $(el)
const imgEl = tr.find('td').get()[0]
const nameEl = tr.find('td').get()[1]
const currentPlayersEl = tr.find('td').get()[2]
const monthAvgEl = tr.find('td').get()[3]
const monthGainEl = tr.find('td').get()[4]
const monthGainPercentEl = tr.find('td').get()[5]
return {
img: `${baseURL}${$(imgEl).find('img').attr('src')}`,
name: $(nameEl).text().replaceAll('\t', '').replaceAll('\n', ''),
link: `${baseURL}${$(nameEl).find('a').attr('href')}`,
currentPlayers: $(currentPlayersEl).text(),
monthAvg: $(monthAvgEl).text(),
monthGain: $(monthGainEl).text(),
monthGainPercent: $(monthGainPercentEl).text()
}
})
const games = result.filter(game => game.name !== '')
return games
}
function buildPreview(game: Game) {
const getColor = (text: string) => {
if(text.startsWith('-')) {
return 'text-red-500'
} else if (text.startsWith('+')) {
return 'text-green-500'
} else {
return ''
}
}
return `
<div class="p-5 prose prose-sm">
<img class="w-full rounded" src="${game.img}"/>
<h2>${game.name}</h2>
<div class="w-full h-10 flex flex-row items-center font-bold justify-start uppercase">
Current Players: ${game.currentPlayers}
</div>
<div class="w-full h-10 flex flex-row items-center font-bold justify-start uppercase">
30-Day Avg.: ${game.monthAvg}
</div>
<div class="w-full h-10 flex flex-row items-center font-bold justify-start uppercase ${getColor(game.monthGain)}">
30-Day Gain: ${game.monthGain}
</div>
<div class="w-full h-10 flex flex-row items-center font-bold justify-start uppercase ${getColor(game.monthGainPercent)}">
30-Day % Gain: ${game.monthGainPercent}
</div>
</div>
`
}
function buildResult(game: Game): Choice {
return {
name: game.name,
value: game.link,
img: game.img,
preview: buildPreview(game)
}
}
const keyword = await arg('Keyword')
const games = await searchGames(keyword)
const game = await arg('Select game', games.map(game => buildResult(game)))
open(game)
// Name: Cron Builder
// Description: Prompts user for desired intervals, creates a cron schedule based on user input, and describes it
// Author: Ricardo Gonçalves Bassete
import "@johnlindquist/kit"
import cronstrue from 'cronstrue';
const commonValues = [
'------------------------------',
'* = any value',
', = value list separator',
'- = range of values',
'/ = step values',
]
const minuteValues = [
"Allowed Values = 0 - 59",
...commonValues,
]
const hourValues = [
"Allowed Values = 0 - 23",
...commonValues,
]
const dayMonthValues = [
"Allowed Values = 1 - 31",
...commonValues,
]
const monthValues = [
"Allowed Values = 1 - 12",
...commonValues,
]
const dayWeekValues = [
"Allowed Values = 0 - 6",
'------------------------------',
"0 = Sunday",
"1 = Monday",
"2 = Tuesday",
"3 = Wednesday",
"4 = Thursday",
"5 = Friday",
"6 = Saturday",
...commonValues
]
const minute = await arg({
placeholder: 'Minute interval, default is *',
alwaysOnTop: true,
hint: minuteValues.join('\n')
}).then(input => input === '' ? '*' : input)
const hour = await arg({
placeholder: 'Hour interval, default is *',
alwaysOnTop: true,
hint: hourValues.join('\n')
}).then(input => input === '' ? '*' : input)
const dayMonth = await arg({
placeholder: 'Day of the month interval, default is *',
alwaysOnTop: true,
hint: dayMonthValues.join('\n')
}).then(input => input === '' ? '*' : input)
const month = await arg({
placeholder: 'Month interval, default is *',
alwaysOnTop: true,
hint: monthValues.join('\n')
}).then(input => input === '' ? '*' : input)
const dayWeek = await arg({
placeholder: 'Day of the week interval, default is *',
alwaysOnTop: true,
hint: dayWeekValues.join('\n')
}).then(input => input === '' ? '*' : input)
const result = `${minute} ${hour} ${dayMonth} ${month} ${dayWeek}`
await div({
alwaysOnTop: true,
enter: 'Press Enter to paste result',
html: `
<div class="p-5 prose prose-sm">
<h1>${cronstrue.toString(result)}</h1>
<p>${result}</p>
</div>
`,
onSubmit: () => setSelectedText(result)
})

// Name: Chmod Calculator
// Description: Asks the user what permissions to grant to a file/folder and creates a chmod command with those permissions
// Author: Ricardo Gonçalves Bassete
import "@johnlindquist/kit"
const permissions = ['read', 'write', 'execute']
function getValue(permissions: string[]) {
const r = permissions.includes('read') ? 4 : 0
const w = permissions.includes('write') ? 2 : 0
const x = permissions.includes('execute') ? 1 : 0
return r+w+x
}
const ownerPermissions: string[] = await select({
placeholder: 'Owner permissions',
alwaysOnTop: true,
strict: true,
}, permissions)
const groupPermissions: string[] = await select({
placeholder: 'Group permissions',
alwaysOnTop: true,
strict: true,
}, permissions)
const publicPermissions: string[] = await select({
placeholder: 'Public permissions',
alwaysOnTop: true,
strict: true,
}, permissions)
const command = `chmod ${getValue(ownerPermissions)}${getValue(groupPermissions)}${getValue(publicPermissions)}`
setSelectedText(command)

// Name: Clear Downloads Folder
// Description: Lists files and folders within your downloads folder and asks which items you want to remove
// Author: Ricardo Gonçalves Bassete
import "@johnlindquist/kit"
const downloadsFolder = home('Downloads')
const items = await readdir(downloadsFolder)
const itemsToRemove: string[] = await select({
placeholder: 'Select the items you want to remove',
alwaysOnTop: true,
strict: true,
}, items)
const wishToRemove = await arg({
placeholder: 'This will remove all selected items, do you want to continue?',
choices: [
{ name: 'Yes', value: true },
{ name: 'No', value: false }
],
strict: true
})
if(wishToRemove) {
itemsToRemove.forEach(item => {
const itemPath = path.resolve(downloadsFolder, item)
remove(itemPath)
})
}