-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_avacloud.py
83 lines (74 loc) · 3.51 KB
/
hello_avacloud.py
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
76
77
78
79
80
81
82
83
from __future__ import print_function
import time
import avacloud_client_python
from avacloud_client_python.rest import ApiException
from pprint import pprint
import requests
import os
import json
client_id = 'use_your_own_value'
client_secret = 'use_your_own_value'
url = 'https://identity.dangl-it.com/connect/token'
payload = {'grant_type': 'client_credentials', 'scope': 'avacloud'}
response = requests.post(url, data=payload, auth=(client_id, client_secret))
access_token = response.json()['access_token']
# Configure OAuth2 access token for authorization: Dangl.Identity
configuration = avacloud_client_python.Configuration()
configuration.access_token = access_token
api_instance = avacloud_client_python.GaebConversionApi(avacloud_client_python.ApiClient(configuration))
gaeb_file = './GAEBXML_EN.X86' # File path to the input GAEB file
# First, the AVA Project is generated
try:
# Converts GAEB files to Dangl.AVA projects
api_response = api_instance.gaeb_conversion_convert_to_ava(gaeb_file=gaeb_file, remove_plain_text_long_texts=False, remove_html_long_texts=False)
pprint(api_response)
except ApiException as e:
print("Exception when calling GaebConversionApi->gaeb_conversion_convert_to_ava: %s\n" % e)
# Then, the GAEB input file is converted to excel and saved locally
try:
# Converts GAEB files to Excel
# See https://github.com/swagger-api/swagger-codegen/issues/2305 for more info about why you should use _preload_content=False
# If the _preload_content parameter is not set to False, the binary response content (file) will be attempted to be decoded as UTF8 string,
# this would lead to an error. Instead, the raw response should be used
api_response = api_instance.gaeb_conversion_convert_to_excel(gaeb_file=gaeb_file, write_prices=True, write_long_texts=True, conversion_culture='en', _preload_content=False)
with open("./GAEB_Conversion_Result.xlsx", "wb") as excel_file:
excel_file.write(api_response.data)
except ApiException as e:
print("Exception when calling GaebConversionApi->gaeb_conversion_convert_to_excel: %s\n" % e)
# Finally, a new project is created and converted to GAEB
try:
ava_api_instance = avacloud_client_python.AvaConversionApi(avacloud_client_python.ApiClient(configuration))
ava_project = json.loads("""{"serviceSpecifications": [
{
"elements": [
{
"elementTypeDiscriminator": "PositionDto",
"shortText": "Concrete Wall",
"unitTag": "m²",
"quantityComponents": [
{
"formula": "10"
}
],
"priceComponents": [
{
"values": [
{
"formula": "80"
}
]
}
]
}
]
}
]
}""")
# See https://github.com/swagger-api/swagger-codegen/issues/2305 for more info about why you should use _preload_content=False
# If the _preload_content parameter is not set to False, the binary response content (file) will be attempted to be decoded as UTF8 string,
# this would lead to an error. Instead, the raw response should be used
api_response = ava_api_instance.ava_conversion_convert_to_gaeb(ava_project, destination_gaeb_type='GaebXml_V3_2', _preload_content=False)
with open("./CreatedGaebXml.X86", "wb") as gaeb_file:
gaeb_file.write(api_response.data)
except ApiException as e:
print("Exception when calling AvaConversionApi->ava_conversion_convert_to_gaeb: %s\n" % e)