Skip to content

Commit 04d44de

Browse files
committed
scripts: add option to create all entities
1 parent 1fce571 commit 04d44de

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

scripts/create_sample_data.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,41 @@ async def create_concepts_for_scheme(scheme_id: str):
143143
except Exception as e:
144144
print(f"Failed to create concept {j} for scheme {scheme_id}: {str(e)}")
145145

146+
async def create_all_data():
147+
"""Create all sample data - schemes and concepts for all schemes."""
148+
configuration = pyst_client.Configuration(
149+
host=API_URL,
150+
api_key={"X-PyST-Auth-Token": API_TOKEN}
151+
)
152+
153+
async with pyst_client.ApiClient(configuration) as api_client:
154+
concept_scheme_api = pyst_client.ConceptSchemeApi(api_client)
155+
concept_api = pyst_client.ConceptApi(api_client)
156+
157+
# Create schemes
158+
for i in range(1, 11):
159+
try:
160+
scheme = create_concept_scheme(i)
161+
response = await concept_scheme_api.concept_scheme_create_concept_scheme_post(
162+
concept_scheme_input=scheme,
163+
x_pyst_auth_token=API_TOKEN
164+
)
165+
print(f"Created concept scheme {i} successfully")
166+
167+
# Create concepts for this scheme
168+
for j in range(1, 6):
169+
try:
170+
concept = create_concept(scheme.id, j)
171+
await concept_api.concept_create_concept_post(
172+
concept_create=concept,
173+
x_pyst_auth_token=API_TOKEN
174+
)
175+
print(f"Created concept {j} for scheme {i} successfully")
176+
except Exception as e:
177+
print(f"Failed to create concept {j} for scheme {i}: {str(e)}")
178+
except Exception as e:
179+
print(f"Failed to create concept scheme {i}: {str(e)}")
180+
146181
async def main():
147182
"""Create sample data - either schemes, concepts, or both."""
148183
import argparse
@@ -151,8 +186,13 @@ async def main():
151186
parser.add_argument('--schemes', action='store_true', help='Create concept schemes')
152187
parser.add_argument('--concepts', action='store_true', help='Create concepts')
153188
parser.add_argument('--scheme-id', type=str, help='Scheme ID to create concepts for (required if --concepts is used)')
189+
parser.add_argument('--all', action='store_true', help='Create all sample data (schemes and concepts)')
154190
args = parser.parse_args()
155191

192+
if args.all:
193+
await create_all_data()
194+
return
195+
156196
if args.schemes:
157197
await create_schemes()
158198

0 commit comments

Comments
 (0)