Skip to content

Instantly share code, notes, and snippets.

@slowkow
Created May 3, 2021 01:32
Show Gist options
  • Save slowkow/7683194f51efaebc7ee16b59dd4d3848 to your computer and use it in GitHub Desktop.
Save slowkow/7683194f51efaebc7ee16b59dd4d3848 to your computer and use it in GitHub Desktop.
Pay your water bill in Baltimore City
#!/usr/bin/env python3
# pay-water-bill.py
# 2021-05-02
"""
Pay your water bill in Baltimore City
=====================================
Steps:
1. Install Google Chrome: https://www.google.com/chrome/
2. Install Chrome Driver: https://chromedriver.chromium.org/
3. Install Python3 (you might already have it installed)
4. Install Python dependencies: pip install selenium
5. Edit this script with your own information (account number, etc.)
6. Run this script.
After downloading the `chromedriver` executable file, it won't run on macOS
because it is in quarantine. Run this command to disable the quarantine:
xattr -d com.apple.quarantine /Users/username/Downloads/chromedriver
"""
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
CHROMEDRIVER = '/Users/username/Downloads/chromedriver'
GOOGLE_CHROME = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
# Account number for your water bill in Baltimore City.
WATER_ACCOUNT = '110001231234'
# Billing information for our checking account.
CHECKING_ACCOUNT = {
'name': 'Joseph Biden',
'routing': '1234123412',
'account': '1234123412',
'zipcode': '21212',
'email': 'jbiden@gmail.com'
}
# Launch Google Chrome.
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.binary_location = GOOGLE_CHROME
driver = webdriver.Chrome(executable_path=CHROMEDRIVER, chrome_options=chrome_options)
# Open the home page for paying the water bill.
driver.get('https://cityservices.baltimorecity.gov/water/default.aspx')
# Submit the water bill account number.
id_account = "ctl00_ctl00_rootMasterContent_LocalContentPlaceHolder_txtAccountNumber"
driver.find_element_by_id(id_account).send_keys(WATER_ACCOUNT)
id_button = "ctl00_ctl00_rootMasterContent_LocalContentPlaceHolder_btnGetInfoAccount"
driver.find_element_by_id(id_button).click()
# Start the payment process.
id_button = "ctl00_ctl00_rootMasterContent_LocalContentPlaceHolder_btnPayWithAccount"
driver.find_element_by_id(id_button).click()
# Wait to be redirected to another site.
time.sleep(5)
# Choose to pay with the default option (bank account).
id_button = "ctl00_ContentPlaceHolder1_UC_ViewPayment1_btnSubmit"
driver.find_element_by_id(id_button).click()
# Ok, now we can enter our checking account information.
# Assume the checking account is a "Personal Checking" account.
# Assume Maryland is the correct state for the billing information.
driver.find_element_by_id('paytype_pc_PERSONAL CHECKING').click()
driver.find_element_by_id("bankaccount_name").send_keys(CHECKING_ACCOUNT['name'])
driver.find_element_by_id("routing_number").send_keys(CHECKING_ACCOUNT['routing'])
driver.find_element_by_id("account_number").send_keys(CHECKING_ACCOUNT['account'])
driver.find_element_by_id("accountPostalCode").send_keys(CHECKING_ACCOUNT['zipcode'])
driver.find_element_by_id("emailAddress").send_keys(CHECKING_ACCOUNT['email'])
driver.find_element_by_id("confirmEmailAddress").send_keys(CHECKING_ACCOUNT['email'])
driver.find_element_by_xpath('//*[@id="stateCode_1"]/option[26]').click()
# Submit, wait for the form to refresh.
driver.find_element_by_id('submitBtnId').click()
time.sleep(5)
# Accept the terms and conditions, and submit the payment.
driver.find_element_by_name('termsAndConditions').click()
driver.find_element_by_name('Submit').click()
time.sleep(5)
# For debugging the current page.
# with open('debug.html', 'wt') as f:
# f.write(driver.page_source)
# At the end, save a screenshot with the receipt.
driver.set_window_size(1420, 1920)
driver.save_screenshot("screenshot.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment