Compare commits

..

No commits in common. "dd368612338ab6f273d4e2efdc73bc2c40ab8210" and "eab71dd49090f072fa473821b37d60a1f2f5d3e6" have entirely different histories.

3 changed files with 2 additions and 175 deletions

View File

@ -1,34 +0,0 @@
import sys
import requests
import lxml.html
base_url = "https://en.wikipedia.org/"
if len(sys.argv) >= 2:
url = base_url + sys.argv[1]
else:
url = "https://en.wikipedia.org/wiki/Python_(programming_language)"
resp = requests.get(url)
see_also = []
if resp.status_code == 200:
html = resp.text
#print(html[:100])
tree = lxml.html.fromstring(html)
see_also_heading = tree.xpath("//span[@id='See_also']")[0].getparent()
for sibling in see_also_heading.itersiblings():
hrefs = sibling.xpath("li/a")
for href in hrefs:
title = href.get("title")
see_also_url = href.get("href")
#print(title, see_also_url)
## TODO
## Parse URL from command line with urlllib.parse.urlsplit()
## and concatenate base URL and relative URL from link
see_also.append((title, base_url + see_also_url))
print(see_also)

View File

@ -24,13 +24,11 @@ try:
print(f"Warning: could not parse line {i+1}: {exc}")
else:
try:
# split raw data at commas
items = [int(item.strip()) for item in raw_data.split(",")]
items = [int(item) for item in raw_data.split(",")] # split raw data at commas
except (ValueError, TypeError) as exc:
print(f"Warning: could not parse data on line {i+1}: {exc}")
else:
data[name.strip()] = items
data[name.strip()] = items
except OSError as exc:
print(f"Could not open file {filename}: {exc}")

View File

@ -1,137 +0,0 @@
# Aufgabe 1
fp = open("../uebungen/employee_skills.txt", encoding="utf-8")
contents = fp.read()
fp.close()
print("Länge:", len(contents))
print("-" * 50)
# Alternativ:
with open("../uebungen/employee_skills.txt") as fp:
contents = fp.read()
print(contents)
print("-" * 50)
# Aufgabe 2
with open("../uebungen/employee_skills.txt") as fp:
i = 0
for line in fp:
line = line.strip()
if not line:
continue
i += 1
print("Nicht leere Zeilen:", i)
print("-" * 50)
# Aufgabe 3
employees = []
with open("../uebungen/employee_skills.txt") as fp:
for line in fp:
if not line.strip():
continue
name = line.split(":")[0].strip()
employees.append(name)
employees.sort()
for name in employees:
print(name)
print("-" * 50)
# Aufgabe 4
employee_salaries = {}
with open("../uebungen/salaries.txt") as fp:
for line in fp:
if not line.strip():
continue
name, salary = line.strip().split(":", 1)
name = name.strip()
salary = int(salary.strip())
employee_salaries[name] = salary
print("Min. Gehalt:", min(employee_salaries.values()))
print("Max. Gehalt:", max(employee_salaries.values()))
print("-" * 50)
# Aufgabe 5
employee_skills = {}
with open("../uebungen/employee_skills.txt") as fp:
for line in fp:
if not line.strip():
continue
name, skills = line.strip().split(":", 1)
name = name.strip()
skills = [item.strip() for item in skills.split(",")]
employee_skills[name] = skills
# Aufgabe 6
employees = {}
for key in employee_salaries:
salary = employee_salaries.get(key, 0)
skills = employee_skills.get(key)
employees[key] = {"skills": skills, "salary": salary}
print("-" * 50)
# Aufgabe 6
employee_salaries = {}
try:
with open("../uebungen/salaries-errors.txt") as fp:
for i, line in enumerate(fp):
# remove whitspace at satrt / end of line
line = line.strip()
# ignore empty / whitespace-only lines
# and comment lines
if not line or line.startswith("#"):
continue
try:
name, salary = line.strip().split(":", 1)
except ValueError as exc:
print(f"Warning: could not parse line {i+1}: {exc}")
else:
name = name.strip()
try:
salary = salary.strip()
salary = salary.strip("$€")
salary = int(salary)
except (ValueError, TypeError) as exc:
print(f"Warning: could not parse data on line {i+1}: {exc}")
else:
employee_salaries[name] = salary
except FileNotFoundError as exc:
print(f"Could not open file: {exc}")
print("Min. Gehalt:", min(employee_salaries.values()))
print("Max. Gehalt:", max(employee_salaries.values()))
print("-" * 50)