Eventboard_v_2.0/eventboard.py

83 lines
2.5 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
import datetime
import random
2022-02-16 22:49:20 +01:00
# 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]
2022-02-16 22:49:20 +01:00
# 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)
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']
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]:
2022-02-17 15:50:39 +01:00
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]:
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()[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]:
2022-02-17 21:36:39 +01:00
message = message + ' ' + i['name']
if len(message) < 5:
message = default_message()
return message
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()