From 699d146cbd55be2059e160eba41000a9a2d09746 Mon Sep 17 00:00:00 2001 From: Mickael Date: Sat, 17 Aug 2019 17:28:42 +0200 Subject: [PATCH 01/10] add first version to generate data for chat --- .gitignore | 5 +- scripts/generate.sh | 3 +- scripts/generate_chat_info.py | 108 ++++++++++++++++++++++++++++++++++ scripts/requirements.txt | 2 + site/data/chat.json | 27 +-------- 5 files changed, 117 insertions(+), 28 deletions(-) create mode 100644 scripts/generate_chat_info.py create mode 100644 scripts/requirements.txt diff --git a/.gitignore b/.gitignore index 570d6fc..8e8f97e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # site/data/*.json !site/data/*.sample.json -config \ No newline at end of file +config +scripts/dev_config.py +.vscode +scripts/__pycache__ diff --git a/scripts/generate.sh b/scripts/generate.sh index d6d21a3..adc54e0 100644 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -1,8 +1,9 @@ #!/bin/sh +pip3 install -r requirements.txt # idees # chat -cp ./site/data/chat.sample.json ./site/data/chat.json +python3 ./script/generate_chat_info.py # wiki \ No newline at end of file diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py new file mode 100644 index 0000000..7fb33bb --- /dev/null +++ b/scripts/generate_chat_info.py @@ -0,0 +1,108 @@ +from rocketchat_API.rocketchat import RocketChat +import dev_config as cfg +import os +import json +from datetime import datetime +from monthdelta import monthdelta + +def main(): + crapauds_total = 0 + crapauds_recent = 0 + channels_total = 0 + channels_recent = 0 + channels_list = [] + messages_total = 0 + messages_recent = 0 + + recent_date = datetime.now() - monthdelta() + + rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'], server_url=cfg.rocket['server']) + users = getAllUsers(rocket) + crapauds_total = len(users) + for user in users: + date = user["createdAt"] + user_date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") + if user_date > recent_date: + crapauds_recent += 1 + + channels = getAllChannels(rocket) + channels_total = len(channels) + + for channel in channels: + messages_total += int(channel["msgs"]) + date = channel["ts"] + channel_date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") + if channel_date > recent_date: + channels_recent += 1 + channels_list.append(channel["name"]) + messages = rocket.channels_history(channel["_id"], oldest= recent_date, count= 10000).json() + messages_recent += len(messages["messages"]) + + + info = { + "crapauds": { + "total": crapauds_total, + "recent": crapauds_recent + }, + "canaux": { + "total": channels_total, + "recent": channels_recent, + "liste": channels_list + }, + "messages": { + "total": messages_total, + "recent": messages_recent + } + } + + save(info) + +def save(info): + # Récupération du répertoire racine du repo + rootFolder = os.path.join(os.path.dirname(__file__), '..') + # Répertoire pour stocker le fichier de sortie + dataFolder = os.path.join(rootFolder, 'site', 'data') + + statsFilePath = os.path.abspath( + os.path.join(dataFolder, 'chat.json')) + 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 getAllUsers(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 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() diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..b45bc34 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,2 @@ +rocketchat_API==0.6.34 +MonthDelta==0.9.1 \ No newline at end of file diff --git a/site/data/chat.json b/site/data/chat.json index d202bae..4333453 100644 --- a/site/data/chat.json +++ b/site/data/chat.json @@ -1,26 +1 @@ -{ - "crapauds": { - "total": 2300, - "recent": 200 - }, - "canaux": { - "total": 183, - "recent": 23, - "liste": [ - "general", - "semourais", - "cohorte-brest", - "accueil", - "right-to-repair", - "cohorte-34", - "cercle-neurodiversité", - "cercle-permaculture", - "no-gafam", - "Le LED" - ] - }, - "messages": { - "total": 23400, - "recent": 892 - } -} \ No newline at end of file +{"crapauds": {"total": 2363, "recent": 85}, "canaux": {"total": 176, "recent": 10, "liste": ["activite-et-travail", "bnb-bonheur-national-brut", "cohorte-barcelone", "cohorte-lyon-st-etienne", "crapomobile", "dessins-citoyens-collectifs-booderies", "emmaus-pau-lescar", "empowerment", "projet-cand-alterincub-centre", "terre-de-convergence"]}, "messages": {"total": 185199, "recent": 1108}} \ No newline at end of file From 0c50498f88d2d8e6b4443384d608479ff4837468 Mon Sep 17 00:00:00 2001 From: Mickael Date: Sat, 17 Aug 2019 17:43:25 +0200 Subject: [PATCH 02/10] - Fix generate.sh - Add log in generate_chat_info.py --- scripts/generate.sh | 6 +++--- scripts/generate_chat_info.py | 4 +++- site/data/chat.json | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/generate.sh b/scripts/generate.sh index 061d064..53493d3 100644 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -1,10 +1,10 @@ #!/bin/sh -pip3 install -r requirements.txt +pip3 install -r ./scripts/requirements.txt # idees cp ./site/data/idees.sample.json ./site/data/idees.json # chat -python3 ./script/generate_chat_info.py +python3 ./scripts/generate_chat_info.py -# wiki \ No newline at end of file +# wiki diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index 7fb33bb..07ad083 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -6,6 +6,8 @@ from datetime import datetime from monthdelta import monthdelta def main(): + print("Start chat info generation") + crapauds_total = 0 crapauds_recent = 0 channels_total = 0 @@ -37,7 +39,6 @@ def main(): channels_list.append(channel["name"]) messages = rocket.channels_history(channel["_id"], oldest= recent_date, count= 10000).json() messages_recent += len(messages["messages"]) - info = { "crapauds": { @@ -56,6 +57,7 @@ def main(): } save(info) + print("End chat info generation") def save(info): # Récupération du répertoire racine du repo diff --git a/site/data/chat.json b/site/data/chat.json index 4333453..3d90fda 100644 --- a/site/data/chat.json +++ b/site/data/chat.json @@ -1 +1 @@ -{"crapauds": {"total": 2363, "recent": 85}, "canaux": {"total": 176, "recent": 10, "liste": ["activite-et-travail", "bnb-bonheur-national-brut", "cohorte-barcelone", "cohorte-lyon-st-etienne", "crapomobile", "dessins-citoyens-collectifs-booderies", "emmaus-pau-lescar", "empowerment", "projet-cand-alterincub-centre", "terre-de-convergence"]}, "messages": {"total": 185199, "recent": 1108}} \ No newline at end of file +{"crapauds": {"total": 2363, "recent": 85}, "canaux": {"total": 176, "recent": 10, "liste": ["activite-et-travail", "bnb-bonheur-national-brut", "cohorte-barcelone", "cohorte-lyon-st-etienne", "crapomobile", "dessins-citoyens-collectifs-booderies", "emmaus-pau-lescar", "empowerment", "projet-cand-alterincub-centre", "terre-de-convergence"]}, "messages": {"total": 185200, "recent": 1108}} \ No newline at end of file From 7cc56582caa5f412bb993931bb98358fc2d8da65 Mon Sep 17 00:00:00 2001 From: Mickael Date: Sat, 17 Aug 2019 18:17:51 +0200 Subject: [PATCH 03/10] Fix active channels last 30 days --- scripts/generate_chat_info.py | 4 ++-- site/data/chat.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index 07ad083..2c3c5e9 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -18,7 +18,7 @@ def main(): recent_date = datetime.now() - monthdelta() - rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'], server_url=cfg.rocket['server']) + rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'], auth_token=cfg.rocket['auth_token'], user_id=cfg.rocket['user_id'], server_url=cfg.rocket['server']) users = getAllUsers(rocket) crapauds_total = len(users) for user in users: @@ -32,7 +32,7 @@ def main(): for channel in channels: messages_total += int(channel["msgs"]) - date = channel["ts"] + date = channel["lm"] channel_date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") if channel_date > recent_date: channels_recent += 1 diff --git a/site/data/chat.json b/site/data/chat.json index 3d90fda..7032726 100644 --- a/site/data/chat.json +++ b/site/data/chat.json @@ -1 +1 @@ -{"crapauds": {"total": 2363, "recent": 85}, "canaux": {"total": 176, "recent": 10, "liste": ["activite-et-travail", "bnb-bonheur-national-brut", "cohorte-barcelone", "cohorte-lyon-st-etienne", "crapomobile", "dessins-citoyens-collectifs-booderies", "emmaus-pau-lescar", "empowerment", "projet-cand-alterincub-centre", "terre-de-convergence"]}, "messages": {"total": 185200, "recent": 1108}} \ No newline at end of file +{"crapauds": {"total": 2363, "recent": 84}, "canaux": {"total": 176, "recent": 102, "liste": ["accueil", "activite-et-travail", "agenda", "animation-crapauds", "aquaponie", "audio-visuel-libre", "bnb-bonheur-national-brut", "bresil", "burn-out", "cercle-autonomie-energetique", "cercle-blockchain-crypto", "cercle-collaboratif", "cercle-des-arts", "cercle-d\u00e9mocratie", "cercle-education", "cercle-game-changers", "cercle-generation-2050", "cercle-intergenerationnel", "cercle-neurodiversit\u00e9", "cercle-permaculture", "cercle-sante", "changer-de-paradigme", "cnv", "cohorte-2607", "cohorte-34", "cohorte-barcelone", "cohorte-belgique", "cohorte-bretagne", "cohorte-centre", "cohorte-geek", "cohorte-grece", "cohorte-grenoble", "cohorte-hdf", "cohorte-ile-de-france", "cohorte-loire", "cohorte-lyon-st-etienne", "cohorte-normandie", "cohorte-paca", "cohorte-scientifique", "cohorte-sud-ouest", "cohorte-suisse", "crapomobile", "desobeissance-civile", "dessins-citoyens-collectifs-booderies", "developpement-personnel", "doughnut-economics", "ecologie-biodiversite", "economie-connaissance", "ecovillages-ecoquartiers", "education-populaire", "emancipation-outre-mer", "emmaus-pau-lescar", "empowerment", "energie", "faire-avancer-le-schmilblick-ecologique", "foret_bleue", "fou-a-lier", "general", "geopolitique", "gestion-de-l-eau", "gilets-jaunes", "how-to-low-tech", "info-desintox", "intelligence-artificielle", "intelligence-collective", "jeux-inde-1", "journee-univ-j-verne-nantes-4-juil-2019", "la-bascule-lobby-citoyen", "langage-vrai-anti-glossaire", "le-led", "lhomme-et-la-terre", "libre", "lobbying", "logiciel-libre", "meditation", "mutuelle-sociale-solidaire", "nature-simplicite-bienveillance", "no-gafam", "open-hardware", "p-2-p-dat", "philosophie", "pratiques-artistiques", "projet-cand-alterincub-centre", "psychologie-neurologie", "radio-crapaud", "recherches-biologie", "recueil-temoignages", "reflexion-sur-l-argent", "rencontre-crapaud-kangourou", "right-to-repair", "semourais", "siteweb", "sociologie-de-l-effondrement", "solucracy", "survivalismes-et-resiliences", "terre-de-convergence", "tiers-lieux-apprenant", "transhumanisme-et-eugenisme", "tsunamis", "tvp-et-ebr", "wiki-crapaud-fou", "zero-dechet"]}, "messages": {"total": 185202, "recent": 12792}} \ No newline at end of file From 9fe47559a77d3a54323fc759915799fd60299dab Mon Sep 17 00:00:00 2001 From: Mickael Date: Sat, 17 Aug 2019 18:31:31 +0200 Subject: [PATCH 04/10] Add log --- scripts/generate_chat_info.py | 6 +++++- site/data/chat.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index 2c3c5e9..3497eae 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -18,7 +18,9 @@ def main(): recent_date = datetime.now() - monthdelta() - rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'], auth_token=cfg.rocket['auth_token'], user_id=cfg.rocket['user_id'], server_url=cfg.rocket['server']) + rocket = RocketChat(None, None, auth_token=cfg.rocket['auth_token'], user_id=cfg.rocket['user_id'], server_url=cfg.rocket['server']) + + print("Check users") users = getAllUsers(rocket) crapauds_total = len(users) for user in users: @@ -27,6 +29,7 @@ def main(): if user_date > recent_date: crapauds_recent += 1 + print("Check channels") channels = getAllChannels(rocket) channels_total = len(channels) @@ -37,6 +40,7 @@ def main(): if channel_date > recent_date: channels_recent += 1 channels_list.append(channel["name"]) + print("Check messages for channels {}".format(channel['name'])) messages = rocket.channels_history(channel["_id"], oldest= recent_date, count= 10000).json() messages_recent += len(messages["messages"]) diff --git a/site/data/chat.json b/site/data/chat.json index 7032726..9aa5bbc 100644 --- a/site/data/chat.json +++ b/site/data/chat.json @@ -1 +1 @@ -{"crapauds": {"total": 2363, "recent": 84}, "canaux": {"total": 176, "recent": 102, "liste": ["accueil", "activite-et-travail", "agenda", "animation-crapauds", "aquaponie", "audio-visuel-libre", "bnb-bonheur-national-brut", "bresil", "burn-out", "cercle-autonomie-energetique", "cercle-blockchain-crypto", "cercle-collaboratif", "cercle-des-arts", "cercle-d\u00e9mocratie", "cercle-education", "cercle-game-changers", "cercle-generation-2050", "cercle-intergenerationnel", "cercle-neurodiversit\u00e9", "cercle-permaculture", "cercle-sante", "changer-de-paradigme", "cnv", "cohorte-2607", "cohorte-34", "cohorte-barcelone", "cohorte-belgique", "cohorte-bretagne", "cohorte-centre", "cohorte-geek", "cohorte-grece", "cohorte-grenoble", "cohorte-hdf", "cohorte-ile-de-france", "cohorte-loire", "cohorte-lyon-st-etienne", "cohorte-normandie", "cohorte-paca", "cohorte-scientifique", "cohorte-sud-ouest", "cohorte-suisse", "crapomobile", "desobeissance-civile", "dessins-citoyens-collectifs-booderies", "developpement-personnel", "doughnut-economics", "ecologie-biodiversite", "economie-connaissance", "ecovillages-ecoquartiers", "education-populaire", "emancipation-outre-mer", "emmaus-pau-lescar", "empowerment", "energie", "faire-avancer-le-schmilblick-ecologique", "foret_bleue", "fou-a-lier", "general", "geopolitique", "gestion-de-l-eau", "gilets-jaunes", "how-to-low-tech", "info-desintox", "intelligence-artificielle", "intelligence-collective", "jeux-inde-1", "journee-univ-j-verne-nantes-4-juil-2019", "la-bascule-lobby-citoyen", "langage-vrai-anti-glossaire", "le-led", "lhomme-et-la-terre", "libre", "lobbying", "logiciel-libre", "meditation", "mutuelle-sociale-solidaire", "nature-simplicite-bienveillance", "no-gafam", "open-hardware", "p-2-p-dat", "philosophie", "pratiques-artistiques", "projet-cand-alterincub-centre", "psychologie-neurologie", "radio-crapaud", "recherches-biologie", "recueil-temoignages", "reflexion-sur-l-argent", "rencontre-crapaud-kangourou", "right-to-repair", "semourais", "siteweb", "sociologie-de-l-effondrement", "solucracy", "survivalismes-et-resiliences", "terre-de-convergence", "tiers-lieux-apprenant", "transhumanisme-et-eugenisme", "tsunamis", "tvp-et-ebr", "wiki-crapaud-fou", "zero-dechet"]}, "messages": {"total": 185202, "recent": 12792}} \ No newline at end of file +{"crapauds": {"total": 2363, "recent": 84}, "canaux": {"total": 176, "recent": 102, "liste": ["accueil", "activite-et-travail", "agenda", "animation-crapauds", "aquaponie", "audio-visuel-libre", "bnb-bonheur-national-brut", "bresil", "burn-out", "cercle-autonomie-energetique", "cercle-blockchain-crypto", "cercle-collaboratif", "cercle-des-arts", "cercle-d\u00e9mocratie", "cercle-education", "cercle-game-changers", "cercle-generation-2050", "cercle-intergenerationnel", "cercle-neurodiversit\u00e9", "cercle-permaculture", "cercle-sante", "changer-de-paradigme", "cnv", "cohorte-2607", "cohorte-34", "cohorte-barcelone", "cohorte-belgique", "cohorte-bretagne", "cohorte-centre", "cohorte-geek", "cohorte-grece", "cohorte-grenoble", "cohorte-hdf", "cohorte-ile-de-france", "cohorte-loire", "cohorte-lyon-st-etienne", "cohorte-normandie", "cohorte-paca", "cohorte-scientifique", "cohorte-sud-ouest", "cohorte-suisse", "crapomobile", "desobeissance-civile", "dessins-citoyens-collectifs-booderies", "developpement-personnel", "doughnut-economics", "ecologie-biodiversite", "economie-connaissance", "ecovillages-ecoquartiers", "education-populaire", "emancipation-outre-mer", "emmaus-pau-lescar", "empowerment", "energie", "faire-avancer-le-schmilblick-ecologique", "foret_bleue", "fou-a-lier", "general", "geopolitique", "gestion-de-l-eau", "gilets-jaunes", "how-to-low-tech", "info-desintox", "intelligence-artificielle", "intelligence-collective", "jeux-inde-1", "journee-univ-j-verne-nantes-4-juil-2019", "la-bascule-lobby-citoyen", "langage-vrai-anti-glossaire", "le-led", "lhomme-et-la-terre", "libre", "lobbying", "logiciel-libre", "meditation", "mutuelle-sociale-solidaire", "nature-simplicite-bienveillance", "no-gafam", "open-hardware", "p-2-p-dat", "philosophie", "pratiques-artistiques", "projet-cand-alterincub-centre", "psychologie-neurologie", "radio-crapaud", "recherches-biologie", "recueil-temoignages", "reflexion-sur-l-argent", "rencontre-crapaud-kangourou", "right-to-repair", "semourais", "siteweb", "sociologie-de-l-effondrement", "solucracy", "survivalismes-et-resiliences", "terre-de-convergence", "tiers-lieux-apprenant", "transhumanisme-et-eugenisme", "tsunamis", "tvp-et-ebr", "wiki-crapaud-fou", "zero-dechet"]}, "messages": {"total": 185204, "recent": 12791}} \ No newline at end of file From 9486431450017daa322c9740bf7524162fc84590 Mon Sep 17 00:00:00 2001 From: Mickael Date: Sun, 18 Aug 2019 21:49:58 +0200 Subject: [PATCH 05/10] use var env instead of file --- scripts/generate_chat_info.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index 3497eae..2b5e8cc 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -18,17 +18,12 @@ def main(): recent_date = datetime.now() - monthdelta() - rocket = RocketChat(None, None, auth_token=cfg.rocket['auth_token'], user_id=cfg.rocket['user_id'], server_url=cfg.rocket['server']) + rocket = RocketChat(os.environ['ROCKETCHAT_USER'], os.environ['ROCKETCHAT_PWD'], server_url=cfg.rocket['server']) print("Check users") - users = getAllUsers(rocket) - crapauds_total = len(users) - for user in users: - date = user["createdAt"] - user_date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") - if user_date > recent_date: - crapauds_recent += 1 - + users = rocket.users_list().json() + crapauds_total = users["total"] + print("Check channels") channels = getAllChannels(rocket) channels_total = len(channels) @@ -42,7 +37,10 @@ def main(): channels_list.append(channel["name"]) print("Check messages for channels {}".format(channel['name'])) messages = rocket.channels_history(channel["_id"], oldest= recent_date, count= 10000).json() - messages_recent += len(messages["messages"]) + if messages["success"]: + messages_recent += len(messages["messages"]) + else: + print("Error : {}".format(messages["error"])) info = { "crapauds": { From 753d25b8b5ba2d5277d0726ba5f87980fca20cad Mon Sep 17 00:00:00 2001 From: Mickael Date: Sun, 18 Aug 2019 22:44:19 +0200 Subject: [PATCH 06/10] Use authkey --- scripts/generate_chat_info.py | 6 +++--- site/data/chat.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index 2b5e8cc..d5652e4 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -1,5 +1,4 @@ from rocketchat_API.rocketchat import RocketChat -import dev_config as cfg import os import json from datetime import datetime @@ -18,10 +17,11 @@ def main(): recent_date = datetime.now() - monthdelta() - rocket = RocketChat(os.environ['ROCKETCHAT_USER'], os.environ['ROCKETCHAT_PWD'], server_url=cfg.rocket['server']) - + rocket = RocketChat(None, None, auth_token= os.environ['ROCKETCHAT_AUTH'], user_id= os.environ['ROCKETCHAT_USERID'], server_url=os.environ['ROCKETCHAT_SERVER']) + print("Check users") users = rocket.users_list().json() + crapauds_total = users["total"] print("Check channels") diff --git a/site/data/chat.json b/site/data/chat.json index 9aa5bbc..9f7a756 100644 --- a/site/data/chat.json +++ b/site/data/chat.json @@ -1 +1 @@ -{"crapauds": {"total": 2363, "recent": 84}, "canaux": {"total": 176, "recent": 102, "liste": ["accueil", "activite-et-travail", "agenda", "animation-crapauds", "aquaponie", "audio-visuel-libre", "bnb-bonheur-national-brut", "bresil", "burn-out", "cercle-autonomie-energetique", "cercle-blockchain-crypto", "cercle-collaboratif", "cercle-des-arts", "cercle-d\u00e9mocratie", "cercle-education", "cercle-game-changers", "cercle-generation-2050", "cercle-intergenerationnel", "cercle-neurodiversit\u00e9", "cercle-permaculture", "cercle-sante", "changer-de-paradigme", "cnv", "cohorte-2607", "cohorte-34", "cohorte-barcelone", "cohorte-belgique", "cohorte-bretagne", "cohorte-centre", "cohorte-geek", "cohorte-grece", "cohorte-grenoble", "cohorte-hdf", "cohorte-ile-de-france", "cohorte-loire", "cohorte-lyon-st-etienne", "cohorte-normandie", "cohorte-paca", "cohorte-scientifique", "cohorte-sud-ouest", "cohorte-suisse", "crapomobile", "desobeissance-civile", "dessins-citoyens-collectifs-booderies", "developpement-personnel", "doughnut-economics", "ecologie-biodiversite", "economie-connaissance", "ecovillages-ecoquartiers", "education-populaire", "emancipation-outre-mer", "emmaus-pau-lescar", "empowerment", "energie", "faire-avancer-le-schmilblick-ecologique", "foret_bleue", "fou-a-lier", "general", "geopolitique", "gestion-de-l-eau", "gilets-jaunes", "how-to-low-tech", "info-desintox", "intelligence-artificielle", "intelligence-collective", "jeux-inde-1", "journee-univ-j-verne-nantes-4-juil-2019", "la-bascule-lobby-citoyen", "langage-vrai-anti-glossaire", "le-led", "lhomme-et-la-terre", "libre", "lobbying", "logiciel-libre", "meditation", "mutuelle-sociale-solidaire", "nature-simplicite-bienveillance", "no-gafam", "open-hardware", "p-2-p-dat", "philosophie", "pratiques-artistiques", "projet-cand-alterincub-centre", "psychologie-neurologie", "radio-crapaud", "recherches-biologie", "recueil-temoignages", "reflexion-sur-l-argent", "rencontre-crapaud-kangourou", "right-to-repair", "semourais", "siteweb", "sociologie-de-l-effondrement", "solucracy", "survivalismes-et-resiliences", "terre-de-convergence", "tiers-lieux-apprenant", "transhumanisme-et-eugenisme", "tsunamis", "tvp-et-ebr", "wiki-crapaud-fou", "zero-dechet"]}, "messages": {"total": 185204, "recent": 12791}} \ No newline at end of file +{"crapauds": {"total": 2365, "recent": 0}, "canaux": {"total": 177, "recent": 99, "liste": ["accueil", "activite-et-travail", "agenda", "animation-crapauds", "audio-visuel-libre", "bnb-bonheur-national-brut", "bresil", "burn-out", "cercle-autonomie-energetique", "cercle-blockchain-crypto", "cercle-collaboratif", "cercle-des-arts", "cercle-d\u00e9mocratie", "cercle-education", "cercle-game-changers", "cercle-generation-2050", "cercle-intergenerationnel", "cercle-neurodiversit\u00e9", "cercle-permaculture", "cercle-sante", "changer-de-paradigme", "cohorte-2607", "cohorte-34", "cohorte-barcelone", "cohorte-belgique", "cohorte-bretagne", "cohorte-centre", "cohorte-geek", "cohorte-grece", "cohorte-grenoble", "cohorte-hdf", "cohorte-ile-de-france", "cohorte-loire", "cohorte-lyon-st-etienne", "cohorte-normandie", "cohorte-paca", "cohorte-scientifique", "cohorte-sud-ouest", "cohorte-suisse", "crapaud-fou-tv", "crapomobile", "desobeissance-civile", "dessins-citoyens-collectifs-booderies", "developpement-personnel", "doughnut-economics", "ecologie-biodiversite", "ecovillages-ecoquartiers", "education-populaire", "emancipation-outre-mer", "emmaus-pau-lescar", "empowerment", "energie", "faire-avancer-le-schmilblick-ecologique", "foret_bleue", "fou-a-lier", "general", "geopolitique", "gestion-de-l-eau", "gilets-jaunes", "how-to-low-tech", "info-desintox", "intelligence-artificielle", "intelligence-collective", "jeux-inde-1", "journee-univ-j-verne-nantes-4-juil-2019", "la-bascule-lobby-citoyen", "langage-vrai-anti-glossaire", "le-led", "lhomme-et-la-terre", "libre", "logiciel-libre", "meditation", "mutuelle-sociale-solidaire", "nature-simplicite-bienveillance", "no-gafam", "open-hardware", "p-2-p-dat", "philosophie", "pratiques-artistiques", "projet-cand-alterincub-centre", "psychologie-neurologie", "radio-crapaud", "recherches-biologie", "recueil-temoignages", "reflexion-sur-l-argent", "reflexion-sur-lamour", "rencontre-crapaud-kangourou", "right-to-repair", "semourais", "siteweb", "sociologie-de-l-effondrement", "solucracy", "survivalismes-et-resiliences", "terre-de-convergence", "tiers-lieux-apprenant", "tsunamis", "tvp-et-ebr", "wiki-crapaud-fou", "zero-dechet"]}, "messages": {"total": 186088, "recent": 13036}} \ No newline at end of file From 8e3beac4f626af37769127ee1e4a554c4a53c21b Mon Sep 17 00:00:00 2001 From: Mickael Date: Sun, 18 Aug 2019 23:25:18 +0200 Subject: [PATCH 07/10] Get active user --- scripts/generate_chat_info.py | 19 +++++++++++++++---- site/data/chat.json | 2 +- site/index.html | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index d5652e4..4b89bcb 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -27,21 +27,31 @@ def main(): print("Check channels") channels = getAllChannels(rocket) channels_total = len(channels) - + + users = [] for channel in channels: messages_total += int(channel["msgs"]) date = channel["lm"] channel_date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") if channel_date > recent_date: channels_recent += 1 - channels_list.append(channel["name"]) + print("Check messages for channels {}".format(channel['name'])) messages = rocket.channels_history(channel["_id"], oldest= recent_date, count= 10000).json() if messages["success"]: - messages_recent += len(messages["messages"]) + nbMessages = len(messages["messages"]) + messages_recent += nbMessages + channels_list.append((channel["name"], nbMessages)) + users.extend(map(lambda message: message["u"]["_id"], messages["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) + channels_recentlist = list(map(lambda channel: channel[0], channels_list)) + + crapauds_recent = len(set(users)) + info = { "crapauds": { "total": crapauds_total, @@ -50,7 +60,8 @@ def main(): "canaux": { "total": channels_total, "recent": channels_recent, - "liste": channels_list + # Get only the 10 first channels + "liste": channels_recentlist[0:10] }, "messages": { "total": messages_total, diff --git a/site/data/chat.json b/site/data/chat.json index 9f7a756..cb037e5 100644 --- a/site/data/chat.json +++ b/site/data/chat.json @@ -1 +1 @@ -{"crapauds": {"total": 2365, "recent": 0}, "canaux": {"total": 177, "recent": 99, "liste": ["accueil", "activite-et-travail", "agenda", "animation-crapauds", "audio-visuel-libre", "bnb-bonheur-national-brut", "bresil", "burn-out", "cercle-autonomie-energetique", "cercle-blockchain-crypto", "cercle-collaboratif", "cercle-des-arts", "cercle-d\u00e9mocratie", "cercle-education", "cercle-game-changers", "cercle-generation-2050", "cercle-intergenerationnel", "cercle-neurodiversit\u00e9", "cercle-permaculture", "cercle-sante", "changer-de-paradigme", "cohorte-2607", "cohorte-34", "cohorte-barcelone", "cohorte-belgique", "cohorte-bretagne", "cohorte-centre", "cohorte-geek", "cohorte-grece", "cohorte-grenoble", "cohorte-hdf", "cohorte-ile-de-france", "cohorte-loire", "cohorte-lyon-st-etienne", "cohorte-normandie", "cohorte-paca", "cohorte-scientifique", "cohorte-sud-ouest", "cohorte-suisse", "crapaud-fou-tv", "crapomobile", "desobeissance-civile", "dessins-citoyens-collectifs-booderies", "developpement-personnel", "doughnut-economics", "ecologie-biodiversite", "ecovillages-ecoquartiers", "education-populaire", "emancipation-outre-mer", "emmaus-pau-lescar", "empowerment", "energie", "faire-avancer-le-schmilblick-ecologique", "foret_bleue", "fou-a-lier", "general", "geopolitique", "gestion-de-l-eau", "gilets-jaunes", "how-to-low-tech", "info-desintox", "intelligence-artificielle", "intelligence-collective", "jeux-inde-1", "journee-univ-j-verne-nantes-4-juil-2019", "la-bascule-lobby-citoyen", "langage-vrai-anti-glossaire", "le-led", "lhomme-et-la-terre", "libre", "logiciel-libre", "meditation", "mutuelle-sociale-solidaire", "nature-simplicite-bienveillance", "no-gafam", "open-hardware", "p-2-p-dat", "philosophie", "pratiques-artistiques", "projet-cand-alterincub-centre", "psychologie-neurologie", "radio-crapaud", "recherches-biologie", "recueil-temoignages", "reflexion-sur-l-argent", "reflexion-sur-lamour", "rencontre-crapaud-kangourou", "right-to-repair", "semourais", "siteweb", "sociologie-de-l-effondrement", "solucracy", "survivalismes-et-resiliences", "terre-de-convergence", "tiers-lieux-apprenant", "tsunamis", "tvp-et-ebr", "wiki-crapaud-fou", "zero-dechet"]}, "messages": {"total": 186088, "recent": 13036}} \ No newline at end of file +{"crapauds": {"total": 2365, "recent": 181}, "canaux": {"total": 177, "recent": 99, "liste": ["semourais", "accueil", "general", "right-to-repair", "wiki-crapaud-fou", "cohorte-loire", "reflexion-sur-l-argent", "le-led", "empowerment", "libre"]}, "messages": {"total": 186095, "recent": 13043}} \ No newline at end of file diff --git a/site/index.html b/site/index.html index 9d53dc0..e4e8ee4 100644 --- a/site/index.html +++ b/site/index.html @@ -143,12 +143,12 @@
0 crapauds actifs
0 canaux actifs
-
0 nouveaux messages
+
0 messages
-
Les canaux les plus actifs sur 30 jours
+
Les 10 canaux les plus actifs sur 30 jours
From 09607b974aef520f4afaeabe4310bb797d6d41ca Mon Sep 17 00:00:00 2001 From: Mickael Date: Sun, 18 Aug 2019 23:34:23 +0200 Subject: [PATCH 08/10] To test CI --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2073add..3fe4764 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,9 @@ pages: stage: deploy script: - sh ./scripts/generate.sh - - cp -r site public - artifacts: - paths: - - public - only: - - master \ No newline at end of file + # - cp -r site public + # artifacts: + # paths: + # - public + # only: + # - master \ No newline at end of file From 1ffea245ab2ee6df250b26e28f665f1fd83e0ed0 Mon Sep 17 00:00:00 2001 From: Mickael Date: Sun, 18 Aug 2019 23:35:38 +0200 Subject: [PATCH 09/10] change image --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3fe4764..bcd13e2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: alpine +image: frolvlad/alpine-python3 pages: stage: deploy From 8b17a0e8fa9e33a1ea2ed3468208538b1556fbd2 Mon Sep 17 00:00:00 2001 From: Mickael Date: Sun, 18 Aug 2019 23:38:37 +0200 Subject: [PATCH 10/10] It's good --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bcd13e2..86187e1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,9 @@ pages: stage: deploy script: - sh ./scripts/generate.sh - # - cp -r site public - # artifacts: - # paths: - # - public - # only: - # - master \ No newline at end of file + - cp -r site public + artifacts: + paths: + - public + only: + - master \ No newline at end of file