1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# Primitives de l'archivage des données d'application
#
# Chargement des données : ChargeDonnees()
# Archivage des données : ArchiveDonnees()
#
# Début : 24 nov 2019
#
import json
import zipfile
import Alertes
Bandes = {
"BP1":{"latitude": 42, "longitude":2, "longueur":100, "largeur":5},
"BP2":{"latitude": 42.5, "longitude":2, "longueur":80, "largeur":2.5},
"HF1":{"latitude": 42, "longitude":1.9, "longueur":100, "largeur":1.5},
"HF2":{"latitude": 42, "longitude": 2.1, "longueur":100, "largeur":1.5}
}
Cultures = {
"BP1-0-190324":{"bande":"BP1", "position": 0, "nature":"Consoude", "nbUK":2},
"BP1-0.5-190324":{"bande":"BP1", "position": 0.5, "nature":"Fraise", "nbUK":4},
"BP1-4.5-190324":{"bande":"BP1", "position": 4.5, "nature":"Topinambour", "nbUK":2}
}
Actions = {
"PrepBin":{"Lib":"Binage de préparation", "outil":{"griffe"},"spécs":""}
}
Actes = {
"CodeDateUnique":{"culture":"BP1-0.5-190324", "Action":"PrepBin", "Comment":""},
"CodeDateUnique":{"culture":"", "Action":{"Pluie":"", "hauteur":20}, "Comment":""}
}
def ArchiveDonnees1():
with open('Bandes.json','w') as f : json.dump(Bandes,f, indent=4)
with open('Cultures.json','w') as f: json.dump(Cultures,f, indent=4)
Alertes.AlerteStatusBar('Données archivées',10000)
# constitution du fichier global regroupant tous les json dans un fichier archive
# technologie à maîtriser qui donne un fichier analogue à .odt (ou d'autres!)
with zipfile.ZipFile('pack.aptbase', 'w') as pack:
pack.write('Bandes.json')
pack.write('Cultures.json')
pack.close()
Alertes.AlerteStatusBar('Pack de données archivé',10000)
def ArchiveDonnees2():
# constitution du fichier global regroupant tous les json dans un fichier archive
# technologie à maîtriser qui donne un fichier analogue à .odt (ou d'autres!)
with zipfile.ZipFile('pack.aptbase', 'w') as pack:
with pack.open('Bandes.json','w') as f : json.dump(Bandes,f, indent=4)
with pack.open('Cultures.json','w') as f: json.dump(Cultures,f, indent=4)
pack.close()
Alertes.AlerteStatusBar('Pack de données archivé',10000)
def ChargeDonnees():
#with open('Bandes.json','r') as f : Bandes=json.load(f)
#with open('Cultures.json','r') as f : Cultures=json.load(f)
with zipfile.ZipFile('pack.aptbase', 'r') as pack:
with pack.open('Bandes.json','r') as f :
Bandes=json.load(f)
print(Bandes)
with pack.open('Cultures.json','r') as f :
Cultures=json.load(f)
print(Cultures)
pack.close() |
Partager