Skip to content

Instantly share code, notes, and snippets.

@hubertgrzeskowiak
Last active October 12, 2015 09:38
Show Gist options
  • Save hubertgrzeskowiak/4007883 to your computer and use it in GitHub Desktop.
Save hubertgrzeskowiak/4007883 to your computer and use it in GitHub Desktop.
Dieses kleine Python Script berechnet anhand der HTML Webseite vom PSSO den eigenen Schnitt und Anzahl der Credits. Es wird die Python Bibliothek BeautifulSoup 4 benötigt.
# encoding: utf-8
import sys
from bs4 import BeautifulSoup
if len(sys.argv) != 2:
print "Dieses Programm benötigt eine html Datei als Parameter!"
print "Speichere deine PSSO Seite, auf der die Noten zu sehen sind"
print "und gib den Namen auf der Kommandozeile als Parameter an."
print "Zum Beispiel: python noten.py rds.html"
sys.exit(1)
html = open(sys.argv[1])
soup = BeautifulSoup(html)
# Finde die richtige Tabelle. sie hat kein summary Attribut.
noten_table = None
for table in soup.find_all('table'):
if "summary" not in table.attrs:
noten_table = table.tbody
break
rows = noten_table.find_all("tr", recursive=False)
# Erste Zeile enthält nur <th>. Wenn wir die Reihe rausschmeißen, haben wir
# nachher leichtere Arbeit.
del rows[0]
# Hier speichern wir Tupel mit Note und Credits Anzahl
noten_und_credits = []
for tr in rows:
# Alle Zellen mit Noten enthalten diese Klasse.
# Überspringe deswegen die Reihen, deren erste Zelle sie nicht hat
if tr.td["class"] != ["tabelle1_alignleft"]:
continue
# Nichtbestandene Prüfungen, sowie Zulassungen geben 0 Credits.
# Wir beachten also nur Zellen die Credits != 0,0 enthalten
zellen = tr.find_all("td")
credits = zellen[7].text.strip().replace(',', '.')
if credits != "0.0":
note = tr.find_all("td")[5].text.strip().replace(',', '.')
noten_und_credits.append((float(note), float(credits)))
note_gesamt = 0.0
credits_gesamt = 0.0
notenschnitt = 0.0
for n, c in noten_und_credits:
credits_gesamt += c
note_gesamt += n
notenschnitt += c*n
notenschnitt /= credits_gesamt
print "Sie haben {} Noten".format(len(noten_und_credits))
print "Insgesamt {} Credits".format(credits_gesamt)
print "Der Schnitt beträgt {}".format(round(notenschnitt, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment