Eventboard_v_2.0/eventboard.py

65 lines
1.6 KiB
Python
Raw Normal View History

2022-02-16 22:49:20 +01:00
"""
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
2022-02-17 15:50:39 +01:00
2022-02-16 22:49:20 +01:00
# Returns the Garbage
def create_Message():
2022-02-17 15:50:39 +01:00
message = ''
2022-02-16 22:49:20 +01:00
if config.garbage == 'true':
for i in read_JSON('muell.json'):
day = i['date']['day']
month = i['date']['month']
2022-02-17 15:50:39 +01:00
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]:
2022-02-17 21:36:39 +01:00
message = message + ' ' + i['name']
2022-02-17 15:50:39 +01:00
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]:
2022-02-17 21:36:39 +01:00
message = message + ' ' + i['name']
2022-02-17 15:50:39 +01:00
2022-02-16 22:49:20 +01:00
# Send Message to the Device
def matrixRequest():
2022-02-17 15:50:39 +01:00
requests.get('http://' + config.host + config.get_request + str(create_Message()))
2022-02-16 22:49:20 +01:00
2022-02-17 15:55:10 +01:00
# Main
2022-02-16 22:49:20 +01:00
matrixRequest()