Downloading attachments from gMail

With a different electric meter than most (because I generate electricity to the grid), I found a subscription service from a group called Smart Meter Texas (https://www.smartmetertexas.com). They email me the previous days’ usage and generation in a CSV file.

Email from Smart Meter Texas

I’ve left these in my gMail with the intention of downloading them and start to pull data from them. Well, me being in IT, I started looking at a way to do that with a program.

A little smart googling and I found a guy on YouTube that walks through this – Jie Jenn – I started up Visual Studio Code and started following what he was doing. I saw quickly that he references a client token file in JSON format. I dug in the description, found how he made a google cloud app that allowed a passthrough to gMail.

So, here’s the steps:

  • Setup a Google Cloud project
  • Add the gMail api
  • create an oAuth page
  • allow my gmail account to access

From here, I could continue on and I got a client token JSON when I setup the oAuth connection. I followed the code and he even has a copy of it on his website. However, I didn’t want to save the attachments in Google Drive, but on my local hard disk. So, I started looking at other pages. I would up with a variant – I didn’t want to download EVERY attachment. So, I added code to filter for the start of the From for the Smart and if the file exists.

Here’s my completed code: GitHub

And here’s my CSVs!

Now, to decide a DB and tool to do the data crunching…

Leave a Comment