refacto for save
This commit is contained in:
parent
ce421523f6
commit
00b4a112bd
4 changed files with 18 additions and 37 deletions
12
scripts/common/savehelper.py
Normal file
12
scripts/common/savehelper.py
Normal 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)
|
|
@ -4,6 +4,7 @@ import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from monthdelta import monthdelta
|
from monthdelta import monthdelta
|
||||||
from common.rocketchathelper import getAllChannels, Connection
|
from common.rocketchathelper import getAllChannels, Connection
|
||||||
|
from common.savehelper import save
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Start chat info generation")
|
print("Start chat info generation")
|
||||||
|
@ -79,20 +80,9 @@ def main():
|
||||||
"cohortes": cohortes
|
"cohortes": cohortes
|
||||||
}
|
}
|
||||||
|
|
||||||
save(info)
|
save(info, "chat")
|
||||||
print("End chat info generation")
|
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):
|
def getAllActiveUsers(rocket):
|
||||||
index = 0
|
index = 0
|
||||||
allUsers = []
|
allUsers = []
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os, json, pytz
|
import os, json, pytz
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from common.savehelper import save
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
@ -10,19 +11,7 @@ def main():
|
||||||
info = {
|
info = {
|
||||||
"lastupdate": datetime.strftime(now, "%d/%m/%Y %X")
|
"lastupdate": datetime.strftime(now, "%d/%m/%Y %X")
|
||||||
}
|
}
|
||||||
save(info)
|
save(info, "global")
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -11,6 +11,7 @@ import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from monthdelta import monthdelta
|
from monthdelta import monthdelta
|
||||||
from common.rocketchathelper import getTsunamy, Tsunami, getAllChannels, Connection
|
from common.rocketchathelper import getTsunamy, Tsunami, getAllChannels, Connection
|
||||||
|
from common.savehelper import save
|
||||||
|
|
||||||
def getColor():
|
def getColor():
|
||||||
r = random.randrange(255)
|
r = random.randrange(255)
|
||||||
|
@ -18,17 +19,6 @@ def getColor():
|
||||||
b = random.randrange(255)
|
b = random.randrange(255)
|
||||||
return 'rgb({:0},{:0},{:0})'.format(r,g,b)
|
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) :
|
def createElement(label, color, data) :
|
||||||
return {
|
return {
|
||||||
"label": label,
|
"label": label,
|
||||||
|
@ -133,7 +123,7 @@ def main():
|
||||||
userGlobal = createElement( 'global', 'red', uniqueUserGlobal)
|
userGlobal = createElement( 'global', 'red', uniqueUserGlobal)
|
||||||
usersGlobal.append(userGlobal)
|
usersGlobal.append(userGlobal)
|
||||||
|
|
||||||
save(info)
|
save(info, "channelsstat")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue