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
#!/usr/bin/env python3 | |
import roman | |
from os import system | |
from requests import get | |
from sys import argv, platform | |
from time import sleep | |
def notify(s, say=False): | |
notif_command = "osascript -e 'display notification \"{}\" with title \"OM\"'" | |
if platform != 'darwin': | |
print(s) | |
else: | |
if say: | |
system("say '{}'".format(s)) | |
else: | |
system(notif_command.format(s)) | |
def getcurrentedition(): | |
d = get("http://om.edu.pl").content.decode().split('\n') | |
for s in d: | |
if s.startswith(' <h2>Terminarz'): | |
return str(roman.fromRoman(s[18:-8])) | |
if len(argv) != 4: | |
print("usage: python3 kwalifikacje.py etap olimpiada \"pełna-nazwa-szkoły\"") | |
print(" etap numer etapu - 2 lub 3") | |
print(" olimpiada arabski numer olimpiady") | |
print(" 0 oznacza obecną") | |
print(" -k znaczy k-tą od końca") | |
print(" \"pełna-nazwa-szkoły\" wpisać pełną podawaną nazwę szkoły w cudzysłowie") | |
exit(-1) | |
if argv[1] == '2': | |
etap = '2-dopuszczeni' | |
elif argv[1] == '3': | |
etap = 'finalisci' | |
else: | |
print("zły numer etapu") | |
exit(-1) | |
olimpiada = getcurrentedition() | |
if argv[2] == '0': | |
pass | |
elif int(argv[2]) > 0: | |
if argv[2] > olimpiada: | |
pass | |
else: | |
olimpiada = argv | |
elif int(argv[2]) < 0: | |
olimpiada = str(int(olimpiada) + int(argv[2])) | |
else: | |
print("zły numer olimpiady") | |
exit(-1) | |
szkoła = "<td>{}</td>".format(argv[3]) | |
url = "http://om.edu.pl/?q={}-{}".format(olimpiada, etap) | |
while True: | |
r = get(url) | |
if r.ok: | |
text = r.content.decode().split('\n') | |
notify("Lista dopuszczonych opublikowana") | |
notify("Dostali się:", True) | |
ibegin = text.index(' <!-- main content -->') | |
zakw = [] | |
for i in range(ibegin, len(text) - 4): | |
if text[i] == szkoła: | |
zakw.append("{} {}".format(text[i-3][4:-5], text[i-2][4:-5])) | |
for i in zakw: | |
notify(i, True) | |
break | |
sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment