Renew U-Pass Automatically (British Columbia)

I often forget to renew my U-Pass.  It’s the first day of the month, I’d tap my Compass Card and the machine displays “Insufficient Funds”.  Though I’ve paid for it in the beginning of the semester, U-Pass asks us to renew it every month.  What a pain.

The code below automates the process of renewing U-Pass for SFU.  To automate that process, I use Windows Task Scheduler so that it runs the code in the background when my computer is on and is connected to the Internet.

(For UBC and other universities change the “sfu” string to corresponding university abbreviation based on the Upass website.)

The web-scraping API being used here is Selenium.  Note that to have a simulated browser open, you need a webdriver.  (For Google Chrome click here).  If you don’t want a web browser open, use PhantomJS webkit.

import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import Select

# get the path for Chrome Driver
dir = os.path.join(os.path.dirname("__file__"))
chrome_driver_path = dir + "\chromedriver.exe"

# Create a new Chrome session
driver = webdriver.Chrome(chrome_driver_path)

# Use this if you prefer no browser open 
# driver = webdriver.PhantomJS()


# Navigate to Upass-BC Homepage

# Get the University Dropbox
search = Select(driver.find_element_by_id("PsiId"))

# University name

# Arrived at University Website
username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")

# Make sure forms are empty

# Input Username and Password

# Screenshot for debugging purpose under PhantomJS
# driver.save_screenshot('screen3.png')


Due to lack of demand and security issues, I’ve decided not to make any system-based applications out of it.  Feel free to simplify the automation process even further.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s