Skip to main content

Getting Weather Data

I decided that I wanted to ingest some weather data through a different means, this time combining Google API scripts to retrieve the data from the API and another script to connect to the MySQL Database and deposit the data. Both steps are setup on a schedule. 

Setting up the API Call: 

I followed the instructions from the following medium post to create a function in Google Apps Scripts that would call an API for me. I use it to call the weather API website and retrieve the weather data for where I live. 

These 2 things combined import the data into my Google Sheet as per: 


I have then set this up to run on a 4 hour schedule within Google Sheets using one of their triggers. 

Getting the data into MySQL:

So now that I have the data in Google Sheets I want to regularly import this data into a database as it only stores a single row in google sheet, though I could probably get it to persist here as well. Looking at my options with the JDBC drivers available MySQL could work and Snowflake couldn't easily and I didn't really want to use a Keboola Flow several times a day to track this. 

I found the following post and modified the code as needed for my weather data and MySQL credentials. I then set that to run on a schedule as well so the data would get imported into the MySQL database on a regular basis and I can look to integrate it with my parkrun and step data to look for correlations between times / number of steps and the weather. 

Weather API

MySQL Table Script:



Create TABLE weather (
LocationName VARCHAR(100),
LocationRegion VARCHAR(100),
LocationCountry VARCHAR(100),
LocationLat VARCHAR(100),
LocationLon VARCHAR(100),
LocationTzId VARCHAR(100),
LocationLocaltimeEpoch VARCHAR(100),
LocationLocaltime VARCHAR(100),
CurrentLastUpdatedEpoch VARCHAR(100),
CurrentLastUpdated VARCHAR(100),
CurrentTempC VARCHAR(100),
CurrentTempF VARCHAR(100),
CurrentIsDay VARCHAR(100),
CurrentConditionText VARCHAR(100),
CurrentConditionIcon VARCHAR(200),
CurrentConditionCode VARCHAR(100),
CurrentWindMph VARCHAR(100),
CurrentWindKph VARCHAR(100),
CurrentWindDegree VARCHAR(100),
CurrentWindDir VARCHAR(100),
CurrentPressureMb VARCHAR(100),
CurrentPressureIn VARCHAR(100),
CurrentPrecipMm VARCHAR(100),
CurrentPrecipIn VARCHAR(100),
CurrentHumidity VARCHAR(100),
CurrentCloud VARCHAR(100),
CurrentFeelslikeC VARCHAR(100),
CurrentFeelslikeF VARCHAR(100),
CurrentVisKm VARCHAR(100),
CurrentVisMiles VARCHAR(100),
CurrentUv VARCHAR(100),
CurrentGustMph VARCHAR(100),
CurrentGustKph VARCHAR(100),
CurrentAirQualityCo VARCHAR(100),
CurrentAirQualityNo2 VARCHAR(100),
CurrentAirQualityO3 VARCHAR(100),
CurrentAirQualitySo2 VARCHAR(100),
CurrentAirQualityPm25 VARCHAR(100),
CurrentAirQualityPm10 VARCHAR(100),
CurrentAQUsepaindex VARCHAR(100),
CurrentAQGbdefraindex VARCHAR(100));
view raw weatherApi.sql hosted with ❤ by GitHub

Comments

Popular posts from this blog

AWS training cloud academy free course

One of the things I like about this course are the instructors are really clear but also that it provides free labs that allow you to actually sign into AWS and perform some actions to actually create and do things without worrying that you are going to incur a cost.  Today I complete one of the hands on labs.  This was to create a lambda function, in this case it was a very basic python script that was searching a website for a keyword. I then placed this into a schedule and used cloudwatch to create a dashboard that monitored the running of this function. Overall it was a very simple use case but it was also a very simple process to setup.  I don't have much to add to this other than it is well worth signing up to cloud academy for the free training if nothing else, I am tempted, once i have done some more training, to give the paid for option a go to get the full sandboxes. 

AI News

Here’s a concise roundup of the latest AI news from the past couple of days: AI Technology: Friend or Foe? Researchers and experts continue to debate the impact of artificial intelligence. Is it a boon or a threat? The discussion ranges from AI ethics to its potential in various fields. Read more here . 5 Ways Artificial Intelligence Will Change the World by 2050 Futurists predict that AI will revolutionize our lives in the coming decades. From healthcare to transportation, AI is set to transform industries. Explore the possibilities here . How AI Will Transform Businesses in 2023 Business leaders are embracing AI to enhance efficiency, decision-making, and customer experiences. Stay updated on the latest AI trends in the corporate world here . China’s High-Level AI Modules China is pushing the boundaries of AI with modular next-generation systems. These high-level AI technologies promise breakthroughs in fields like robotics, healthcare, and smart cities. Learn more here . The Future ...

Data Cleansing View in Snowflake

For part of one of my free ETLs I am using Zapps to transfer e-mails from Google Sheets and then Keboola to transfer the sheets into my Snowflake database. I am familiar with string searches and cleansing in Oracle and using python but have not had the chance to do this in Snowflake. I wanted to give it a go as a proof of concept if nothing else. There were some difference in functions between Oracle and Snowflake, no INSTR and using POSITION instead and some difference in working with dates / timestamps but overall it was very similar.  The code below is what I ended up using:  I think want to use this to create some overview graphics to allow me to track the success or failure of my ETLs. Assuming the aspects of Retool remain free you can see how much ETL is going on this link .  In case things aren't working, here is a table of the output I am producing.