Skip to content

Instantly share code, notes, and snippets.

@enedil
Last active January 16, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enedil/e170b2cc232882a26411 to your computer and use it in GitHub Desktop.
Save enedil/e170b2cc232882a26411 to your computer and use it in GitHub Desktop.
#!/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