SUPL MKII.b
--

This is a better version of my supl script, which instead of having you write the input, detects if you press the key. It also clears the screen every time you choose one of the menu options. Sadly this functionality isnt supported by trinket.io, so thats why i only share the source code.



import urllib.request
import urllib.parse
import re
import datetime
import calendar
import os
import platform
import keyboard
if platform.system() == "Windows":
    platform = "cls"
else:
    platform = "clear"
def clear():
    os.system(platform)
def menu():
    print("")
    print("#######################")
    print("#1. refresh           #")
    print("#2. next day          #")
    print("#3. previous day      #")
    print("#4. exit program      #")
    print("#######################")
def replacediacritic(targetlist, replacewhat, withwhat):
    for i in range(len(targetlist)):
        if replacewhat in targetlist[i]:
            targetlist[i] = targetlist[i].replace (replacewhat,withwhat)
def replace_diacritics_list(targetlist, *positional_parameters, **keyword_parameters):
    replacediacritic(targetlist, "\\\\xe1", "�")
    replacediacritic(targetlist, "\\\\xe8", "�")
    replacediacritic(targetlist, "\\\\xc8", "�")
    replacediacritic(targetlist, "\\\\x9a", "�")
    replacediacritic(targetlist, "\\\\xf8", "�")
    replacediacritic(targetlist, "\\\\xed", "�")
    replacediacritic(targetlist, "\\\\xe9", "�")
    replacediacritic(targetlist, "\\\\xec", "�")
    replacediacritic(targetlist, "\\\\x8a", "�")
    replacediacritic(targetlist, "\\\\xf8", "�")
    replacediacritic(targetlist, "\\\\xf9", "�")
    replacediacritic(targetlist, "\\\\n*", "\n*")
    replacediacritic(targetlist, "\\\\n", "")
    replacediacritic(targetlist, "\\\\xfd", "�")
    replacediacritic(targetlist, "\\\\x9e", "�")
    replacediacritic(targetlist, "\\\\xdd", "�")
    replacediacritic(targetlist, "\\\\xda", "�")
    if ('optional' in keyword_parameters):
        replacediacritic(targetlist, "1.hod", "\n 1.hod")
        replacediacritic(targetlist, "2.hod", "\n 2.hod")
        replacediacritic(targetlist, "3.hod", "\n 3.hod")
        replacediacritic(targetlist, "4.hod", "\n 4.hod")
        replacediacritic(targetlist, "5.hod", "\n 5.hod")
        replacediacritic(targetlist, "6.hod", "\n 6.hod")
        replacediacritic(targetlist, "7.hod", "\n 7.hod")
        replacediacritic(targetlist, "8.hod", "\n 8.hod")
        replacediacritic(targetlist, "9.hod", "\n 9.hod")
def checkweekday():
    global day
    global weekday
    if weekday == 6:
        print("today aint school")
        print("displaying supl for monday")
        day = day + 2
        weekday = 1
    elif weekday == 7:
        print("no school yet, but tommorow")
        print("displaying supl for monday")
        day = day + 1
        weekday = 1
def checkleapyear(inputyear):
    if calendar.isleap(inputyear):
        return 1


alldate = datetime.date.today()

global day
global month
global year
global weekday

day = alldate.day
month = alldate.month


weekday = datetime.date.isoweekday(alldate)

year = alldate.year
checkweekday()


        



values = {'s':'basics',
          'submit':'search'}
data = urllib.parse.urlencode(values)
data = data.encode('utf-8')



def getsupl():
    global day
    global month
    global year
    global weekday
    month = int(month)
    day = int(day)
    year = int(year)
    weekday = int(weekday)
    checkweekday()
    
    if month == (4 or 6 or 9 or 11):
        if day == 31:
            day = 1
            month = month + 1
    
    if month == 2:
        if checkleapyear(year) == 1 and int(day) == 30:
            day = 1
            month = month + 1
        elif day == 29:
            day = 1
            month = month + 1
    
    if day >= 32:
        day = 1
        month = month + 1
    elif day <= 0:
        if month == (4 or 6 or 9 or 11):
            day = 31
        else:
            day = 30
        month = month - 1
    if month >= 13:
        month = 1
        year = + 1
    elif month <= 0:
        month = 12
        year = year - 1
    if (month > 13) or (day > 32):
        print("test" + str(day) + str(month))
        print("an error occured, please send me an error report via email")
        raise SystemExit
    
    
    if day < 10:
        
        day = str(0) + str(day)
    if month < 10:
        
        month = str(0) + str(month)

    if year > 2000:    
        year = int(year) - 2000
    
    url = "http://rozvrh-suplovani.alej.cz/suplovani/su" + str(year) + str(month) + str(day) + ".htm" 

    clear()
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("supl for: " + str(day) + "." + str(month) + ". 20" + str(year))
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print(url)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++")


    
    req = urllib.request.Request(url, data)
    try:
        resp = urllib.request.urlopen(req)
    except:
        print("supl hasnt yet been made for this day or there is no school")
        menu()
        return
    
    respData = resp.read()
    supldataraw = re.findall(r'<p>  O4.A</p>(.*?)<td class="td_supltrid_3" width="11%"><p>  ',str(respData)) #change O4.A to your class
    supldataref = re.findall(r'<p>(.*?)</p>',str(supldataraw))
    supladditional = re.findall(r'<p class="textnormal_3">(.*?)</p>',str(respData))
    supladditional = re.findall(r'>(.*?)<',str(supladditional))
    
    if len(supldataraw) == 0:
        print("No supl today sadly :(")


    replace_diacritics_list(supldataref, optional = 1)
    replace_diacritics_list(supladditional)

    test = " ".join(supldataref)
    additional = " ".join(supladditional)

    print(test)
    print("")
    print(additional)
    menu()
getsupl()
while True:
    
    try:
        
        
        if keyboard.is_pressed('1'):
            getsupl()
        elif keyboard.is_pressed('2'):
            day = int(day) + 1
            weekday = weekday + 1
            
            getsupl()
        elif keyboard.is_pressed('3'):
            day = int(day) - 1
            weekday = weekday - 1
            
            getsupl()
        elif keyboard.is_pressed('4'):
            print("� Jarom�r �m�d 2018")
            raise SystemExit
        
    except ValueError:
        print("You may only enter numbers")
    
 


download script

--
BY JAREK

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------