sett logs to be deleted after 10 days
This commit is contained in:
19
app.py
19
app.py
@@ -12,6 +12,24 @@ urllib3.disable_warnings()
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(filename='./data/log.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
def delete_old_logs():
|
||||
log_dir = './data/'
|
||||
log_file = 'log.txt'
|
||||
log_path = os.path.join(log_dir, log_file)
|
||||
|
||||
if os.path.exists(log_path):
|
||||
file_mod_time = datetime.fromtimestamp(os.path.getmtime(log_path))
|
||||
if datetime.now() - file_mod_time > timedelta(days=10):
|
||||
os.remove(log_path)
|
||||
logging.info("Deleted old log file: %s", log_file)
|
||||
else:
|
||||
logging.info("Log file is not older than 10 days: %s", log_file)
|
||||
else:
|
||||
logging.info("Log file does not exist: %s", log_file)
|
||||
|
||||
# Call the function to delete old logs
|
||||
delete_old_logs()
|
||||
|
||||
|
||||
def config():
|
||||
import config
|
||||
@@ -55,6 +73,7 @@ def check_internet_connection():
|
||||
cmd_block_wifi = 'sudo rfkill block wifi'
|
||||
cmd_unblock_wifi = 'sudo rfkill unblock wifi'
|
||||
logging.info('Internet connection check loaded')
|
||||
delete_old_logs()
|
||||
|
||||
def manage_wifi_connection():
|
||||
if var1 == 0:
|
||||
|
||||
Reference in New Issue
Block a user