diff --git a/scripts/common/savehelper.py b/scripts/common/savehelper.py new file mode 100644 index 0000000..e011f7a --- /dev/null +++ b/scripts/common/savehelper.py @@ -0,0 +1,12 @@ +import json, os + +def save(info, filename): + # 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, '{}.json'.format(filename))) + with open(statsFilePath, "w") as file_write: + json.dump(info, file_write) \ No newline at end of file diff --git a/scripts/generate_chat_info.py b/scripts/generate_chat_info.py index 9c83c02..51f969f 100644 --- a/scripts/generate_chat_info.py +++ b/scripts/generate_chat_info.py @@ -4,6 +4,7 @@ import json from datetime import datetime from monthdelta import monthdelta from common.rocketchathelper import getAllChannels, Connection +from common.savehelper import save def main(): print("Start chat info generation") @@ -79,20 +80,9 @@ def main(): "cohortes": cohortes } - save(info) + save(info, "chat") print("End chat info generation") -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 getAllActiveUsers(rocket): index = 0 allUsers = [] diff --git a/scripts/generate_global_info.py b/scripts/generate_global_info.py index 8a85cf9..9ef6131 100644 --- a/scripts/generate_global_info.py +++ b/scripts/generate_global_info.py @@ -1,5 +1,6 @@ import os, json, pytz from datetime import datetime, timedelta +from common.savehelper import save def main(): @@ -10,19 +11,7 @@ def main(): info = { "lastupdate": datetime.strftime(now, "%d/%m/%Y %X") } - 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, 'global.json')) - with open(statsFilePath, "w") as file_write: - json.dump(info, file_write) - + save(info, "global") if __name__ == "__main__": main() \ No newline at end of file diff --git a/scripts/getstats.py b/scripts/getstats.py index 9405626..c08f2f2 100644 --- a/scripts/getstats.py +++ b/scripts/getstats.py @@ -11,6 +11,7 @@ import random from datetime import datetime from monthdelta import monthdelta from common.rocketchathelper import getTsunamy, Tsunami, getAllChannels, Connection +from common.savehelper import save def getColor(): r = random.randrange(255) @@ -18,17 +19,6 @@ def getColor(): b = random.randrange(255) return 'rgb({:0},{:0},{:0})'.format(r,g,b) -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, 'channelsstat.json')) - with open(statsFilePath, "w") as file_write: - json.dump(info, file_write) - def createElement(label, color, data) : return { "label": label, @@ -133,7 +123,7 @@ def main(): userGlobal = createElement( 'global', 'red', uniqueUserGlobal) usersGlobal.append(userGlobal) - save(info) + save(info, "channelsstat")