Python tkinter alert calendar project .
user1272047
2 min read
Python tkinter alert calendar project .
https://github.com/Risico98908/alert.calendar.py.tkinker/tree/main
#!/usr/bin/env python3
#/0.myfiles/notify.02.py
import json
import tkinter as tk
from tkinter import messagebox
from datetime import datetime
# Define the file path
filepath = "/0.myfiles/notify.array"
# Load the data from the file
with open(filepath, 'r') as file:
main_array = json.load(file)
# Function to parse 2D array and check for time match
def parse_and_notify(array):
for sub_array in array:
time_value = None
desc_value = None
# Search for pairs with specified keys
for pair in sub_array:
if pair[0] == "time":
time_value = pair[1]
elif pair[0] == "desc":
desc_value = pair[1]
# Check if current time matches the time_value and show notification
if time_value and desc_value:
current_time = datetime.now().strftime("%Y.%m.%d.%H.%M")
if current_time == time_value:
show_notification(time_value, desc_value)
# Function to show a pop-up message and log the message to the terminal on close
def show_notification(time_value, desc_value):
# Display the pop-up message
root = tk.Tk()
root.withdraw() # Hide the main window
messagebox.showinfo("Notification", f"Time: {time_value}\nDescription: {desc_value}")
root.destroy()
# Log the message in the terminal
drop_off_time = datetime.now().strftime("%Y.%m.%d.%H.%M")
print(f"{time_value}.{desc_value}.{drop_off_time}.close")
# Run the function once
parse_and_notify(main_array)
[
[["time", "2024.10.29.11.38"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.29.11.55"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.30.08.45"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.30.08.55"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.28.19.46"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.28.19.47"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.28.19.49"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.28.19.51"], ["desc", "test test"], ["rrrr", "ttttt"]],
[["time", "2024.10.29.11.33"], ["desc", "another test"], ["rrrr", "sample"]],
["#/0.myfiles/notify.array"]
]
/0.myfiles/notify.02.service
[Unit]
Description=Notify Service to Display Alerts
After=network.target
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/python3 /0.myfiles/notify.02.py
Restart=always
RestartSec=60
TimeoutStartSec=infinity
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
# Copy each service file to the systemd directory
sudo cp /0.myfiles/notify.02.service /etc/systemd/system/
sudo cp /0.myfiles/notify.04.service /etc/systemd/system/
sudo cp /0.myfiles/notify.05.service /etc/systemd/system/
# Reload systemd to recognize the new/updated services
sudo systemctl daemon-reload
# Enable each service to start on boot
sudo systemctl enable notify.02.service
sudo systemctl enable notify.04.service
sudo systemctl enable notify.05.service
# Start or restart each service
sudo systemctl restart notify.02.service
sudo systemctl restart notify.04.service
sudo systemctl restart notify.05.service
# Check the status of each service
sudo systemctl status notify.02.service
sudo systemctl status notify.04.service
sudo systemctl status notify.05.service
Bash commands.
Remark.
Files
notify.02.service,
notify.04.service,
notify.05.service ,
are similar.
Inside them just change:
ExecStart=/usr/bin/python3 /0.myfiles/notify.02.py
ExecStart=/usr/bin/python3 /0.myfiles/notify.04.py
ExecStart=/usr/bin/python3 /0.myfiles/notify.05.py
0
Subscribe to my newsletter
Read articles from user1272047 directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by