mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
60 lines
1.2 KiB
Python
60 lines
1.2 KiB
Python
|
#!/usr/bin/env python3
|
||
|
# -*-coding:UTF-8 -*
|
||
|
"""
|
||
|
The TermTracker Module
|
||
|
===================
|
||
|
|
||
|
"""
|
||
|
import os
|
||
|
import sys
|
||
|
import time
|
||
|
import datetime
|
||
|
|
||
|
from pubsublogger import publisher
|
||
|
|
||
|
import NotificationHelper
|
||
|
|
||
|
from packages import Date
|
||
|
from packages import Item
|
||
|
from packages import Term
|
||
|
|
||
|
def clean_term_db_stat_token():
|
||
|
all_stat_date = Term.get_all_token_stat_history()
|
||
|
|
||
|
list_date_to_keep = Date.get_date_range(31)
|
||
|
for date in all_stat_date:
|
||
|
if date not in list_date_to_keep:
|
||
|
# remove history
|
||
|
Term.delete_token_statistics_by_date(date)
|
||
|
|
||
|
print('Term Stats Cleaned')
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
|
||
|
publisher.port = 6380
|
||
|
publisher.channel = "Script"
|
||
|
publisher.info("DbCleaner started")
|
||
|
|
||
|
config_section = 'TermTrackerMod'
|
||
|
|
||
|
# low priority
|
||
|
time.sleep(180)
|
||
|
|
||
|
daily_cleaner = True
|
||
|
current_date = datetime.datetime.now().strftime("%Y%m%d")
|
||
|
|
||
|
while True:
|
||
|
|
||
|
if daily_cleaner:
|
||
|
clean_term_db_stat_token()
|
||
|
daily_cleaner = False
|
||
|
else:
|
||
|
sys.exit(0)
|
||
|
time.sleep(600)
|
||
|
|
||
|
new_date = datetime.datetime.now().strftime("%Y%m%d")
|
||
|
if new_date != current_date:
|
||
|
current_date = new_date
|
||
|
daily_cleaner = True
|