Skip to content

Instantly share code, notes, and snippets.

@alvarotuso
Created September 1, 2020 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvarotuso/9d5d78ee5932a2a16a8fd14d38d72bb4 to your computer and use it in GitHub Desktop.
Save alvarotuso/9d5d78ee5932a2a16a8fd14d38d72bb4 to your computer and use it in GitHub Desktop.
Hubspot field definitions
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