Skip to content

Instantly share code, notes, and snippets.

@victor141516
Last active January 28, 2017 02:23
Show Gist options
  • Save victor141516/971559377bee6d910a22607016c58ce4 to your computer and use it in GitHub Desktop.
Save victor141516/971559377bee6d910a22607016c58ce4 to your computer and use it in GitHub Desktop.
[uah_user : "Usuario de la universidad"] [uah_password : "Contraseña de la universidad"] [telegram_bot_api_key : "API key de un bot de telegram"] [telegram_channel : "Nombre del canal (@Nombre) en el que el bot anterior tiene permiso para escribir (estoy hay que hacerlo desde la app de telegram)"] [subject : "Nombre de la asignatura tal cual apa…
# -*- 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"
poll_time = 60 #seconds
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)
driver.execute_script("buttonSubmit('OK')")
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:
if nota == -2:
try:
login(driver, uah_user, uah_password)
except Exception as e:
print e
continue
nota = get_nota(driver, subject)
print nota
time.sleep(poll_time)
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