Friday, September 19, 2014

Blink(1) first project

I have been waiting for about 3 years to purchase a Blink(1), and just about they are out of stock when I go to purchase one. I stumbled over to the website last week and noticed they were in stock so I quickly scooped one up.
So what is the blink(1) you may be asking. It is a set of ultra bright multicolor LED lights that you plug into USB. Using the control software and some handing scripting skills you can setup a wide variety of rules to make the blink device flash colors. Well wooptie freakin doo Joe, I still don’t understand what is so cool about this.
How about we just take it for a test spin. The blink(1) has its own IFTTT channel. IFTTT is a site that allows you to create a wide array of rules, apply them to various web services and/or web connected devices, and perform tasks. For instance let’s look at one of the  most popular blink recipes (recipes are what the site calls these trigger/action rule sets). You can set the blink(1) to notify you when you get a new email on Gmail.
  • First you activate the Gmail and blink(1) channels in your IFTTT account.
  • Then you can browse the recipes for blink and add the new Gmail rule recipe
  • Once you setup the rule in IFTTT you use the Blink(1) control software to add the rule to the blink
  • You can setup various properties in the Blink(1) control screen that control what colors and patterns to use for the blink notification.
  • Now you sit back and wait for the rule to fire
Ok so Joe the last thing I need is another notification about email. I agree, this is just a simple example about how to use integrate the blink(1) with IFTTT and is just scratching the surface of the capabilities of the device.
Ragweed season is a wonderful time of year at team story’s house. I thought it would be cool to notify using blink(1) when the pollen counts were high. Using Python Web Scraping skills we can find today’s pollen count, determine if the count is high, and then write a color to a text file. Using the Blink(1) control center we setup a rule to monitor a text file for changes. 
  • First I reviewed this web site for web scraping opportunities: http://www.wunderground.com/DisplayPollen.asp?Zipcode=64157
  • I then created the Python Script (pasted below) to parse the page and find today’s pollen count
  • If the pollen count is > 9.0 I want to set the text file with the notification pattern fireengine. There are several built in patterns out of the box, and you can create your own customized patterns.
Check out a video of the high pollen count in action: http://youtu.be/X_fO_9uEX2c. The cool thing about file notifications is that the blink(1) control software keeps track of the file modified date so if the file has not changes it will not fire off the notification. You will only get notified if the file is updated.
Anyway, again this is just scratching the surface. I hope to get more time to explore and play with the new toy in the next few weeks.
Pollen Python Script
from bs4 import BeautifulSoup
import urllib2
import urlparse
import datetime


f = open('C:\Python27\projects\pollen\outfile.txt','w')
errorFile = open('C:\Python27\projects\pollen\error.txt','w')

soup = BeautifulSoup(urllib2.urlopen('http://www.wunderground.com/DisplayPollen.asp?Zipcode=64157').read(), 'html5')
tableStats = soup.find("table", {"class" : "all-clear pollen-table"})
try:
 for row in tableStats.findAll('tr')[1:]:
  col = row.findAll("td", {"class" : "levels"})
  
  
  try:
   if not col[0].p.string:
    levels = "0"
   else: 
    levels = col[0].p.string.strip()
   
   if float(levels) > 9.0: 
    f.write('pattern: "fireengine"')
   
   
  except Exception as e: 
   #errorFile.write (str(e)+'**********'+str(col)+'\n')
   pass

except Exception as e:
 pass

 
f.close 
errorFile.close 

0 comments:

Post a Comment