-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_export_schemas.py
More file actions
75 lines (56 loc) · 3.28 KB
/
Copy pathmain_export_schemas.py
File metadata and controls
75 lines (56 loc) · 3.28 KB
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
71
72
73
74
75
import requests
import json
import os
from methods import init_session
from methods import recursively_truncate_enumeration, recursively_get_parameter_names_in_blockquote
from methods import check_for_prefix
rh, settings, src_project, _ = init_session(validate_src=True, validate_target=False)
org_id = settings["srcOrgId"]
project_id = settings["srcProjectId"]
environment_id = settings["srcEnvId"]
project_name = src_project.get("name", "Unknown Project")
print(" EXPORT SCHEMAS AS MARKDOWN ")
print("-------------------------------------------------")
print(f"Here's a link to the source project {project_name}:")
print(f"https://cloud.unity.com/home/organizations/{org_id}/projects/{project_id}/environments/{environment_id}")
input("If this is correct, press enter to continue... If not, terminate the script and change the settings.json file.")
print("thanks! beginning...")
newpath = ".\outputs\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
#------------------------------get the source schemas and parameters--------------------
src_schemas = rh.get_schemas(org_id, project_id, environment_id)
if not src_schemas:
print("No schemas found in source project. This probably means your token is expired. Look in the cookie for https://cloud.unity.com/, under 'token'.")
print("Store the latest token in token.auth and re-run the script.")
print("Exiting...")
exit(1)
schema_names = [x["name"] for x in src_schemas ]
src_schemas = {x["name"]: x for x in src_schemas}
# read token from token.auth
#-------------------------------get the target schemas and parameters--------------------
#-------------------------------these already exist, and should not be created--------------------
with (open(f"outputs/{project_name}_{project_id}_schemas.md", "w+", encoding="UTF-8")) as f:
f.write(f"# Schemas for project {project_name} [{project_id}](https://cloud.unity.com/home/organizations/{org_id}/projects/{project_id}/environments/{environment_id})")
f.write("\n\n")
f.write("The following is an output of **all** event schemas for the project, including the standard Unity Analytics events. \n")
for event_name, event in src_schemas.items():
event:dict
# convert the event from GET to POST format
original_event_desc = str.strip(event.get("description", ""))
compiled_schema = json.loads(event["schema"])
compiled_event, list_of_truncated_enums = recursively_truncate_enumeration("",compiled_schema,[])
is_enabled = event.get("isEnabled", True)
basic_output = recursively_get_parameter_names_in_blockquote("", compiled_event)
fancy_output = json.dumps(compiled_schema, indent=4)
f.write(f"## {event_name}\n")
f.write(f"**Description:** {original_event_desc} \n")
f.write(f"**Event Version:** {event.get('version', 'Unknown')} \n")
f.write(f"**Enabled:** {event.get('isEnabled')} \n")
f.write(f"**Restricted:** {event.get('isRestricted', False)} \n")
f.write(f"**Predefined:** {event.get('isPredefined', False)} \n")
f.write("**Parameter summary:**\n")
f.write(basic_output)
f.write("\n\n")
f.write("**Actual Event schema:**\n")
f.write(f"```json\n{fancy_output}\n```\n")