Eventboard_v_2.0/eventboard.py
2022-03-16 22:34:16 +01:00

83 lines
2.5 KiB
Python

"""
Eventboard script in Python
Author: Marcus Ferl
Email: marcus@weifer.de
"""
import json
from datetime import date
import requests
import config
import datetime
import random
# 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)
tomorrow_date = date.today() + datetime.timedelta(days=1)
tomorrow = str('{:02d}'.format(tomorrow_date.day))
return [day, month, year, tomorrow]
# Raw data from Json file
def read_JSON(filename):
f = open(filename)
data = json.load(f)
f.close()
return data
# Creat default Message
def default_message():
lines = []
with open('zitate.txt', 'r') as file:
for l in file:
lines.append(l)
return random.choice(lines)
# 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()[3] and month == get_current_date()[1]:
message = message + ' Morgen: ' + i['name']
elif int(day) == int(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()[3] and month == get_current_date()[1]:
message = message + ' Morgen: ' + i['name']
elif int(day) == int(get_current_date()[0]) and month == get_current_date()[1]:
message = message + ' ' + i['name']
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()[3] and month == get_current_date()[1]:
message = message + ' Morgen: ' + i['name']
elif int(day) == int(get_current_date()[0]) and month == get_current_date()[1]:
message = message + ' ' + i['name']
if len(message) < 5:
message = default_message()
return message
# Send Message to the Device
def matrixRequest():
requests.get('http://' + config.host + config.get_request + str(create_Message()))
# Main
matrixRequest()