Last active
October 30, 2016 20:51
-
-
Save etra0/5fa916f0d3d48f843dc4a53280300f3a to your computer and use it in GitHub Desktop.
Para ver la minuta de la usm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
import time | |
ROJO = "\033[31m{0}\033[0m" | |
VERDE = "\033[92m{0}\033[0m" | |
try: | |
minuta = requests.get('http://www.usm.cl/comunidad/servicio-de-alimentacion/') | |
except: | |
sys.exit(ROJO.format("Time out")) | |
if minuta.status_code != 200: | |
sys.exit(ROJO.format("No se pudo conectar!")) | |
minuta_text = minuta.text.strip().split('\n') | |
leer = False | |
info = [] | |
for linea in minuta_text: | |
if "<table>" in linea: | |
leer = True | |
continue | |
if "</table>" in linea: | |
leer = False | |
continue | |
if leer and linea != '' and "col width=" not in linea and " " not in linea: | |
info.append(linea.strip().replace("<p>", "").replace("</p>", "")) | |
info = "\n".join(info) | |
info = info.strip().split("</td>") | |
info.remove("\n</tr>\n<tr>\n<td><strong>Almuerzos</strong>") | |
for i in range(len(info)): | |
info[i] = info[i].replace("<td>","").replace("<strong>", "").replace("</strong>", "").replace("<tr>", "") | |
weekday = int(time.strftime("%w")) | |
if "-t" in sys.argv and weekday < 6: | |
print (VERDE.format("Hoy") + ": " + info[weekday + 4]) | |
else: | |
for i in range(0, 5): | |
print(VERDE.format(info[i]) + ": " + info[i+5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dice la comida de hoy 😄