-
-
Save eiiot/7c3901cc09b3183d4f5b0f9388129cf3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const shlinkExportCSV = Bun.file('orphan_visits.csv'); | |
| const exportText = await shlinkExportCSV.text(); | |
| const exportRows = exportText.split('\n'); | |
| const keys = exportRows[0].split(',').map((key) => | |
| key.slice(1, key.length - 1) | |
| ); | |
| const rowsArray = exportRows.slice(1).map((row) => { | |
| const values = row.split(','); | |
| const obj: Record<string, string> = {}; | |
| keys.forEach((key, index) => { | |
| obj[key] = values[index].slice(1, values[index].length - 1); | |
| }); | |
| return obj; | |
| }); | |
| const visitsByUrl = rowsArray.reduce((acc, visit) => { | |
| const existing = acc.find((v) => v.url === visit.visitedUrl); | |
| if (existing) { | |
| existing.visits += 1; | |
| } else { | |
| acc.push({ | |
| url: visit.visitedUrl, | |
| visits: 1, | |
| }); | |
| } | |
| return acc; | |
| }, [] as { | |
| url: string; | |
| visits: number; | |
| }[]).sort((a, b) => b.visits - a.visits); | |
| // log a markdown table of the top 50 visited URLs | |
| console.log('URL | Visits') | |
| console.log('--- | ------') | |
| visitsByUrl. | |
| filter((visit) => !visit.url.includes(`.php`) && !visit.url.includes('wp-')). | |
| slice(0, 50).forEach((visit) => { | |
| console.log(`${visit.url.replace('http://bhs.sh', '').replace('http://eliot.sh', '')} | ${visit.visits}`); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment