add markdown format

main
lub 3 weeks ago
parent b3d8044157
commit acfdcdca59

@ -7,7 +7,8 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
def scrape(): def scrape():
output = { output = {
'print': '', 'print': '',
'digital': '' 'digital': '',
'markdown': ''
} }
overview_url = 'https://gruene-hohenlohe.de/kalender' overview_url = 'https://gruene-hohenlohe.de/kalender'
@ -28,38 +29,66 @@ def scrape():
output['print'] += date output['print'] += date
output['print'] += ' ' output['print'] += ' '
# day of week # day of week and month
date_splitted = date.split('.') date_splitted = date.split('.')
year = int(date_splitted[2]) year = int(date_splitted[2])
previous_month = month previous_month = month
if (month := int(date_splitted[1].lstrip('0'))) != previous_month: if (month := int(date_splitted[1].lstrip('0'))) != previous_month:
output['digital'] += '<br>' output['digital'] += '<br>'
output['markdown'] += '<br>'
match month: match month:
case 1:
month_formatted = 'Januar'
case 2: case 2:
output['digital'] += 'Februar' month_formatted = 'Februar'
case 3:
month_formatted = 'März'
case 4:
month_formatted = 'April'
case 5:
month_formatted = 'Mai'
case 6:
month_formatted = 'Juni'
case 7:
month_formatted = 'Juli'
case 8:
month_formatted = 'August'
case 9:
month_formatted = 'September'
case 10:
month_formatted = 'Oktober'
case 11:
month_formatted = 'November'
case 12: case 12:
output['digital'] += 'Dezember' month_formatted = 'Dezember'
output['digital'] += '<br>' output['digital'] += '<b>' + month_formatted + ' ' + str(year) + '</b><br>'
output['markdown'] += '<b>*' + month_formatted + ' ' + str(year) + '*</b><br>'
day = int(date_splitted[0].lstrip('0')) day = int(date_splitted[0].lstrip('0'))
match datetime(year, month, day).weekday(): match datetime(year, month, day).weekday():
case 0: case 0:
output['digital'] += 'Montag' weekday_formatted = 'Montag'
case 1: case 1:
output['digital'] += 'Dienstag' weekday_formatted = 'Dienstag'
case 2: case 2:
output['digital'] += 'Mittwoch' weekday_formatted = 'Mittwoch'
case 3: case 3:
output['digital'] += 'Donnerstag' weekday_formatted = 'Donnerstag'
case 4: case 4:
output['digital'] += 'Freitag' weekday_formatted = 'Freitag'
case 5: case 5:
output['digital'] += 'Samstag' weekday_formatted = 'Samstag'
case 6: case 6:
output['digital'] += 'Sonntag' weekday_formatted = 'Sonntag'
output['digital'] += weekday_formatted
output['digital'] += ', ' output['digital'] += ', '
output['digital'] += date output['digital'] += date
output['digital'] += ' ' output['digital'] += ' '
output['markdown'] += '* '
output['markdown'] += weekday_formatted
output['markdown'] += ', '
output['markdown'] += date
output['markdown'] += ', '
# time # time
timespan = data[1].text.strip() timespan = data[1].text.strip()
@ -74,6 +103,8 @@ def scrape():
output['digital'] += time_formatted output['digital'] += time_formatted
output['digital'] += ', ' output['digital'] += ', '
output['markdown'] += time_formatted
# place # place
if len(data) > 2: if len(data) > 2:
place = data[2].text.strip() place = data[2].text.strip()
@ -84,6 +115,10 @@ def scrape():
output['digital'] += place output['digital'] += place
output['digital'] += ', ' output['digital'] += ', '
output['markdown'] += ', '
output['markdown'] += place
output['markdown'] += ': '
# title # title
title = event_soup.select('.calendarize h1')[0].text.strip() title = event_soup.select('.calendarize h1')[0].text.strip()
@ -95,6 +130,8 @@ def scrape():
output['digital'] += title output['digital'] += title
output['digital'] += '</b>' output['digital'] += '</b>'
output['markdown'] += title
# description # description
try: try:
description = event_soup.select('.calendarize .text p')[0].text.strip() description = event_soup.select('.calendarize .text p')[0].text.strip()
@ -104,6 +141,9 @@ def scrape():
output['digital'] += ' ' output['digital'] += ' '
output['digital'] += description output['digital'] += description
output['markdown'] += ' '
output['markdown'] += description
except IndexError: except IndexError:
pass pass
@ -111,7 +151,9 @@ def scrape():
output['digital'] += '<br>' output['digital'] += '<br>'
return output['print'] + "<hr>" + output['digital'] output['markdown'] += '<br>'
return output['print'] + '<br><hr>' + output['digital'] + '<br><hr>' + output['markdown']
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self): def do_GET(self):

Loading…
Cancel
Save