Skip to content

Instantly share code, notes, and snippets.

@Dunnomix
Created August 29, 2019 16:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dunnomix/351776daf2565e7de677a7db0ba08c44 to your computer and use it in GitHub Desktop.
Save Dunnomix/351776daf2565e7de677a7db0ba08c44 to your computer and use it in GitHub Desktop.
This is used to notify me when my bank balance gets updated. Because the bank won't send me SMS
import json
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
try:
# access default config
config = json.load(open("config.json"))
LAST_KNOWN_BALANCE = config[0]["LAST_KNOWN_BALANCE"]
except:
json.dump([{"LAST_KNOWN_BALANCE": 0.0}], open("config.json", "w"), indent=4)
LAST_KNOWN_BALANCE = 0.0
BANCOLOMBIA_LOGIN_URL = "https://sucursalpersonas.transaccionesbancolombia.com/cb/pages/jsp/home/mainPage.jsp"
BANCOLOMBIA_USERNAME = "<YOUR_BANCOLOMBIA_USERNAME>"
BANCOLOMBIA_PASSWORD = "<YOUR_BANCOLOMBIA_PASSWORD>"
TELEGRAM_TOKEN = "<YOUR_TELEGRAM_TOKEN>"
TELEGRAM_ID = "<YOUR_TELEGRAM_ID>"
# get a selenium
driver = webdriver.Chrome()
# login username
driver.get(BANCOLOMBIA_LOGIN_URL)
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@id='username']"))
).send_keys(BANCOLOMBIA_USERNAME)
driver.find_element_by_xpath("//button[@id='btnGo']").click()
# login password
keyboard = driver.find_element_by_xpath("//table[@id='_KEYBRD']")
for number in BANCOLOMBIA_PASSWORD:
number_xpath = f".//td/div[contains(@id, '{number}')]"
keyboard.find_element_by_xpath(number_xpath).click()
# login
driver.find_element_by_xpath("//input[@id='btnGo']").click()
# the iframe
iframe = driver.find_element_by_xpath("//iframe")
driver.switch_to.frame(iframe)
# account & balance
WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//div[@id='container_account']//div[contains(@class, 'Cell')]")
)
)
data = driver.find_elements_by_xpath(
"//div[@id='container_account']//div[contains(@class, 'Cell')]"
)
acc_type = data[0].text
acc_number = data[1].text
# remove pesos sign
balance = data[2].text.replace("$ ", "")
# remove commans
balance = float(balance.replace(",", ""))
acc = {
"type": acc_type,
"number": acc_number,
"balance": balance
}
if balance != LAST_KNOWN_BALANCE:
# send telegram
msg = f"Hey your Bancolombia account {acc_type} {acc_number} has updated"
msg += f"with new balance: {balance}"
url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/"
url += f"sendMessage?chat_id={TELEGRAM_ID}&text={msg}"
requests.post(url)
# dump new LAST_KNOWN_BALANCE
json.dump([acc], open("config.json", "w"), indent=4)
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment