-
Notifications
You must be signed in to change notification settings - Fork 0
/
utiles.py
executable file
·57 lines (47 loc) · 1.91 KB
/
utiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from PyQt5.QtWidgets import QDialog, QApplication, QLabel, QDesktopWidget
from PyQt5.QtCore import QTimer, QThread, Qt, QPoint
from plyer import notification
from datetime import datetime
from PyQt5.uic import loadUi
from PIL import Image
import traceback
import pystray
import logging
import json
import time
import sys
import os
PATH = os.path.dirname(os.path.realpath(__file__)) + "/"
NOTIFY_BEFORE = 15 # this is the time that program notifies you before the pray in minuits
def notify(message):
notification.notify(
title="Azan Notifier",
message=message,
app_name='Azan Notifier',
timeout=1
)
class Logger:
@staticmethod
def logIntoFile(file_name):
# Create the root logger and set its level to DEBUG
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# Create a file handler and set its level to INFO
file_handler = logging.FileHandler(file_name)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
# Create a console handler and set its level to INFO
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
# Add handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)
# Set custom exception hook to handle uncaught exceptions
sys.excepthook = Logger.handle_exception
@staticmethod
def handle_exception(exc_type, exc_value, exc_traceback):
# Log unhandled exceptions with traceback
logging.error(f'Unhandled exception: {exc_type.__name__}: {exc_value}')
logging.error("".join(traceback.format_tb(exc_traceback)))
Logger.logIntoFile(PATH + "logg.log")