added default Message and Yesterdays date

This commit is contained in:
Marcus Ferl 2022-02-23 23:19:44 +01:00
parent f7e1baaf2e
commit 36377d330c

View File

@ -8,7 +8,8 @@ import json
from datetime import date from datetime import date
import requests import requests
import config import config
import datetime
import random
# Get current Date # Get current Date
def get_current_date(): def get_current_date():
@ -16,8 +17,9 @@ def get_current_date():
day = str('{:02d}'.format(currentDate.day)) day = str('{:02d}'.format(currentDate.day))
month = str('{:02d}'.format(currentDate.month)) month = str('{:02d}'.format(currentDate.month))
year = str(currentDate.year) year = str(currentDate.year)
return [day, month, 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 # Raw data from Json file
def read_JSON(filename): def read_JSON(filename):
@ -26,6 +28,13 @@ def read_JSON(filename):
f.close() f.close()
return data 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 # Returns the Garbage
def create_Message(): def create_Message():
@ -35,7 +44,9 @@ def create_Message():
for i in read_JSON('muell.json'): for i in read_JSON('muell.json'):
day = i['date']['day'] day = i['date']['day']
month = i['date']['month'] month = i['date']['month']
if day == get_current_date()[0] and month == get_current_date()[1]: 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'] message = message + ' ' + i['name']
if config.events == 'true': if config.events == 'true':
@ -43,7 +54,9 @@ def create_Message():
for i in read_JSON(filename): for i in read_JSON(filename):
day = i['date']['day'] day = i['date']['day']
month = i['date']['month'] month = i['date']['month']
if day == get_current_date()[0] and month == get_current_date()[1]: 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'] message = message + ' ' + i['name']
if config.holidays == 'true': if config.holidays == 'true':
@ -51,14 +64,19 @@ def create_Message():
for i in read_JSON(filename): for i in read_JSON(filename):
day = i['date']['day'] day = i['date']['day']
month = i['date']['month'] month = i['date']['month']
if day == get_current_date()[0] and month == get_current_date()[1]: 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'] message = message + ' ' + i['name']
if len(message) < 5:
message = default_message()
return message
# Send Message to the Device # Send Message to the Device
def matrixRequest(): def matrixRequest():
requests.get('http://' + config.host + config.get_request + str(create_Message())) requests.get('http://' + config.host + config.get_request + str(create_Message()))
# Main # Main
matrixRequest() matrixRequest()