-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanup.py
47 lines (37 loc) · 1.48 KB
/
cleanup.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
###
# Project: oghma
# Author: M-Davies
# https://github.com/M-Davies/oghma
###
from utils import getFileDelimiter
import os
import logging
import datetime
import sys
CURRENT_DIR = f"{os.path.dirname(os.path.realpath(__file__))}{getFileDelimiter()}"
LOGGER = logging.getLogger()
LOGGER.setLevel(logging.INFO)
LOG_FILE_HANDLER = logging.FileHandler(filename=f"{CURRENT_DIR}{getFileDelimiter()}logs{getFileDelimiter()}oghma-{datetime.now().strftime('%d-%m-%Y')}.log", encoding="utf-8", mode="a")
LOG_FILE_HANDLER.setFormatter(logging.Formatter("%(asctime)s: %(levelname)s: %(name)s: %(message)s"))
LOGGER.addHandler(LOG_FILE_HANDLER)
LOG_OUTPUT_HANDLER = logging.StreamHandler(sys.stdout)
LOG_OUTPUT_HANDLER.setFormatter(logging.Formatter("%(asctime)s: %(levelname)s: %(name)s: %(message)s"))
LOGGER.addHandler(LOG_OUTPUT_HANDLER)
def cleanup():
"""
FUNC NAME: cleanup
FUNC DESC: Cleans up all txt files created from commands. Fires on a schedule set by Heroku
FUNC TYPE: Function
"""
FOLDER = os.getcwd() + getFileDelimiter()
for filename in os.listdir(FOLDER):
FILE = f"{FOLDER}{getFileDelimiter()}{filename}"
if ".md" in filename:
LOGGER.info(f"Trying to clean { FILE }")
os.remove(FILE)
if os.path.exists(FILE):
LOGGER.warn(f"Failed to delete { FILE }")
else:
LOGGER.info(f"{ FILE } successfully deleted!\n------")
LOGGER.info("SUCCESS: All data files deleted!")
cleanup()