Alright, today we’re taking another look at how to make your computer talk. This time we will use our VB script to let our PC read out some useful data
NOTE: If you missed part 1, click here
Parsing Data: Few Reliable Sources
The problem with parsing data is that there are few public domain sources that allow you to scrape weather data and other things. If you’re located in the US, you’re in luck, because you won’t have any problems finding the 4-letter ICAO station on NOAA. But even if you’re not in the US, NOAA provides weather data for most major cities around the globe, but it requires more work and string manipulation. In Part 3 we will also provide a solution for Non-US cities
Computer Speaking To You: Tells You Current Date and Weather in Major US Cities
1. Step If you missed the previous tutorial you have to follow this one first or you won’t know what I’m talking about
2. Step Next, we are going to download AutoHotkey from http://www.autohotkey.com/ and Notepad++ from http://notepad-plus-plus.org/
3. Step After installing Autohotkey and Notepad++, download this file
4. Step Right-click on noa.ahk and click on edit with Notepad++. Now replace the
Airport_Code = PHX with your US airport code.
Important: Right now this script will only work for US weather stations. Simply copy the 4-letter ICAO station identifier from http://www.weather.gov/xml/current_obs/ – go to the site, select your state from the dropdown field and click Find, then copy the 4 letter code in brackets.
If you are outside the US you will have to do a lot more coding, testing and what not. NOAA provides data for major cities outside the US! The problem, they are usually using METARS data which you have to parse using Autohotkey (http://aviationweather.gov/adds/metars/)
Computer Still Talking? Test It
Let’s see if our VB script will still work when we add our new text file
0. Copy the noa.ahk to your test folder and double-click the file
1. Step Open your runner.bat file with a notepad editor
2. Step Next, change mytextfile.txt to a fully-qualified path that points directly to the file we just created. Example:
- Keep in mind, PHX_Data.txt will be called differently depending on the weather station code you used in step 4 (above)
3. Step When you double-click the runner.bat (should be on your QuickLaunch toolbar too) then it should talk to you and and tell you something like
Hello - it is currently 16:09 and the temperature is 49.0 degree Fahrenheit
Schedule Autohotkey File
1. Step You can either create an infinite loop in Autohotkey or use the Windows 7 task scheduler to run the AHK file occassionally to get the latest weather and date. An infinite loop often breaks and uses too much memory, we therefore recommend to use the task scheduler
2. Step Follow our guide how to schedule a Powershell script
3. Step You now know how to schedule a script – simply schedule the noa.ahk file to run every X minutes or X hours and it will automatically update the .TXT file with more recent weather data
Alright, that’s it – if you’re outside the US and don’t want to wait for the next update, I recommend to look up the regular expressions functions that Autohotkey uses and how to use them to manipulate the METARS data from http://weather.noaa.gov/pub/data/observations/metar/stations/
@Everyone-outside-US The METARS data is actually easy to read, for the best info read the Wiki entry http://en.wikipedia.org/wiki/METAR
Let’s say the temperatures are minus 2 / and minus 8 dewpoint:
Then it would display something like M02/M08 which you can extract using a Regular Expression (M[(0-9)(0-9)][(0-9)(0-9)])
You can then convert the extracted string to a readable text e.g. minus 2 degree and you’re done.
Some of the things are a little bit advanced – you should learn how to program using Autohotkey and also learn regular expressions, which can cause real headaches ;)
The link to the file noa.ahk doesn’t work anymore! Would you mind re-uploading it please?
Not sure why it didnt work but I reuploaded a file that I found, hopefully this was the correct one, let me know if it works for you
Here’s more on scraping using Autohotkey: