Hacker News new | ask | show | jobs
by oulipo 536 days ago
Cool project!

Seems a bit complex though, compared to doing a shell script showing a notification or sending yourself an email each morning when you open it?

Or just doing a light script on val.town?

For instance this could be an example val.town script that does something similar (just need to bind to a data source for the dictionary)

    import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
    import { OpenAI } from "https://esm.town/v/std/openai";
    import { email } from "https://esm.town/v/std/email";
    
    // Dutch words database
    const dutchWords = [
      { word: "boek", translation: "book" },
      { word: "huis", translation: "house" },
      { word: "boom", translation: "tree" },
      { word: "water", translation: "water" },
      { word: "kat", translation: "cat" },
      { word: "hond", translation: "dog" },
      { word: "appel", translation: "apple" },
      { word: "tafel", translation: "table" },
      { word: "school", translation: "school" },
      { word: "fiets", translation: "bicycle" }
    ];
    
    export default async function generateDutchWordLearning() {
      const KEY = new URL(import.meta.url).pathname.split("/").at(-1);
      const openai = new OpenAI();
    
      // Ensure SQLite table exists
      await sqlite.execute(`
        CREATE TABLE IF NOT EXISTS ${KEY}_dutch_words (
          word TEXT PRIMARY KEY,
          translation TEXT,
          example TEXT,
          timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
        )
      `);
    
      // Fetch words not previously used
      const usedWords = await sqlite.execute(`
        SELECT word FROM ${KEY}_dutch_words
      `);
    
      const availableWords = dutchWords.filter(
        w => !usedWords.rows.some(row => row.word === w.word)
      );
    
      if (availableWords.length < 3) {
        // Reset if we've used all words
        await sqlite.execute(`DELETE FROM ${KEY}_dutch_words`);
        availableWords = dutchWords;
      }
    
      // Randomly select 3 unique words
      const selectedWords = [];
      for (let i = 0; i < 3; i++) {
        const randomIndex = Math.floor(Math.random() * availableWords.length);
        selectedWords.push(availableWords.splice(randomIndex, 1)[0]);
      }
    
      // Generate example sentences with ChatGPT
      const wordDetails = await Promise.all(selectedWords.map(async (wordObj) => {
        const exampleResponse = await openai.chat.completions.create({
          model: "gpt-4o-mini",
          messages: [{
            role: "user", 
            content: `Geef een voorbeeld zin met het woord "${wordObj.word}" in het Nederlands.`
          }]
        });
    
        const example = exampleResponse.choices[0].message.content || "Geen voorbeeld gevonden";
    
        // Store in database
        await sqlite.execute(`
          INSERT INTO ${KEY}_dutch_words (word, translation, example) 
          VALUES (?, ?, ?)
        `, [wordObj.word, wordObj.translation, example]);
    
        return { ...wordObj, example };
      }));
    
      // Prepare HTML email
      const htmlContent = `
        <html>
          <body>
            <h2>Dutch Word Learning </h2>
            ${wordDetails.map(w => `
              <div>
                <h3>${w.word} (${w.translation})</h3>
                <p><em>Example:</em> ${w.example}</p>
              </div>
            `).join('')}
          </body>
        </html>
      `;
    
      // Send email
      await email({
        subject: "Your Daily Dutch Words ",
        html: htmlContent,
        text: wordDetails.map(w => 
          `${w.word} (${w.translation}): ${w.example}`
        ).join('\n')
      });
    
      return wordDetails;
    }
2 comments

I wouldn't argue that it's rather complex for what it does. The reason I still did it this way was that I want to get them automated, without doing anything manually. Even if I would need to just open my laptop, or run a script once, I think I would just stop at one point, and I don't think it would ever become a habit. Are there other tools that could probably get this project done with less complexity? Probably, but I have the pride of an engineer and wanted to brush up on my Terraform ;)
the val.town way doesn't require you to open your laptop... it's just "lighter" than having a whole terraform infra
Is that code from an LLM?
Based on the style with comments above each block it seems very likely to be from chatgpt or claude
Yeah.

Kind of weird we have people submitting GPT samples to people that likely have GPT themselves and could ask it for one if that's what they wanted.

But then plenty of people link google searches as though that makes sense.

yes, basically just asked the val.town AI bot to write it, probably need a few bugfixes here and there, but the idea was to show that there are services that do that in 50 lines of codes, rather than spanning a big infra