Feeling of Euphoria (1 Viewer)

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:54
Joined
Jul 9, 2003
Messages
16,282
I've spent the past three evenings pulling together various strands of an idea I had, and tonight it all came together, and I achieved my goal!

I've got that wonderful feeling of euphoria you get when you've achieved something significant. I mention it because it was something that Richard Feynman and Fred Hoyle discussed in this YouTube video during their meeting in the Yorkshire Pennines:


Is that why we program? Is that why we stay up until 3 am? To enter into those solitary and magical moments that enable you to achieve greatness?

It doesn't happen that often. It comes about after extreme effort to dig in and find out where something doesn't work as you expect it to work, and then suddenly, all the bits slide together, and it just works.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:54
Joined
Jul 9, 2003
Messages
16,282
Do go on...

The story starts with another story: my amazing science fiction story. However, it's not really a story, but a collection of disassociated pieces of text in various documents throughout Google Drive.

False starts have made a mockery of the idea of a book. I bought a leading software tool for helping construct books, but we didn't get along.

What do you do? Well, I asked ChatGPT, "Any idea on how I can organise my book?" My digital buddy said, "Yes, create these folders and use them to organize the mess." It gave me a list of folders.

I wondered, can ChatGPT create these folders on Google Drive for me? I asked, and the answer was, "Of course I can." Can you write the code? ChatGPT wrote some Python code which, when run, created all the folders for me. Job done. Not so fast, there's more.

The way I work, I like a note document in each folder. I name it the same as the folder it's in, with "Note" concatenated to it. For example, in a folder named "Resources," I'll have a document in it called "Resources - Notes." I said to ChatGPT, "Can you add such a document to each folder?"

ChatGPT set about creating a Google document with code for each folder, to my specification. But there's a snag: Python code cannot give a document a heading. Chat told me there's a workaround: put the heading at the top of the document body, not in the heading section.

Sorry, that's a no-go for me. I want my heading in the heading section. I want my heading to appear on every page in my document. Talking to ChatGPT, we came up with another idea: have a template document already made with placeholders. A placeholder can go in the heading, so I get my nice heading. A placeholder for the date. A placeholder for the URL of the folder it is within.

I have a blank custom template document, which is copied and put in the various folders as required. Code fills the placeholders with the various information. This worked like a charm. There's an upside as well.

I put in some extra placeholders that enabled me to display information from within the Python code. If I want to check if something is working in the Python code, I can display a message on the document. Quite handy for a programmer.

This first draft was hard-coded. That means the ID of the template document is written in the code. The folder where it was placed was also hard-coded. Not a good solution. How can I replace this hard-coded folder ID with the ID of the folder I want to place the document in?

The folder is displayed in the selected Google Chrome Tab. The URL of the folder is clearly displayed. Drive folder URLs are all the same, except for the ID. Can I capture this URL and extract the Google folder ID? If I could, I could make a document in any folder that is open in a Chrome tab.

I asked ChatGPT if a Chrome extension could extract the URL from the currently opened tab. And it's a yes, and ChatGPT wrote me the code.

I placed the Chrome extension in the bar, across the top of Chrome. Press the button and a message box appears containing the URL from the currently opened tab. A minor success.

ChatGPT? "Yes?" Can you pass that URL into the Python script? No. What? No, you can't. Why not? Because internet things aren't allowed to do things to your computer. It could do something nasty. So, it's blocked. But, said my mate Chatty, there's a workaround. Oh, you clever bugger, I thought.

Transfer the URL into a Python Flask server (which needs to be running). I don't know how on earth this works, but when you pass the URL into the Python Flask server, it also triggers the Python script that creates the document.

I have a Chrome extension which passes the currently opened Chrome tab URL into a Python Flask server. The Python Flask server passes the URL into a Python script. The script extracts the folder ID and makes a copy of the custom Google template document. It places that copy in the folder open in the Chrome tab. All the information I want is there: the heading (name of the Google folder plus "Notes"), the date and time, and the URL of the folder that the Google document is now placed in.

I like that feature. I like to be able to click in the Google document and open the folder it's in.

There's another story: the placeholders.

The placeholders allow me, the programmer, to capture information from the running code. That's a useful thing in itself. I'll discuss that in another blog, if enough people express an interest….
 

Users who are viewing this thread

Top Bottom