mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add app store genres as app tags
This commit is contained in:
parent
99df3d0e8f
commit
7330018f94
2 changed files with 142 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import slugify from 'slugify'
|
|||
import axios from 'axios'
|
||||
|
||||
import statuses, { getStatusName } from './statuses'
|
||||
import appStoreGenres from './app-store/genres.js'
|
||||
import parseDate from './parse-date'
|
||||
import { eitherMatches } from './matching.js'
|
||||
import { getAppEndpoint } from './app-derived'
|
||||
|
|
@ -98,6 +99,41 @@ const lookForLastUpdated = function (app, commits) {
|
|||
return null
|
||||
}
|
||||
|
||||
// Fetch list of genres for each bundle
|
||||
async function fetchBundleGenres () {
|
||||
const genresJsonUrl = `${process.env.VFUNCTIONS_URL}/app-store/listings-sheet?fields=bundleId,genreIds`
|
||||
|
||||
return await axios.get( genresJsonUrl )
|
||||
.then( response => {
|
||||
return new Map( response.data.apps )
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.warn('Error fetching bundle genres', error)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function generateTagsFromGenres( bundleId, bundleGenres ) {
|
||||
// If we don't have this bundleID
|
||||
// then return empty
|
||||
if ( !bundleGenres.has( bundleId ) ) return []
|
||||
|
||||
const genres = new Set()
|
||||
|
||||
bundleGenres.get( bundleId ).split(',').forEach( genreId => {
|
||||
if ( !appStoreGenres.hasOwnProperty(genreId) ) {
|
||||
console.warn('Not known genre ID', genreId)
|
||||
}
|
||||
|
||||
appStoreGenres[genreId].forEach( genreName => {
|
||||
genres.add(genreName)
|
||||
})
|
||||
})
|
||||
|
||||
return genres
|
||||
}
|
||||
|
||||
|
||||
export default async function () {
|
||||
|
||||
|
|
@ -113,6 +149,7 @@ export default async function () {
|
|||
// Save commits to file just in case
|
||||
// await fs.writeFile('./commits-data.json', JSON.stringify(commits))
|
||||
|
||||
const bundleGenres = await fetchBundleGenres()
|
||||
|
||||
const scanListMap = new Map()
|
||||
|
||||
|
|
@ -154,10 +191,15 @@ export default async function () {
|
|||
href: 'https://doesitarm.com/apple-silicon-app-test/',
|
||||
})
|
||||
|
||||
// console.log('appScan', appScan)
|
||||
|
||||
const tags = generateTagsFromGenres( appScan.bundleIdentifier, bundleGenres )
|
||||
|
||||
// Add to scanned app list
|
||||
scanListMap.set( appSlug, {
|
||||
name: appName,
|
||||
aliases: appScan['aliases'],
|
||||
bundleId: appScan.bundleIdentifier,
|
||||
status: statusName,
|
||||
lastUpdated: parseDate( appScan['Date'] ),
|
||||
// url,
|
||||
|
|
@ -172,6 +214,7 @@ export default async function () {
|
|||
category: {
|
||||
slug: 'uncategorized'
|
||||
},
|
||||
tags,
|
||||
relatedLinks
|
||||
})
|
||||
})
|
||||
|
|
@ -236,14 +279,27 @@ export default async function () {
|
|||
|
||||
const [ name, url ] = link.substring(1, link.length-1).split('](')
|
||||
|
||||
let bundleId = null
|
||||
let tags = []
|
||||
|
||||
// Search for this app in the scanList and remove duplicates
|
||||
scanListMap.forEach( ( scannedApp, key ) => {
|
||||
|
||||
for ( const alias of scannedApp.aliases) {
|
||||
for ( const alias of scannedApp.aliases ) {
|
||||
// console.log( key, alias, name, eitherMatches(alias, name) )
|
||||
|
||||
if ( eitherMatches(alias, name) ) {
|
||||
console.log(`Removing ${alias} from scanned apps`)
|
||||
// If we don't have a bundleId yet
|
||||
// Set this app's bundleId
|
||||
if ( bundleId === null ) { bundleId = scannedApp.bundleId }
|
||||
|
||||
// Merge this scanned app's tags into the matching app
|
||||
tags = Array.from(new Set([
|
||||
...tags,
|
||||
...scannedApp.tags
|
||||
]))
|
||||
|
||||
console.log(`Merged ${alias} (${scannedApp.bundleId}) from scanned apps into ${name} from README`)
|
||||
scanListMap.delete( key )
|
||||
}
|
||||
}
|
||||
|
|
@ -285,15 +341,22 @@ export default async function () {
|
|||
appList.push({
|
||||
name,
|
||||
status,
|
||||
bundleId,
|
||||
lastUpdated,
|
||||
// url,
|
||||
text,
|
||||
slug: appSlug,
|
||||
endpoint,
|
||||
category,
|
||||
tags,
|
||||
// content: token.content,
|
||||
relatedLinks
|
||||
relatedLinks,
|
||||
})
|
||||
|
||||
|
||||
// if ( tags.length > 1 ) {
|
||||
// console.log('tags', name, bundleId, tags)
|
||||
// }
|
||||
}
|
||||
|
||||
// appList[categorySlug]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue