Eventboard_v_2.0/eventboard.py
2022-02-17 15:50:39 +01:00

68 lines
1.6 KiB
Python

"""
Eventboard script in Python
Author: Marcus Ferl
Email: marcus@weifer.de
"""
import json
from datetime import date
import requests
import config
# Get current Date
def get_current_date():
currentDate = date.today()
day = str('{:02d}'.format(currentDate.day))
month = str('{:02d}'.format(currentDate.month))
year = str(currentDate.year)
return [day, month, year]
# Raw data from Json file
def read_JSON(filename):
f = open(filename)
data = json.load(f)
f.close()
return data
# Returns the Garbage
def create_Message():
message = ''
if config.garbage == 'true':
for i in read_JSON('muell.json'):
day = i['date']['day']
month = i['date']['month']
if day == get_current_date()[0] and month == get_current_date()[1]:
message = message + ' ' + i['name']
if config.events == 'true':
filename = 'events.json'
for i in read_JSON(filename):
day = i['date']['day']
month = i['date']['month']
if day == get_current_date()[0] and month == get_current_date()[1]:
message = message + ' ' + i['message']
if config.holidays == 'true':
filename = 'holidays.json'
for i in read_JSON(filename):
day = i['date']['day']
month = i['date']['month']
if day == get_current_date()[0] and month == get_current_date()[1]:
message = message + ' ' + i['message']
# Send Message to the Device
def matrixRequest():
requests.get('http://' + config.host + config.get_request + str(create_Message()))
matrixRequest()