mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:57:08 +00:00
38 lines
819 B
Python
Executable File
38 lines
819 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
"""
|
|
Import survey configuration.
|
|
|
|
Imports the content of the YAML survey configuration files
|
|
into the database (as JSON) so their data is available to
|
|
database functions and procedures.
|
|
"""
|
|
|
|
import json
|
|
from glob import glob
|
|
import configuration
|
|
from datastore import Datastore
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print("Reading configuration")
|
|
configs = configuration.files(include_archived = True)
|
|
|
|
print("Connecting to database")
|
|
db = Datastore()
|
|
#db.connect()
|
|
|
|
print("Reading surveys")
|
|
for config in configs:
|
|
filepath = config[0]
|
|
survey = config[1]
|
|
print(f'Survey: {survey["id"]} ({filepath})')
|
|
db.set_survey(survey["schema"])
|
|
if not db.file_in_db(filepath):
|
|
print("Saving to DB")
|
|
db.save_file_data(filepath, json.dumps(survey))
|
|
else:
|
|
print("Already in DB")
|
|
|
|
print("Done")
|