-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsportkadaster_api_tools.py
1143 lines (993 loc) · 43.9 KB
/
sportkadaster_api_tools.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 8 14:11:04 2020
@author: dverdoodt
@ tools for the sportkadaster API
"""
import requests
import json
import pandas as pd
from datetime import datetime
########################################################
### make request bodies
########################################################
def makeRequestBodyActivity(language='fr', activityId=0, name=""):
"""
Returns
-------
dict: request body for the subsidy API.
"""
request_body = {
"request": {
"filter": {
"language": language,
"page": 0,
"itemsPerPage": 10
},
"activityFilter": {
"id": activityId,
"name": name
}
}
}
return request_body
def makeRequestbodySubsidy(language='fr', subsidyId=0, subsidyOrganisation='', status='',lastModificationDate=None):
"""
returns the request body (dictionary) for the subsidy API
"""
request_body = {
"request": {
"filter": {
"language": language,
"page": 0,
"itemsPerPage": 0
},
"subsidyFilter": {
"id": subsidyId,
"subsidyOrganization": subsidyOrganisation,
"status": status,
"lastModificationDate": lastModificationDate
}
}
}
return request_body
def makeRequestBodyOrganisation(language='fr', organisationId=None, organisationMainId=None,
name='', shortName='', partOfTheName='', status= '',
referenceKey='', companyNumber='', organizationType='',
startDate=None, endDate=None, lastModificationDate=None,
publish=True,
showDetails=True, showPeople=True, showOrganizationActivities=True,
showInfrastructures=True, showPlaces=True, showChildOrganizations=True,
isClub=True):
"""
Returns
-------
dict: request body for the subsidy API.
"""
request_body = {
"request": {
"generalFilter": {
"language": language,
"page": 0,
"itemsPerPage": 0
},
"organisationFilter": {
"id": organisationId,
"mainId": organisationMainId,
"name": name,
"shortName": shortName,
"partOfTheName": partOfTheName,
"status": status,
"referenceKey": referenceKey,
"companyNumber": companyNumber,
"organizationType": organizationType,
"startDate": startDate,
"endDate": endDate,
"lastModificationDate": lastModificationDate,
"publish": publish
},
"showDetails": showDetails,
"showPeople": showPeople,
"showOrganizationActivities": showOrganizationActivities,
"showInfrastructures": showInfrastructures,
"showPlaces": showPlaces,
"showChildOrganizations": showChildOrganizations,
"isClub": isClub
}
}
return request_body
def makeRequestBodyAudience(language='fr', audienceId=0, audienceName=""):
request_body = {
"request": {
"filter": {
"language": language,
"page": 0,
"itemsPerPage": 0
},
"audienceFilter": {
"id": audienceId,
"name": audienceName
}
}
}
return request_body
def makeRequestBodyEvents(language='fr', eventId=None, eventMainId=None,
name="", status="", referenceKey="",
organisationMainId=None, isRegular=True,
publish=True, lastModificationDate="2020-01-01T00:00:00",
showDetails=True, showActivities=True, showAudience=True):
request_body = {
"request": {
"filter": {
"language": language,
"page": 1,
"itemsPerPage": 10
},
"eventFilter": {
"id": eventId,
"mainId": eventMainId,
"name": name,
"status": status,
"referenceKey": referenceKey,
"organizationMainId": organisationMainId,
"isRegular": isRegular,
"publish": publish,
"lastModificationDate": lastModificationDate
},
"showDetails": showDetails,
"showActivities": showActivities,
"showAudience": showAudience
}
}
return request_body
def makeRequestBodyFacilityType(language='fr', facilityTypeId=0, facilityTypeName=""):
request_body = {
"request": {
"filter": {
"language": language,
"page": 0,
"itemsPerPage": 0
},
"facilityTypeFilter": {
"id": facilityTypeId,
"name": facilityTypeName
}
}
}
return request_body
def makeRequestBodyFacility(language='fr', facilityId=None, facilityMainId=None,
name="", status="", referenceKey="", infrastructureMainId=None,
organizationMainId=None, facilityType="", lastModificationDate="2020-01-01T00:00:00",
showDetails=True, showActivity=True, showFacilityTypeValues=True):
request_body = {
"request": {
"filter": {
"language": language,
"page": 0,
"itemsPerPage": 0
},
"facilityFilter": {
"id": facilityId,
"mainId": facilityMainId,
"name": name,
"status": status,
"referenceKey": referenceKey,
"infrastrucutreMainId": infrastructureMainId,
"organizationMainId": organizationMainId,
"facilityType": facilityType,
"lastModificationDate": lastModificationDate
},
"showDetails": showDetails,
"showActivity": showActivity,
"showFacilityTypeValues": showFacilityTypeValues
}
}
return request_body
def makeRequestBodyPlaces(language='en', placeId=None, placeMainId=None,
name='', status='', addressPostalCode='',
lastModificationDate=None, publish=True,
showDetails=True, showProperties=True,
showOrganisations=True, showInfrastructures=True):
request_body = {
"request": {
"filter": {
"language": language,
"page": 0,
"itemsPerPage": 0
},
"placeFilter": {
"id": placeId,
"mainId": placeMainId,
"name": name,
"status": status,
"addressPostalCode": addressPostalCode,
"lastModificationDate": lastModificationDate,
"publish": publish
},
"showDetails": showDetails,
"showProperties": showProperties,
"showOrganisations": showOrganisations,
"showInfrastructures": showInfrastructures
}
}
return request_body
def makeRequestBodyInfrastructure(language='fr', infrastructureId=None, infrastructureMainId=None,
name="", status="", referenceKey="", publish=True,
lastModificationDate="2020-01-01T00:00:00",
showDetails=True, showOrganisations=True,
showClubs=True, showFacilities=True,
showProperties=True, showImages=True):
request_body = {
"request": {
"filter": {
"language": language,
"page": 0,
"itemsPerPage": 0
},
"infrastructureFilter": {
"id": infrastructureId,
"mainId": infrastructureMainId,
"name": name,
"status": status,
"referenceKey": referenceKey,
"publish": publish,
"lastModificationDate": lastModificationDate
},
"showDetails": showDetails,
"showOrganisations": showOrganisations,
"showClubs": showClubs,
"showFacilities": showFacilities,
"showProperties": showProperties,
"showImages": showImages
}
}
return request_body
def getActivities(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
activities : Nested list: Id, ParentId, TranslatedName
"""
url = end_point + '/api/Activity/GetActivities'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
activities_extended_list = response.json()['response']
activities = []
# append header names
activities.append(['id', 'parentId', 'translatedName'])
for i, activity in enumerate(activities_extended_list):
activities.append([activity['id'], activity['parentId'], activity['translatedName']])
# Convert to pandas dataframe
df_activities = pd.DataFrame(activities[1:], columns=activities[0])
return df_activities
def getMainActivities(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
activities : Nested list: Id, ParentId, TranslatedName
"""
url = end_point + '/api/Activity/GetActivities'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
mainActivities_extended_list = response.json()['response']
mainActivities = []
# append header names
mainActivities.append(['id', 'parentId', 'translatedName'])
for i, mainActivity in enumerate(mainActivities_extended_list):
# Main activities do not have a parentId
if mainActivity['parentId'] == None:
mainActivities.append([mainActivity['id'], mainActivity['parentId'], mainActivity['translatedName']])
# Convert to pandas dataframe
df_mainActivities = pd.DataFrame(mainActivities[1:], columns=mainActivities[0])
return df_mainActivities
def getAudiences(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
audiences - Dataframe: id, name, translatedName, minAge, maxAge, disabled, gender, type
"""
url = end_point + '/api/Audience/GetAudiences'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
audiences_extended_list = response.json()['response']
audiences = []
# append header names
audiences.append(['id', 'name', 'translatedName', 'minAge', 'maxAge', 'disabled', 'gender', 'type'])
for i, audience in enumerate(audiences_extended_list):
audiences.append(
[audience['id'],
audience['name'],
audience['translatedName'],
audience['minAge'],
audience['maxAge'],
audience['disabled'],
audience['gender'],
audience['type']
])
# Convert to pandas dataframe
df_audiences = pd.DataFrame(audiences[1:], columns=audiences[0])
return df_audiences
def getEvents(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
events - Nested list
"""
url = end_point + '/api/Event/GetEvents'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
events_extended_list = response.json()['response']
##print(events_extended_list)
#print('')
events = []
# append header names
events.append(['id', 'isVisibleOnWebsite', 'activityType', 'status',
# name and description
'name', 'description',
# location - extra infos
'placeMainId',
'place',
# details
'isPublic', 'isCompetitive', 'isEntertaining', 'isFree',
'fares', 'dayWeek', 'startDate', 'startTime', 'endDate', 'endTime',
'isRegular',
'eventActivities', 'eventAudiences',
'eventLanguages',
# Contact info
'organiser',
'surname', 'firstname',
'organisation', 'organiserPeople',
'mail','website'
])
for i, event in enumerate(events_extended_list):
# languages
if not event['details']['eventLang'] == None:
languageList = [language['translatedUsedLanguage'] for language in event['details']['eventLang']]
else:
languageList = None
if not event['basicInfo'] == None:
events.append(
[event['basicInfo']['id'], # id in URL. eventId
event['basicInfo']['publish'], # isVisibleOnWebsite
event['basicInfo']['translatedType'], # activityType
event['details']['status'],
event['details']['eventLg'][0]['name'],
event['details']['eventLg'][0]['description'],
event['details']['placeMainId'],
event['details']['eventLg'][0]['place'], # location - extra infos
event['details']['public'], # isPublic
event['details']['competitive'], # isCompetitive
event['details']['entertaining'], # isEntertaining
event['details']['free'], # isFree
event['details']['eventLg'][0]['fares'],
event['details']['timetable'][0]['dayWeek'],
stringToDate(event['details']['timetable'][0]['start']),
stringToTime(event['details']['timetable'][0]['start']),
stringToDate(event['details']['timetable'][0]['end']),
stringToTime(event['details']['timetable'][0]['end']),
event['details']['isRegular'],
event['eventActivity'],
event['eventAudience'],
languageList,
event['details']['eventLg'][0]['organiser'],
event['details']['contact']['name'],
event['details']['contact']['firstname'],
event['details']['organisation'],
event['details']['organiserPeople'],
event['details']['mail'],
event['details']['website'],
])
# Convert to pandas dataframe
df_events = pd.DataFrame(events[1:], columns=events[0])
return df_events
def getFacilityTypes(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
audiences - Nested list
"""
url = end_point + '/api/Facility/GetFacilityType'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
facilityTypes_extended_list = response.json()['response']
facilityTypes = []
# append header names
facilityTypes.append(['id', 'translatedName', 'status', 'facilityTypes'])
facilityTypeDict = {'R':'Radio button', 'C':'Check boxes', 'F':'Text fields',
'M':'Comment field', 'S':'Drop down', 'T': 'Time',
'D':'Date', 'I':'Integer', 'A':'Disciplines', 'H': 'Title'
}
for i, facilityType in enumerate(facilityTypes_extended_list):
# facilityTypeField
# facilityTypeFields = ''
# for element in facilityType['facilityTypeField']:
# facilityTypeFields += '{0}; '.format(element['name'])
facilityTypeFields = []
facilityTypeName = [element['name'] for element in facilityType['facilityTypeField']]
facilityTypeValues = [element['valueType'] for element in facilityType['facilityTypeField']] # datatype
facilityTypeValues = [facilityTypeDict.get(x, x) for x in facilityTypeValues]
facilityTypeMandatory = [element['mandatory'] for element in facilityType['facilityTypeField']]
facilityTypeMandatory = ['*' if x == True else '' for x in facilityTypeMandatory]
for i, element in enumerate(facilityTypeName):
facilityTypeFields.append(element + facilityTypeMandatory[i] + '(' + facilityTypeValues[i] +')')
facilityTypes.append(
[facilityType['id'],
facilityType['translatedName'],
facilityType['status'],
facilityTypeFields #name + mandatory + (type)
])
# Convert to pandas dataframe
df_facilityTypes = pd.DataFrame(facilityTypes[1:], columns=facilityTypes[0])
return df_facilityTypes
def getInfrastructures(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
events - Nested list
"""
url = end_point + '/api/Infrastructure/GetInfrastructures'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
infrastructures_extended_list = response.json()['response']
## print(infrastructures_extended_list)
infrastructures = []
# append header names
infrastructures.append(['id', 'mainId', 'referenceKey', 'name',
'organisations',
'clubs',
'facilities',
'status',
'details_automatedExternalDefibrillator',
'details_energyFile',
'details_inPlaceId',
'infrastructureProperties'])
for i, infrastructure in enumerate(infrastructures_extended_list):
# infrastructureName
if not infrastructure['basicInfo']['infrastructureLg'] == None:
infrastructureName = infrastructure['basicInfo']['infrastructureLg'][0]['name']
# this is redundant, because only one value for each language.
# infrastructureName = [language['name'] for language in infrastructure['basicInfo']['infrastructureLg']]
else:
infrastructureName == None
if not infrastructure['infrastructureProperties'] == None:
infraList = []
for infra in infrastructure['infrastructureProperties']:
## Concatenate number, translatedLabel and type|trasnlatedLabel, if not null-values
number = xstr(infra['number'])
translatedLabel1 = xstr(infra['translatedLabel'])
translatedLabel2 = xstr(infra['type']['translatedLabel'])
infraList.append('{0} {1} {2}'.format(translatedLabel1, translatedLabel2, number))
infrastructureProperties = '; '.join(infraList)
else:
infrastructureProperties == None
infrastructures.append(
[infrastructure['basicInfo']['id'],
infrastructure['basicInfo']['mainId'],
infrastructure['basicInfo']['referenceKey'],
infrastructureName,
infrastructure['organisations'],
infrastructure['clubs'],
infrastructure['facilities'],
infrastructure['details']['status'],
infrastructure['details']['automatedExternalDefibrillator'],
infrastructure['details']['energyFile'],
infrastructure['details']['inPlaceId'],
infrastructureProperties
])
# Convert to pandas dataframe
df_infrastructures = pd.DataFrame(infrastructures[1:], columns=infrastructures[0])
return df_infrastructures
def getOrganisations(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
events - Nested list
"""
url = end_point + '/api/Organisation/GetOrganisations'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
organisations_extended_list = response.json()['response']
# Subsidy status organisations
status_dict = {'N':'Non-Profit Organisation', 'U':'Unincorporated organisation', 'E':'Enterprise', 'P':'Public institution', None:'Undefined'}
organisations = []
# append header names
organisations.append(['id', 'nameEn', 'nameFr', 'nameNl',
'status',
'descriptionEn', 'descriptionFr', 'descriptionNl',
'infraManager', 'isClub',
'type name', 'subtype name', 'subtype info',
'reference key', 'companyNumber', 'vat', 'legalName', 'legalStatus',
'contact name', 'contact title', 'contact email', 'contact phone',
'infrastructures',
'places',
'organisationActivities',
'organisationActivitiesAudiences'])
for i, organisation in enumerate(organisations_extended_list):
# print(json.dumps(organisation, indent=2))
# type and subtype
typeName = None
subTypeName = None
subTypeInfo = None
if not organisation['details']['organisationType'] == None:
## Club Type = Associated counties
if not organisation['details']['organisationType']['type'] == None:
typeName = organisation['details']['organisationType']['type']['categoryBase']
subTypeName = organisation['details']['organisationType']['translatedTypeName']
subTypeInfo = None
## Club Type = County
if not organisation['details']['organisationType']['city'] == None:
typeName = organisation['details']['organisationType']['city']['categoryBase']
subTypeName = organisation['details']['organisationType']['translatedCityName']
subTypeInfo = organisation['details']['organisationType']['translatedTypeName']
## Club Type = Community
if not organisation['details']['organisationType']['community'] == None:
typeName = organisation['details']['organisationType']['community']['categoryBase']
subTypeName = organisation['details']['organisationType']['translatedCommunityName']
subTypeInfo = None
if not organisation['details']['organisationType']['level'] == None:
typeName = organisation['details']['organisationType']['level']['categoryBase']
subTypeName = organisation['details']['organisationType']['translatedLevelName']
subTypeInfo = None
## Club Type = Schools
if not organisation['details']['organisationType']['network'] == None:
typeName = organisation['details']['organisationType']['network']['categoryBase']
subTypeName = organisation['details']['organisationType']['translatedNetworkName']
subTypeInfo = organisation['details']['organisationType']['translatedLevelName'] + ' - ' + organisation['details']['organisationType']['translatedTypeName']
## Club Type = Brussels Capital Region
if not organisation['details']['organisationType']['service'] == None:
typeName = organisation['details']['organisationType']['service']['categoryBase']
subTypeName = organisation['details']['organisationType']['translatedServiceName']
subTypeInfo = None
# print(typeName)
# print(subTypeName)
# contact name, contact title, contact email, contact phone
contactName, contactTitle, contactEmail, contactPhone = '', '', '', ''
# persons = list()
if not organisation['people'] == None:
contactName = ';'.join(['{0} {1}'.format(xstr(person['firstname']), xstr(person['name'])) for person in organisation['people']])
contactTitle = ';'.join(['{0}'.format(xstr(person['title'])) for person in organisation['people']])
contactEmail = ';'.join(['{0}'.format(xstr(person['mail'])) for person in organisation['people']])
contactPhone = ';'.join(['{0} {1}'.format(xstr(person['phone']), xstr(person['mobile'])) for person in organisation['people']])
#for person in organisation['people']:
# persons.append('{0} {1}; '.format(person['firstname'], person['name']))
#people = concatenate_listitems(persons)
# infrastructures
infrastructures = organisation['infrastructures']
# places
places = organisation['places']
# organisationActivities
# organisationActivityAudience
organisationActivities = list()
organisationActivityAudiences = list()
if not organisation['organizationActivities'] == None:
for organisationActivity in organisation['organizationActivities']:
organisationActivities.append(organisationActivity['activityId'])
for organisationActivityAudience in organisationActivity['organisationActivityAudience']:
organisationActivityAudiences.append(organisationActivityAudience['audienceId'])
organisations.append(
[organisation['basicInfo']['id'],
organisation['basicInfo']['nameEn'],
organisation['basicInfo']['nameFr'],
organisation['basicInfo']['nameNl'],
organisation['details']['status'],
organisation['details']['descriptionEn'],
organisation['details']['descriptionFr'],
organisation['details']['descriptionNl'],
organisation['details']['infraManager'],
organisation['details']['isClub'],
typeName, # type name
subTypeName, # subtype name
subTypeInfo, # subtype info
organisation['basicInfo']['referenceKey'],
organisation['details']['companyNumber'],
organisation['details']['vat'],
organisation['details']['legalName'],
status_dict[organisation['details']['legalStatus']],
contactName, # contact name
contactTitle, # contact title
contactEmail, # contact email
contactPhone, # contact phone
infrastructures,
places,
organisationActivities,
organisationActivityAudiences
])
# Convert to pandas dataframe
df_organisations = pd.DataFrame(organisations[1:], columns=organisations[0])
return df_organisations
def getPlaces(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
events - Nested list
"""
url = end_point + '/api/Place/GetPlaces'
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
places_extended_list = response.json()['response']
# print(places_extended_list)
places = []
# append header names
places.append(['id', 'nameEn', 'nameFr', 'nameNl', 'status',
'streetFr', 'streetNl', 'number', 'postCode', 'city',
'address', 'isUrbisAddress', 'urbisRef_x', 'urbisRef_y', 'sector',
'ownerType','isPublic', 'isSchool',
'property_carparking_isAvailable', 'property_carSpace',
'property_carSpacePMR', 'property_carSpaceVIP', 'property_carSpaceBus',
'property_hasConvivialityArea', 'property_bikeparking_isAvailable',
'property_bikeparking_totalSpaces', 'property_bikeparking_isSecured',
'property_bikeparking_isFullyCovered', 'property_playground',
'infrastructures', 'organisations'])
for i, place in enumerate(places_extended_list):
if not place['basicInfo'] == None:
coord_x = None
coord_y = None
if place['details']['addresses'][0]['urbisRef'] != None:
coords = place['details']['addresses'][0]['urbisRef']
#print(coords)
coord_x = float(coords.split(',')[1][:-1])
coord_y = float(coords.split(',')[0][1:])
property_carparking_isAvailable = None
property_carSpace = None
property_carSpacePMR = None
property_carSpaceVIP = None
property_carSpaceBus = None
property_hasConvivialityArea = None
property_bikeparking_isAvailable = None
property_bikeparking_totalSpaces = None
property_bikeparking_isSecured = None
property_bikeparking_isFullyCovered = None
property_playground = None
if not place['properties'] == None:
for prop in place['properties']:
# print('label is: {0}'.format(prop['type']['translatedLabel']))
# properties car parking, cafetaria, bike parking, playground
if prop['type']['translatedLabel'] == 'Parking':
property_carparking_isAvailable = prop['boolean']
if prop['type']['translatedLabel'] == 'Car space':
property_carSpace = prop['text']
if prop['type']['translatedLabel'] == 'Car Space-PMR':
property_carSpacePMR = prop['text']
if prop['type']['translatedLabel'] == 'Car Space-VIP':
property_carSpaceVIP = prop['text']
if prop['type']['translatedLabel'] == 'Car Space-Bus':
property_carSpaceBus = prop['text']
if prop['type']['translatedLabel'] == 'Conviviality Area':
property_hasConvivialityArea = prop['boolean']
if prop['type']['translatedLabel'] == 'Bike parking':
property_bikeparking_isAvailable = prop['boolean']
if prop['type']['translatedLabel'] == 'Total number of spaces':
property_bikeparking_totalSpaces = prop['text']
if prop['type']['translatedLabel'] == 'Secured':
property_bikeparking_isSecured = prop['boolean']
if prop['type']['translatedLabel'] == 'Fully covered':
property_bikeparking_isFullyCovered = prop['boolean']
if prop['type']['translatedLabel'] == 'Playground':
property_playground = prop['boolean']
#if prop['type']['translatedLabel'] == 'Min':
# property_playgroundMinAge = prop['text']
#if prop['type']['translatedLabel'] == 'Max':
# property_playgroundMaxAge = prop['text']
#if prop['type']['translatedLabel'] == 'Other':
# property_isOther = prop['boolean']
# print(places)
places.append(
[place['basicInfo']['id'],
place['basicInfo']['nameEn'],
place['basicInfo']['nameFr'],
place['basicInfo']['nameNl'],
place['details']['status'],
place['details']['addresses'][0]['streetFR'],
place['details']['addresses'][0]['streetNL'],
place['details']['addresses'][0]['number'],
place['details']['addresses'][0]['postCode'],
place['details']['addresses'][0]['city'],
'{0} {1} {2} {3}'.format(place['details']['addresses'][0]['streetFR']
, place['details']['addresses'][0]['number']
, place['details']['addresses'][0]['postCode']
, place['details']['addresses'][0]['city']),
place['details']['addresses'][0]['isUrbisAddress'],
coord_x,
coord_y,
place['details']['sector'],
place['details']['ownerType'],
place['details']['public'],
place['details']['isSchool'],
property_carparking_isAvailable,
property_carSpace,
property_carSpacePMR,
property_carSpaceVIP,
property_carSpaceBus,
property_hasConvivialityArea,
property_bikeparking_isAvailable,
property_bikeparking_totalSpaces,
property_bikeparking_isSecured,
property_bikeparking_isFullyCovered,
property_playground,
place['infrastructures'],
place['organisations']
])
# Convert to pandas dataframe
df_places = pd.DataFrame(places[1:], columns=places[0])
return df_places
def getSubsidies(end_point, headers, request_body):
"""
Parameters
----------
end_point : string
API URL endpoint
headers : dictionary
headers, connection details
request_body : dictionary
data to pass to the API request to filter the data
Returns
-------
events - Nested list
"""
url = end_point + '/api/Subsidy/GetSubsidies'
# Subsidy status dictionary
# status_dict = {'N':'N-code: Draft?', 'V':'Validated', 'E':'Exported', 'L':'Legacy', 'D':'Draft', 'R':'Refused', 'W':'Waiting for validation'}
# Launch API Call
response = requests.post(url, headers=headers, data=json.dumps(request_body))
# Format response into a list
subsidies_extended_list = response.json()['response']
subsidies = []
# append header names
subsidies.append(['id', 'name', 'subsidy organisation', 'more information', 'status', 'date', 'amount',
'modification date',
'operating subsidy', 'subsidy type', 'starting date', 'closing date',
'contact',
'organisationMainId',
'organisationSubsidyBpl',
'infrastructureId'
])
for i, subsidy in enumerate(subsidies_extended_list):
subsidies.append(
[subsidy['id'],
subsidy['type']['name'],
subsidy['subsidisingPartner']['name'], # subsidy organisation
subsidy['type']['informationPage'], # more information
subsidy['status'], # status_dict[subsidy['status']],
stringToDate(subsidy['creationDate']),
subsidy['amount'],
stringToDate(subsidy['modificationDate']), # modification date
subsidy['type']['operatingSubsidy'], # operating subsidy
subsidy['type']['typeOfSubsidy'], # subsidy type
stringToDate(subsidy['type']['startDate']), # starting date
stringToDate(subsidy['type']['endDate']), # closing date
subsidy['contact'],
subsidy['organisationMainId'],
subsidy['organisationSubsidyBpl'],
subsidy['infrastructureId']
])
# Convert to pandas dataframe
df_subsidies = pd.DataFrame(subsidies[1:], columns=subsidies[0])
return df_subsidies
def stringToDate(inputString):
"""
Converts string to date values and format date to dd/mm/yyyy format
Returns
-------
date : date
formatted date (dd-mm-yyyy).
"""
# Convert string to dates if not null
if inputString is None or inputString == '':
date = inputString
else:
try:
# Date without nanoseconds
date = datetime.strptime(inputString, '%Y-%m-%dT%H:%M:%S').date()
except:
# date with nanoseconds
date = datetime.strptime(inputString, '%Y-%m-%dT%H:%M:%S.%f').date()
return date
def stringToTime(inputString):
"""
Converts string to datetime values and format date to dd/mm/yyyy format
Returns
-------
time : datetime
formatted date (dd-mm-yyyy).
"""
# Convert string to times if not null
if inputString is None or inputString == '':
time = inputString
else:
try: