Skip to content

Instantly share code, notes, and snippets.

@victor141516
Created January 25, 2017 10:34
Show Gist options
  • Save victor141516/a451a80c479473d3b2e938e3f5be6fd7 to your computer and use it in GitHub Desktop.
Save victor141516/a451a80c479473d3b2e938e3f5be6fd7 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import sys
import requests
import time
uah_user = ""
uah_password = ""
telegram_bot_api_key = ""
telegram_channel = ""
subject = "ELECTRÓNICA"
def login(driver, uah_user, uah_password):
driver.get("https://portal.uah.es/portal/page/portal/GP_EPD/pg_login")
driver.delete_all_cookies()
elem = driver.find_element(By.NAME, "ssousername")
elem.clear()
elem.send_keys(uah_user)
elem = driver.find_element(By.NAME, "password")
elem.clear()
elem.send_keys(uah_password)
elem = driver.find_element(By.XPATH, "(//INPUT[@type='BUTTON'][@value='OK'])")
elem.click()
def get_nota(driver, subject):
driver.get("https://portal.uah.es/portal/page/portal/GP_ACADEMICO/PG_Notas")
driver.get_screenshot_as_file('/Users/victor141516/Downloads/foo.png')
try:
nota = driver.find_element(By.XPATH, "//*[text()='" + subject + "']/parent::*/td[6]").text.replace(',','.')
except Exception as e:
return -2
try:
return float(nota)
except Exception as e:
return -1
driver = webdriver.PhantomJS()
nota = -2
while nota < 0:
time.sleep(60)
if nota == -2:
try:
login(driver, uah_user, uah_password)
except Exception as e:
continue
nota = get_nota(driver, subject)
driver.close()
requests.get('https://api.telegram.org/bot' + telegram_bot_api_key + '/sendMessage?chat_id=' + telegram_channel + '&text=' + str(nota))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment