diff --git a/scripts/generate_chat_stat_monthly.py b/scripts/generate_chat_stat_monthly.py index 8c6f86c..602874a 100644 --- a/scripts/generate_chat_stat_monthly.py +++ b/scripts/generate_chat_stat_monthly.py @@ -14,7 +14,13 @@ from common.rocketchathelper import getAllChannels, getAllMessages, Connection from common.savehelper import save from common.charthelper import createElement, getColor, setTsunamyInfo, Tsunami, getTsunamy +begin = datetime.now() +end = datetime.now() + def main(): + + global begin, end + rocket = Connection() labels = [None] * 12 @@ -56,6 +62,8 @@ def main(): begin = date - monthdelta(12) end = begin + monthdelta(1) + messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate=date, count= channel['msgs']) + tsunamy = getTsunamy(channel) for id in range(0, 12): @@ -63,11 +71,8 @@ def main(): uniqueUserGlobal[id] = [] labels[id] = begin.strftime("%b %Y") print(f"\t{labels[id]}") - begindate = begin.isoformat() - enddate = end.isoformat() - - resultMess = getAllMessages(rocket, channel['_id'], begindate= begindate, enddate=enddate) - resultMess = list(filter(lambda mess: 't' not in mess, resultMess)) + + resultMess = list(filter(lambda mess: begin < datetime.strptime(mess["ts"], "%Y-%m-%dT%H:%M:%S.%fZ") < end, messages)) length = len(resultMess) dataMess.append(length)