Garnet Auto Check In with Selenium

4/10/17 | Brendan Bailey

Today I had my computer log into Garnet for me. For those not familiar with Garnet, it is General Assembly’s attendance system, and according to school policy if you are tardy more than five times you cannot receive the additional career support after course has finished. This policy makes complete sense because if General Assembly is building relationships with potential employers, they at minimum need to convey that their students were at least in class. However, I feel bad for those who get to class early and forget to sign in (It’s almost happened to me a couple of times!).

Garnet Auto Check In

**Click above for video**

The other reason why I picked this project is that I wanted to explore using Selenium. I did a lot browser automation at my previous job with iMacros. I macros are great for those who have little programming experience because you can just click record, and the program will record every action you do until you click stop. If you play the macro, the system will take the exact steps that you recorded. iMacros also generates a script based on what you recorded, which you can modify according to the task you need to accomplish. However, the free version of iMacros has limited flexibility. For example, you cannot implement conditionals or nested for loops. If you would like to have free reign of what you can do in the browser, and have the time to invest in writing the script then Selenium is a good choice.

The script to use this is pretty simple, and below is a walkthrough of the code.

Here I'm importing relevant libraries

In [1]:
from urllib2 import urlopen
import selenium
from selenium import webdriver
import time

Users configure the script to enter the IP Address for their GA location, their GitHub credentials, and their course title.

In [ ]:
#Configure the script
config_ip = "50.200.196.50" #Your General Assembly Campus's IP Address
config_username = #Your Github Username
config_password = #Your Github Password
config_link_text = "DC DSI 4" #Your course title in Garnet

This function confirms that the user's current IP address is the same as their GA campus's IP address. According to our instructors, the system does check where people are logging in from.

In [2]:
def right_ip(ga_ip):
    if urlopen('https://ip.42.pl/raw').read() == ga_ip:
        return True
    else:
        print "Incorrect IP Address"
        return False

The function below takes the users Github credentials and course name. It then opens a web browser, signs the user into Garnet, and clicks the sign in link.

In [3]:
def click_link(url, ga_username, ga_password, link_text):
    #Pull Up Firefox
    driver = webdriver.Firefox()
    driver.get(url)

    #Github Sign In - They made this hard to automate...
    driver.find_element_by_link_text("Sign in with Github").click()
    time.sleep(3)
    username = driver.find_element_by_name("login")
    password = driver.find_element_by_name("password")
    username.send_keys(ga_username)
    password.send_keys(ga_password)
    driver.find_element_by_name("commit").click()

    #Click DSI 4 Link
    time.sleep(5)
    driver.find_element_by_link_text(link_text).click()

    #Click on check in
    time.sleep(5)
    driver.find_element_by_xpath("/html/body/main/form[1]").submit()
    print "Signed in to Garnet!"

The final two lines executes the functions above. The first function is executed, and if the user has the same IP address as General Assembly, the script will sign the user into Garnet. If not, then the script will print to console that the user does not have the correct IP address to sign in.

In [ ]:
if right_ip(config_ip) is True:
    click_link("https://garnet.wdidc.org/", config_username, config_password, config_link_text)