refacto for save

This commit is contained in:
Mickael 2019-09-01 13:12:30 +02:00
parent ce421523f6
commit 00b4a112bd
4 changed files with 18 additions and 37 deletions

View file

@ -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)

View file

@ -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 = []

View file

@ -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()

View file

@ -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")