refacto getallmessages

This commit is contained in:
Mickael 2019-09-01 14:40:26 +02:00
parent 5aa9df037a
commit 4410fe1232
3 changed files with 16 additions and 29 deletions

View file

@ -56,5 +56,8 @@ def getAllChannels(rocket):
index += channels['count'] index += channels['count']
return allChannels return allChannels
def getAllMessages(rocket, roomid, begindate=None, enddate=None):
return rocket.channels_history(roomid, oldest= begindate, count= 10000).json()
if __name__ == "__main__": if __name__ == "__main__":
print("Ce fichier est juste une librarie") print("Ce fichier est juste une librarie")

View file

@ -3,7 +3,7 @@ import os
import json import json
from datetime import datetime from datetime import datetime
from monthdelta import monthdelta from monthdelta import monthdelta
from common.rocketchathelper import getAllChannels, Connection from common.rocketchathelper import getAllChannels, getAllMessages, Connection
from common.savehelper import save from common.savehelper import save
def main(): def main():
@ -44,17 +44,15 @@ def main():
if channel_date > recent_date: if channel_date > recent_date:
channels_recent += 1 channels_recent += 1
print("Check messages for channels {}".format(channel['name'])) messages = getAllMessages(rocket, channel["_id"], begindate= recent_date)
messages = rocket.channels_history(channel["_id"], oldest= recent_date, count= 10000).json()
if messages["success"]: messages = list(filter(lambda message: "t" not in message, messages["messages"]))
messages = list(filter(lambda message: "t" not in message, messages["messages"])) nbMessages = len(messages)
nbMessages = len(messages) print("Check messages for channels {} ({})".format(channel['name'], nbMessages))
messages_recent += nbMessages messages_recent += nbMessages
if (channel["name"] != "general") and (channel["name"] != "accueil"): if (channel["name"] != "general") and (channel["name"] != "accueil"):
channels_list.append((channel["name"], nbMessages)) channels_list.append((channel["name"], nbMessages))
users.extend(map(lambda message: message["u"]["_id"], messages)) users.extend(map(lambda message: message["u"]["_id"], messages))
else:
print("Error : {}".format(messages["error"]))
# Get the channels with the most number of message # Get the channels with the most number of message
channels_list.sort(key=lambda channel: channel[1], reverse= True) channels_list.sort(key=lambda channel: channel[1], reverse= True)
@ -95,17 +93,5 @@ def getAllActiveUsers(rocket):
index += users['count'] index += users['count']
return list(filter( lambda user: user["active"] ,allUsers)) return list(filter( lambda user: user["active"] ,allUsers))
def getAllMessages(rocket, roomid, begindate):
index = 0
allMessages = []
while True:
messages = rocket.channels_history(roomid, offset = index, oldest= begindate).json()
allMessages.extend(messages["m"])
if messages['count'] + messages['offset'] >= messages['total']:
break
index += messages['count']
return allMessages
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -10,7 +10,7 @@ import os
import random import random
from datetime import datetime from datetime import datetime
from monthdelta import monthdelta from monthdelta import monthdelta
from common.rocketchathelper import getTsunamy, Tsunami, getAllChannels, Connection from common.rocketchathelper import getTsunamy, Tsunami, getAllChannels, getAllMessages, Connection
from common.savehelper import save from common.savehelper import save
def getColor(): def getColor():
@ -90,8 +90,8 @@ def main():
begindate = begin.isoformat() begindate = begin.isoformat()
enddate = end.isoformat() enddate = end.isoformat()
resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json() resultMess = getAllMessages(rocket, channel['_id'], begindate= begindate, enddate=enddate)
resultMess = list(filter(lambda mess: 't' not in mess, resultMess['messages'])) resultMess = list(filter(lambda mess: 't' not in mess, resultMess))
length = len(resultMess) length = len(resultMess)
dataMess.append(length) dataMess.append(length)
@ -125,7 +125,5 @@ def main():
save(info, "channelsstat") save(info, "channelsstat")
if __name__ == "__main__": if __name__ == "__main__":
main() main()