Monthly Archives: September 2012

Selenium User Extension: Unknown Command

So at work we are setting up a selenium RC 1 grid. We decided to use RC1 and not web drivers since we can setup user-extensions to create locations and custom actions for our QA team.

We’ve slowly got the grid running with our python test cases running the client drivers. Somewhere in the setup (we still don’t know the cause) our user extensions weren’t working anymore. We would receive the Unknown Command error from the selenium nodes. Testing on the ide confirmed we had the user extension correctly written because they would run in the ide.

After some research I came across Stuvel’s blog post about the same issue. For some reason this fix didn’t work for me. So after some digging around in the selenium source I came up with a slight modification to Stuvel’s fix, but the concept of what is happening is the same.

1
2
3
4
5
//This is a fix to get the user-extensions working for RC.  The check is to prevent a runtime error in the IDE
//since the IDE does not contain command factory.
if(this['commandFactory']){
    commandFactory.registerAll(selenium);
}

Place the above code at the bottom of your user extension file. Hopefully this works for you as it did for me. Let me know how it goes in the comments.

Getting Rain Fall Inches in Python

Rain Study 2 © by amandabhslater

Currently my wife and I are working on the house and decided to redo the front and back yards; they are what we love most about our house. We hired someone who knows a lot more about plants to help pick out what to plant and where. She has come up with some fun and neat ideas including lots of ferns, which I love. Georgia gets lots of rain in the fall, winter, and spring but summers can be very hit or miss. So our landscape architect gave me a rule for watering.

If the rainfall has been less than 1 inch in the last three days then water the garden. Wait three more days and repeat the same logic.

As soon as she told me this algorithm lights went off that this would work as great as a simple script that email’s me to water my new garden. I am also a new owner of a raspyberry pi (details later), which will work perfectly to do the monitoring and notifying.

Here is what I am currently thinking for the setup:

Python 2.7 using the following library’s

Here is what I have coded so far:

?Download raingauge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
Created on Sep 12, 2012
 
@author: csimpson
'''
import urllib2
import sqlite3
import datetime
from bs4 import BeautifulSoup
from bs4 import SoupStrainer
 
MORNINGSIDE_STATION = 'KGAATLAN54'
BASE_URL = 'http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID='
 
def fetchRainfall(station):
    print 'Retrieving rainfall from ' + station
    weatherData = urllib2.urlopen(BASE_URL+station)
    html = weatherData.read()
 
    onlyTables = SoupStrainer(class_="contentData") 
 
    soup = BeautifulSoup(html.encode("utf8"), "lxml", parse_only=onlyTables)
    contentTable = soup.find(text='Precipitation:')
    contentTable = contentTable.find_parent('tr')
 
    inchStr = contentTable.find(class_='b')
    rainfall = float(inchStr.contents[0].string)
    recordRainFall(rainfall)
 
def recordRainFall(inches):
    date = datetime.date.today()
    iso = date.isoformat()
    print 'Station reporting ' + str(inches) + ' inches on ' + iso
 
    sql = "INSERT INTO Rainfall(Inches, Date) VALUES('"+str(inches)+"','"+str(iso)+"');"
 
    db = sqlite3.connect('rainfall.db')
    db.execute(sql)
    db.commit()
    db.close()     
 
if __name__ == '__main__':
    fetchRainfall(MORNINGSIDE_STATION)

fetchRainfall uses the urllib to get the html page from wunderground.com. I limit my soup parsing to one contentData div on the site since it contains the actual data I care about. From there I found the first “Percipitation:” text node (note the second text node is the months total which is not what I wanted.) From there it was pretty simple the get the parent row and then from the parent dig back down to the reported inch level.

recordRainfall puts the inch level and date into a simple sql database for analysis. Note I configured the db and tables outside this script and if you want to run this example so will you.

This is just the start of the script, but I figured I should post this to give people ideas on how to get daily rain fall levels using python.

Future task include:

  • Setup a github repo
  • Setting up the logic for sending emails
  • Making it generic for all weather stations
  • Install scripts

The above script is current running as a cron job on my macbook at 11:55pm to collect the most recent rainfall levels for that day. I will eventually make it to were I can run the script on the next day, but get the rainfall levels for the previous day. This would allow me to collect the full 24 hours 0-24 data instead of data from 0 – 11:55. In Georgia 5 minutes can really be a 1/4 inch, so it is important.

Let me know what you find out about this script when you play around with it.