In Which I Vibe-Code A Private Library System

Editorial Team
15 Min Read


Once I was a child, I used to be eager about plenty of professions that at the moment are both outdated, or have modified utterly. A type of desires concerned testing books and issues to patrons, and it was targeted totally on pulling out the little card and including a date-due stamp.

After all, when you’ve been to a library within the final 20 years, you recognize that the majority of them don’t work that method anymore. Both the librarian scans particular barcodes, otherwise you verify supplies out your self just by putting them simply so, one by one. Both method, you find yourself with a printed receipt with all of the supplies listed, or an electronic mail. I ask you, what’s the enjoyable in that? At the very least with the previous method, you’d normally get a bookmark for every e-book by means of the due date card.

As I obtained older and spent the higher a part of twenty years in a job that I didn’t precisely vibe with, I critically thought-about turning into a programmer. I took Java, Android, and UNIX lessons on the native junior school, met my now-husband, and ultimately determined I didn’t have the heart to really remedy issues with computer systems. And, not like my husband, I’ve little or no creativeness on the subject of making them do issues.

Quick ahead to final weekend, the one earlier than Thanksgiving right here within the US. I had tossed across the concept of creating a private library system only for funsies a day or so earlier than, and I introduced it up once more. My husband was like, do you wish to make it tonight utilizing ChatGPT? And I used to be like, certain — not realizing what I used to be stepping into apart from the motive force’s seat, excited for the vacation spot.

Vibing On a Saturday Evening

I wish to make a e-book storage system. Are you able to please write a Python script that makes use of SQL Alchemy to make a e-book mannequin that shops these fields: title, creator, yr of publication, style, and barcode quantity?

So principally, I envisioned scanning a e-book’s barcode, pulling it up within the system, after which clicking a button to test it out or verify it again in. I knew stepping into that a few of my books don’t have barcodes in any respect, and a few are obliterated or coated up with school bookstore stickers and what have you ever. Extra on that later.

First, I used to be advised to pip set up sqlalchemy, which I didn’t have. I used to be given a python script referred to as books_db.py to get began. Then I requested for code that appears up all of the books and prints them, which I used to be advised so as to add to the script.

Then issues have been getting critical. I requested it to jot down a Flask server and a fundamental HTML entrance finish for managing the books within the system. I used to be given the Flask server as app.py, after which some templates: base.html for use by all pages, and index.html to view all of the books, and add_book.html to, you recognize, add a brand new e-book. At that time, I obtained to see what it had created for the primary time, and I believed it was pretty for a black and white desk. However it wanted colour.

Yeah, so I’ve been busy including books and never CSS colour key phrases to genres these days.

Test It Out

It is a nice e-book, and it’s best to learn it whether or not you assume you’ve an issue or not.

I requested the chat-thing for options and carried out them piecemeal, as you do when you’re not a masochist. First up was a cute little trash-can delete-button for each entry. Then it was time to arrange the CheckoutEvent. Every of those occasions data which e-book it belongs to, whether or not it’s a check-out or check-in occasion, and the timestamp of stated occasion. After all, then it was time to get the checkout historical past wired to the front-end and accessible by clicking a e-book’s title.

All I actually needed to do was add a historical past path to app.py, replace index.html to make the titles clickable, and create the book_history.html it spat out. Then I had it add the buttons for checking out and in on the brand new checkout historical past web page, which concerned including routes to app.py in addition to a helper to compute the present standing.

Then it had me modify the historical past route and replace book_history.html with the precise buttons. They usually’re tremendous cute, too — there’s slightly crimson e-book on the checkout button, and a inexperienced e-book on the check-in.

Barcode Blues

On the index.html web page, are you able to add a barcode number-based search field? And when the person searches, redirect them to the e-book web page for that barcode?

Now it was time to get the barcode scanning scenario up and operating. I used to be certain sooner or later that ChatGPT would time me out for the night time since I exploit the free mannequin, however it simply saved serving to me do no matter I needed, and even suggesting new options.

I needed the barcode dealing with to be twofold: one, it ought to undoubtedly pull the checkout web page if the e-book exists within the system, and it also needs to undoubtedly go to the book-entering web page if not.

Sure — that’s an important workflow function.
We’ll add a barcode search field to your index web page, and when somebody submits a barcode, the app will:

  1. Search for the e-book by barcode

  2. Redirect straight to that e-book’s checkout historical past web page

  3. Present a pleasant error if the barcode doesn’t exist

I did what it advised me, including a barcode search route in app.py and updating the index() route to make use of it. I then added its barcode search kind to index.html. It was at this level that I had to determine a solution to generate barcodes so I may make little stickers for the books that lack them solely, or have in any other case obliterated ones.

I’ve a reasonably fundamental 1D barcode scanning gun, and it gained’t scan the whole lot. As I quickly discovered, it prefers faux EAN barcodes to UPCs altogether. I lastly discovered a web based barcode generator and set to work, beginning with a listing of randomly-generated numbers I made with Excel. I made a decision I needed all of the faux barcodes to start out with 988, which is shut sufficient to the ISBN 978 lead-in, and occurs to make use of my favourite quantity twice.

We took a quick detour as I requested the chat-thing to make the desk to have ascending/descending sorting by clicking the headers. The method it selected was to maintain issues server-side, and use little arrows to point course. I added sorting logic to app.py and up to date index.html to provide the clickable headers, and in addition determined that the entries needs to be color-coded primarily based on style, and carried out that half with out assist from GPT. Then I obtained drained and went to mattress.

The Lengthy, Darkish Evening of the Solo Programmer

I’m of a sure age and now sleep in two components just about each night time. In truth, I’m scripting this half now at 1:22 AM, blasting Rush (2112) and customarily having an excellent time. However I can inform you that I used to be not having an excellent time after I obtained away from bed to proceed engaged on this library system a few hours later.

There I used to be, getting into books (BEEP!), after I determined I’d had sufficient of that and wanted to attempt including extra options. I cracked my knuckles and requested the chat-thing if it may make it so the search works throughout all fields — title, creator, yr, style, or barcode. It stated, cool, we will try this with a easy SQLAlchemy or_ question. I used to be like, no matter, boss; let’s get loopy.

Are you able to make it so the search works throughout all fields?

It had me import or_ and replace the search route in app.py to interchange the present barcode search route with a generalized search utilizing POST. Then I used to be to replace index.html to rename the enter to a common question. Cool.

However no. I messed it up some how and obtained an error a couple of lacking {% endblock %}. In my GPT historical past it says, I’m confused about step 2. The place do I add it? And possibly I used to be simply drained. I swear I simply threw the code up there on the high prefer it advised me to. However it stated:

Ah! I see precisely why it’s complicated — your present index.html begins with the after which goes straight into the desk. The search kind ought to go proper below the and earlier than the desk.

Then I used to be actually confused. Didn’t I have already got a search field that solely dealt with barcodes? I certain did, over in base.html. So the brand new search code ended up there. Possibly that’s improper. I don’t bear in mind the small print, however I searched the broader web about my two-layer error and obtained the factor again to a working state many agonizing minutes later. Boy, was I proud, and relieved that I didn’t need to ask my husband to repair my mistake(s) within the morning. I threw my arms within the air and seemed round for the cats to inform them the excellent news, however in fact, I used to be the one one awake.

Moar Options!

I wasn’t happy. I needed extra. I requested it so as to add a present depend of books within the database and show it towards the highest. After that, it provided so as to add a depend of currently-checked-out vs. obtainable books, to which I stated sure please. Then I needed an creator web page that accepts an creator’s identify and exhibits all books by that creator. I requested for a brand new web page that exhibits all of the books which are checked out. Most lately, I made it so the search field and the column headers persist on scroll.

I’m nonetheless making an attempt to consider options, however for now I’m busy getting into books, typing up check-out playing cards on my IBM Wheelwriter 5, and making use of library pockets to the within again covers of all my books. If you wish to make your personal private library system, I put the whole lot on GitHub.

On the Shoulders of Giants (and Robots)

I couldn’t have performed any of this with out my husband’s prompts and steerage, his capability to name shenanigans on GPT’s code every time warranted, and ChatGPT itself. Though I’ve programmed prior to now, it’s been an excellent very long time since I even printed “Hiya, World” in any language, although I did discover myself recalling an excellent deal about this and that syntax.

If you wish to make an identical sort of area of interest system on your eyes solely, I’d say this could possibly be one solution to do it. Wait, that’s fairly non-committal. I’d say simply go for it. You may have your self and the broader Web to verify errors alongside the way in which, and also you simply may like among the selections it makes in your behalf.

Share This Article