From 9132f4f03fe575e243bdb4622d9b1e39c97d1596 Mon Sep 17 00:00:00 2001 From: Mickael Date: Sun, 1 Sep 2019 12:50:21 +0200 Subject: [PATCH] refacto --- .../{channelhelper.py => rocketchathelper.py} | 5 +++++ scripts/generate_chat_info.py | 15 ++------------- scripts/getstats.py | 4 ++-- site/data/chat.json | 2 +- 4 files changed, 10 insertions(+), 16 deletions(-) rename scripts/common/{channelhelper.py => rocketchathelper.py} (84%) diff --git a/scripts/common/channelhelper.py b/scripts/common/rocketchathelper.py similarity index 84% rename from scripts/common/channelhelper.py rename to scripts/common/rocketchathelper.py index 2fe3b9d..ed0d0ba 100644 --- a/scripts/common/channelhelper.py +++ b/scripts/common/rocketchathelper.py @@ -1,3 +1,8 @@ +from rocketchat_API.rocketchat import RocketChat + +def Connection(): + return RocketChat(None, None, auth_token= os.environ['ROCKETCHAT_AUTH'], user_id= os.environ['ROCKETCHAT_USERID'], server_url=os.environ['ROCKETCHAT_SERVER']) + def getNodesOrigin(channel): nodes = [] if 'description' not in channel: diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index 45ec2c2..9c83c02 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -3,6 +3,7 @@ import os import json from datetime import datetime from monthdelta import monthdelta +from common.rocketchathelper import getAllChannels, Connection def main(): print("Start chat info generation") @@ -18,7 +19,7 @@ def main(): recent_date = datetime.now() - monthdelta() - rocket = RocketChat(None, None, auth_token= os.environ['ROCKETCHAT_AUTH'], user_id= os.environ['ROCKETCHAT_USERID'], server_url=os.environ['ROCKETCHAT_SERVER']) + rocket = Connection() print("Check users") users = getAllActiveUsers(rocket) @@ -92,18 +93,6 @@ def save(info): with open(statsFilePath, "w") as file_write: json.dump(info, file_write) -def getAllChannels(rocket): - index = 0 - allChannels = [] - while True: - channels = rocket.channels_list(offset = index).json() - - allChannels.extend([ channel for channel in channels['channels'] if 'archived' not in channel]) - if channels['count'] + channels['offset'] >= channels['total']: - break - index += channels['count'] - return allChannels - def getAllActiveUsers(rocket): index = 0 allUsers = [] diff --git a/scripts/getstats.py b/scripts/getstats.py index fa05015..9405626 100644 --- a/scripts/getstats.py +++ b/scripts/getstats.py @@ -10,7 +10,7 @@ import os import random from datetime import datetime from monthdelta import monthdelta -from common.channelhelper import getTsunamy, Tsunami, getAllChannels +from common.rocketchathelper import getTsunamy, Tsunami, getAllChannels, Connection def getColor(): r = random.randrange(255) @@ -49,7 +49,7 @@ def setTsunamyInfo(tsunamy, messagesDataTsunamy, id, length): messagesDataTsunamy[Tsunami.TECHNOLOGY][id] += length def main(): - rocket = RocketChat(None, None, auth_token= os.environ['ROCKETCHAT_AUTH'], user_id= os.environ['ROCKETCHAT_USERID'], server_url=os.environ['ROCKETCHAT_SERVER']) + rocket = Connection() labels = [None] * 12 messagesByChannel = [] diff --git a/site/data/chat.json b/site/data/chat.json index 2ac3a04..2161d16 100644 --- a/site/data/chat.json +++ b/site/data/chat.json @@ -1 +1 @@ -{"crapauds": {"total": 2373, "recent": 180}, "canaux": {"total": 177, "recent": 98, "liste": ["semourais", "accueil", "general", "techos", "right-to-repair", "wiki-crapaud-fou", "reflexion-sur-l-argent", "cohorte-loire", "empowerment", "le-led"]}, "messages": {"total": 187094, "recent": 13313}, "cohortes": ["2607", "34", "barcelone", "belgique", "bourgogne", "bretagne", "centre", "grand-est", "grece", "grenoble", "hdf", "ile-de-france", "la-reunion", "loire", "lyon-st-etienne", "normandie", "paca", "paysdesavoie", "sud-ouest", "suisse"]} \ No newline at end of file +{"crapauds": {"total": 2180, "recent": 98}, "canaux": {"total": 184, "recent": 107, "liste": ["semourais", "techos", "right-to-repair", "libre", "cratube", "reflexion-sur-lamour", "reflexion-sur-l-argent", "animation-crapauds", "lucarn", "empowerment"]}, "messages": {"total": 192117, "recent": 12337}, "cohortes": ["2607", "34", "barcelone", "belgique", "bourgogne", "bretagne", "centre", "grand-est", "grece", "grenoble", "hdf", "ile-de-france", "la-reunion", "loire", "lyon-st-etienne", "normandie", "paca", "paysdesavoie", "sud-ouest", "suisse"]} \ No newline at end of file