Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

speiseplan.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. import re
  3. from string import Template
  4. import urllib
  5. try:
  6. from BeautifulSoup import BeautifulSoup
  7. except ImportError:
  8. from bs4 import BeautifulSoup
  9. def excludeAllergens(html_soup):
  10. exclude_allergens = html_soup.find_all("sup")
  11. for element in exclude_allergens:
  12. element.extract()
  13. def excludeForm(html_soup):
  14. excludeForm = html_soup.find('form')
  15. excludeForm.extract()
  16. def excludeImages(html_soup):
  17. exclude_img = html_soup.find_all("img")
  18. for element in exclude_img:
  19. element.extract()
  20. if __name__ == '__main__':
  21. url = 'https://www.werkswelt.de/?id=mohm'
  22. page = urllib.request.urlopen(url).read().decode()
  23. correctedPage = re.sub('/br', 'br', page)
  24. html_soup = BeautifulSoup(correctedPage, features='html.parser')
  25. parsed_html = html_soup.findAll('body')
  26. #parsed_html = html_soup.body.html.body
  27. excludeForm(parsed_html[1])
  28. excludeAllergens(parsed_html[1])
  29. excludeImages(parsed_html[1])
  30. template = Template('<html>\n<div style="background:black; color:white">\n$parsed_html\n</div>\n</html>')
  31. # write html-file
  32. with open("speiseplan.html", "w") as file:
  33. file.write(template.substitute(parsed_html=parsed_html[1].div.decode_contents()))