Kaushik's Blog

Prompted by a Podcast, I promptly prompted Copilot

In Lex Fridman's latest podcast episode, he suggested leveraging code generation tools to produce code using mainly natural language prompts. I don't think this is a great way to maintain existing code, but it is a fantastic way to hack together something new, quickly.

I wanted to make a collage, day by day, of the podcast episodes I listened to. The app I use, Podcast Addict, stores all of my listening data in a SQLite database. I don't know the first thing about SQLite, but, for my purposes, I didn't really need to.

Table Structure

I used the DBeaver application to explore the database and understand the table structure1.

  1. episodes table
    • Contains all the episodes the app had ever fetched.
    • Of those, the ones I'd completed had a playbackDate > 0.
    • If there is custom artwork per episode, the thumbnail_id column is populated. Otherwise it's -1.
    • Has a podcast_id field that relates to the podcasts table.
  2. podcasts table
    • Contains all the podcasts the app had ever fetched.
    • I can match the podcast ID to the podcast name.
    • Thumbnail ID is populated for each podcast.
  3. bitmaps table
    • All of thumbnail_id values match with an entry in this table.
    • The URL to the image is stored here.

Creating the Query

Seems easy enough. I asked Copilot to make me a query, and it did. I could even iterate on it to get exactly the behaviour I wanted: if an episode didn't have custom artwork, return the podcast's artwork instead.

Prompts to achieve this

Organizing the information

As a NamedTuple

I had Copilot then wrap this query in a Python script that runs the query and packages the results into a NamedTuple. It wrote some neat code to create those records. I particularly liked doing all the data transformations in the from_row class method.

I used the following prompts:

And it generated this code:

# Define a NamedTuple to store the data
class Episode(NamedTuple):
    episode_name: str
    podcast_name: str
    url: str
    date: datetime.date
    duration: datetime.timedelta
    img_url: str

    @classmethod
    def from_row(cls, row):
        episode_name, podcast_name, url, playback_date, duration_ms, img_url = row
        # Convert playback_date to a human-readable date
        date = datetime.datetime.fromtimestamp(playback_date / 1000).date()
        # Convert duration_ms to a time object
        duration = datetime.timedelta(milliseconds=duration_ms)
        return cls(
            episode_name, podcast_name, url, date, duration, img_url
        )


# Convert the rows into Episode objects
episodes = [Episode.from_row(row) for row in rows]

As a DataFrame

Unfortunately, it turned out that I didn't actually need a NamedTuple. Perhaps I shouldn't have been so prescriptive.

Since I wanted to group the data by date, I needed a Pandas DataFrame instead.

These prompts did the trick:

Filtering and Grouping

I also had to filter date ranges since the database had records starting from 2019. While I was at it, might as well have Copilot clean up the code a little bit:

Downloading the images

Easy enough to achieve with these prompts:

Making the collage

Finally, the big one. This took Copilot a little bit, but it got there in the end:

And voila! Here's my collages:

alt text

alt text

alt text

Takeaways

I can sense the trepidation programmers feel at the prospect of Copilot completely replacing human programming. But I don't think that's what's going to happen.

In this case, I got a sweet little thing made in a couple of hours that I never would've tried doing in the first place. Without Copilot, I would've had to:

None of those individual things is particularly challenging. I could do any of them by hand. But I would've needed to figure each piece out, one by one, and put them all together.

All things considered, I ended up building something. It's local, it's for myself, but it's real and it works 2. That, I think, is the promise of these AI tools: to empower people to build things.


  1. This link helped me make sense of Podcast Addict's table structure.

  2. And if you're interested in looking at Copilot's handiwork, look here.