Fix generate info for chat

This commit is contained in:
Mickael 2020-02-16 16:12:08 +01:00
parent 0e62246c63
commit 24810ff5af

View file

@ -1,5 +1,5 @@
from rocketchat_API.rocketchat import RocketChat
import os
import os, time
import json
from datetime import datetime
from monthdelta import monthdelta
@ -23,8 +23,7 @@ def main():
rocket = Connection()
print("Check users")
users = getAllActiveUsers(rocket)
crapauds_total = len(users)
crapauds_total = getNbUsers(rocket)
print("Check channels")
channels = getAllChannels(rocket)
@ -43,15 +42,17 @@ def main():
cohortes.append(channel["name"][8:])
if channel_date > recent_date:
channels_recent += 1
messages = getAllMessages(rocket, channel["_id"], begindate= recent_date)
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))
if messages is not None:
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 : couldn't get message")
time.sleep(20)
# Get the channels with the most number of message
channels_list.sort(key=lambda channel: channel[1], reverse= True)
@ -80,17 +81,9 @@ def main():
save(info, "chat")
print("End chat info generation")
def getAllActiveUsers(rocket):
index = 0
allUsers = []
while True:
users = rocket.users_list(offset = index).json()
allUsers.extend(users["users"])
if users['count'] + users['offset'] >= users['total']:
break
index += users['count']
return list(filter( lambda user: user["active"] ,allUsers))
def getNbUsers(rocket):
users = rocket.users_list().json()
return users["total"]
if __name__ == "__main__":
main()