added default Message and Yesterdays date
This commit is contained in:
parent
f7e1baaf2e
commit
36377d330c
|
@ -8,7 +8,8 @@ import json
|
|||
from datetime import date
|
||||
import requests
|
||||
import config
|
||||
|
||||
import datetime
|
||||
import random
|
||||
|
||||
# Get current Date
|
||||
def get_current_date():
|
||||
|
@ -16,8 +17,9 @@ def get_current_date():
|
|||
day = str('{:02d}'.format(currentDate.day))
|
||||
month = str('{:02d}'.format(currentDate.month))
|
||||
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
|
||||
def read_JSON(filename):
|
||||
|
@ -26,6 +28,13 @@ def read_JSON(filename):
|
|||
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():
|
||||
|
@ -35,7 +44,9 @@ def create_Message():
|
|||
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]:
|
||||
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':
|
||||
|
@ -43,7 +54,9 @@ def create_Message():
|
|||
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]:
|
||||
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':
|
||||
|
@ -51,14 +64,19 @@ def create_Message():
|
|||
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]:
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user