Created
September 1, 2020 20:49
-
-
Save alvarotuso/9d5d78ee5932a2a16a8fd14d38d72bb4 to your computer and use it in GitHub Desktop.
Hubspot field definitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
HS_TYPE_MAP = { | |
'string': 'string', | |
'number': 'float', | |
'enumeration': 'string', | |
'datetime': 'datetime', | |
'date': 'date', | |
'bool': 'bool' | |
} | |
def process_properties(obj): | |
with open(f'./{obj}_properties.json') as f: | |
properties = json.loads(f.read()) | |
processed_properties = [] | |
for p in properties: | |
processed_property = { | |
'name': p['name'], | |
'display_name': p['label'], | |
'type': HS_TYPE_MAP[p['type']], | |
'typeahead': p['type'] == 'string', | |
'multivalued': False | |
} | |
if p['type'] == 'enumeration': | |
processed_property['enum'] = [{ | |
'display_value': opt['label'], | |
'value': opt['value'] | |
} for opt in p['options']] | |
processed_properties.append(processed_property) | |
with open(f'./{obj}_attribute_definitions.json', 'w') as f: | |
f.write(json.dumps(processed_properties)) | |
if __name__ == '__main__': | |
for obj in ('company', 'deal'): | |
process_properties(obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment