🌈️ apply a wallpaper based on the weather outside
0

Configure Feed

Select the types of activity you want to include in your feed.

fix(analyze): catch errors in analyze

Angel Wang (Jun 26, 2026, 6:10 PM -0600) 445733d3 ae613862

+49 -44
+49 -44
src/analyze/analysis.ts
··· 29 29 const imagePath = path.join(imageDir, image.name) 30 30 const stat = await fs.promises.stat(imagePath) 31 31 if (stat.isFile()) { 32 - let output = await $`magick ${imagePath} -colorspace Oklch -kmeans 10 -format "%c" histogram:info:`.then( 33 - (s) => 34 - s.stdout 35 - .split("\n") 36 - .map((substr) => substr.trim()) 37 - .filter((n) => n), 38 - ) as string[] 32 + try { 33 + let output = await $`magick ${imagePath} -colorspace Oklch -kmeans 10 -format "%c" histogram:info:` 34 + .then( 35 + (s) => 36 + s.stdout 37 + .split("\n") 38 + .map((substr) => substr.trim()) 39 + .filter((n) => n), 40 + ) as string[] 39 41 40 - if (output.length < 5) { 41 - // do it again but with more violence 42 - console.log( 43 - `-kmeans 10 of ${image.name} didn't give enough colours, trying again with a higher value...`, 44 - ) 45 - output = await $`magick ${imagePath} -colorspace Oklch -kmeans 40 -format "%c" histogram:info:`.then( 46 - (s) => 47 - s.stdout 48 - .split("\n") // split the output by newlines 49 - .map((substr) => substr.trim()) // trim the whitespace on each line 50 - .filter((n) => n), // and then filter out any blank elements generated 51 - ) 52 - } 53 - 54 - const colours = output.map((entry) => { 55 - const arr = entry.split(" ") 56 - arr.pop() 57 - // [# of pixels, oklab colour, hex code] 58 - return { 59 - pixels: parseInt(arr[0]), 60 - oklab: arr[1].replace(/[()]/g, "").split(","), // (0,0,0) -> Array [0, 0, 0] 61 - hex: arr[2], 42 + if (output.length < 5) { 43 + // do it again but with more violence 44 + console.log( 45 + `-kmeans 10 of ${image.name} didn't give enough colours, trying again with a higher value...`, 46 + ) 47 + output = await $`magick ${imagePath} -colorspace Oklch -kmeans 40 -format "%c" histogram:info:` 48 + .then( 49 + (s) => 50 + s.stdout 51 + .split("\n") // split the output by newlines 52 + .map((substr) => substr.trim()) // trim the whitespace on each line 53 + .filter((n) => n), // and then filter out any blank elements generated 54 + ) 62 55 } 63 - }) 56 + const colours = output.map((entry) => { 57 + const arr = entry.split(" ") 58 + arr.pop() 59 + // [# of pixels, oklab colour, hex code] 60 + return { 61 + pixels: parseInt(arr[0]), 62 + oklab: arr[1].replace(/[()]/g, "").split(","), // (0,0,0) -> Array [0, 0, 0] 63 + hex: arr[2], 64 + } 65 + }) 64 66 65 - colours.sort((a, b) => (b.pixels) - (a.pixels)) 67 + colours.sort((a, b) => (b.pixels) - (a.pixels)) 66 68 67 - const dominantColour = colordx({ 68 - l: Number(colours[0].oklab[0]), 69 - c: Number(colours[0].oklab[1]), 70 - h: Number(colours[0].oklab[2]), 71 - }) 69 + const dominantColour = colordx({ 70 + l: Number(colours[0].oklab[0]), 71 + c: Number(colours[0].oklab[1]), 72 + h: Number(colours[0].oklab[2]), 73 + }) 72 74 73 - analysisOutput.files.push({ path: imagePath, colour: dominantColour.toOklch() }) 75 + analysisOutput.files.push({ path: imagePath, colour: dominantColour.toOklch() }) 74 76 75 - console.log( 76 - `Got ${dominantColour.toOklchString()} as dominant colour of ${image.name}!`, 77 - ) 77 + console.log( 78 + `Got ${dominantColour.toOklchString()} as dominant colour of ${image.name}!`, 79 + ) 78 80 79 - // flush every time we finish analyzing a file, because it just takes so long 80 - fs.writeFile(outputPath, JSON.stringify(analysisOutput, null, 4), (err: Error) => { 81 - if (err) throw new Error(err.message) 82 - }) 81 + // flush every time we finish analyzing a file, because it just takes so long 82 + fs.writeFile(outputPath, JSON.stringify(analysisOutput, null, 4), (err: Error) => { 83 + if (err) throw new Error(err.message) 84 + }) 85 + } catch (e) { 86 + console.warn(`Got error ${e} when attempting to analyze ${imagePath}! Continuing...`) 87 + } 83 88 } 84 89 } 85 90 }