refacto getallmessages
This commit is contained in:
parent
5aa9df037a
commit
4410fe1232
3 changed files with 16 additions and 29 deletions
|
@ -56,5 +56,8 @@ def getAllChannels(rocket):
|
|||
index += channels['count']
|
||||
return allChannels
|
||||
|
||||
def getAllMessages(rocket, roomid, begindate=None, enddate=None):
|
||||
return rocket.channels_history(roomid, oldest= begindate, count= 10000).json()
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Ce fichier est juste une librarie")
|
|
@ -3,7 +3,7 @@ import os
|
|||
import json
|
||||
from datetime import datetime
|
||||
from monthdelta import monthdelta
|
||||
from common.rocketchathelper import getAllChannels, Connection
|
||||
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
|
||||
from common.savehelper import save
|
||||
|
||||
def main():
|
||||
|
@ -44,17 +44,15 @@ def main():
|
|||
if channel_date > recent_date:
|
||||
channels_recent += 1
|
||||
|
||||
print("Check messages for channels {}".format(channel['name']))
|
||||
messages = rocket.channels_history(channel["_id"], oldest= recent_date, count= 10000).json()
|
||||
if messages["success"]:
|
||||
messages = getAllMessages(rocket, channel["_id"], begindate= recent_date)
|
||||
|
||||
messages = list(filter(lambda message: "t" not in message, messages["messages"]))
|
||||
nbMessages = len(messages)
|
||||
print("Check messages for channels {} ({})".format(channel['name'], nbMessages))
|
||||
messages_recent += nbMessages
|
||||
if (channel["name"] != "general") and (channel["name"] != "accueil"):
|
||||
channels_list.append((channel["name"], nbMessages))
|
||||
users.extend(map(lambda message: message["u"]["_id"], messages))
|
||||
else:
|
||||
print("Error : {}".format(messages["error"]))
|
||||
|
||||
# Get the channels with the most number of message
|
||||
channels_list.sort(key=lambda channel: channel[1], reverse= True)
|
||||
|
@ -95,17 +93,5 @@ def getAllActiveUsers(rocket):
|
|||
index += users['count']
|
||||
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__":
|
||||
main()
|
||||
|
|
|
@ -10,7 +10,7 @@ import os
|
|||
import random
|
||||
from datetime import datetime
|
||||
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
|
||||
|
||||
def getColor():
|
||||
|
@ -90,8 +90,8 @@ def main():
|
|||
begindate = begin.isoformat()
|
||||
enddate = end.isoformat()
|
||||
|
||||
resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json()
|
||||
resultMess = list(filter(lambda mess: 't' not in mess, resultMess['messages']))
|
||||
resultMess = getAllMessages(rocket, channel['_id'], begindate= begindate, enddate=enddate)
|
||||
resultMess = list(filter(lambda mess: 't' not in mess, resultMess))
|
||||
length = len(resultMess)
|
||||
dataMess.append(length)
|
||||
|
||||
|
@ -125,7 +125,5 @@ def main():
|
|||
|
||||
save(info, "channelsstat")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue