1
1
class Response :
2
2
def __init__ (self , obj ):
3
3
self .smarty_key = obj .get ('smarty_key' , None )
4
- self .data_set_name = obj .get ('data_set_name' , None )
5
- self .data_subset_name = obj .get ('data_subset_name' , None )
6
- self .attributes = get_attributes (self .data_set_name , self .data_subset_name , obj .get ('attributes' , None ))
4
+ data_set_name = None
5
+ data_subset_name = None
6
+ if 'data_set_name' in obj :
7
+ self .data_set_name = obj .get ('data_set_name' )
8
+ data_set_name = obj .get ('data_set_name' )
9
+ elif 'secondaries' in obj :
10
+ data_set_name = 'secondary'
11
+
12
+ if 'data_subset_name' in obj :
13
+ self .data_subset_name = obj .get ('data_subset_name' , None )
14
+ data_subset_name = obj .get ('data_subset_name' , None )
15
+ elif 'count' in obj :
16
+ data_set_name = 'secondary'
17
+ data_subset_name = 'count'
18
+
19
+ if data_set_name == 'secondary' :
20
+ if data_subset_name == 'count' :
21
+ self .count = obj .get ('count' , None )
22
+ else :
23
+ self .root_address = get_secondary_root_address (obj .get ('root_address' , None ))
24
+ if 'aliases' in obj :
25
+ self .aliases = get_secondary_aliases (obj .get ('aliases' , None ))
26
+ self .secondaries = get_secondary_secondaries (obj .get ('secondaries' , None ))
27
+ else :
28
+ self .attributes = get_attributes (data_set_name , data_subset_name , obj .get ('attributes' , None ))
7
29
8
30
def __str__ (self ):
9
31
lines = [self .__class__ .__name__ + ':' ]
10
32
for key , val in vars (self ).items ():
11
- lines += '{}: {}' . format (key , val ). split ( ' \n ' )
33
+ lines += get_lines (key , val )
12
34
return '\n ' .join (lines )
13
35
14
36
def __eq__ (self , __value : object ) -> bool :
15
37
return isinstance (__value , type (self )) and __value .smarty_key == self .smarty_key
16
38
39
+ def get_lines (key , val ):
40
+ lines = ['' ]
41
+ if type (val ) is list :
42
+ if len (val ) > 1 :
43
+ for item in val :
44
+ if val .index (item ) == 0 :
45
+ lines += ['secondaries:' ]
46
+ lines += get_lines (val .index (item ), val [val .index (item )])
47
+ return lines
48
+ else :
49
+ return get_lines (key , val [0 ])
50
+ else :
51
+ if type (key ) == int :
52
+ return ' {}: {}' .format (key , val ).split ('\n ' )
53
+ return '{}: {}' .format (key , val ).split ('\n ' )
17
54
18
55
def get_attributes (dataset , data_subset , attribute_obj ):
19
56
if dataset == "property" :
@@ -24,7 +61,6 @@ def get_attributes(dataset, data_subset, attribute_obj):
24
61
if dataset == "geo-reference" :
25
62
return GeoReferenceOutputCategories (attribute_obj )
26
63
27
-
28
64
class PrincipalAttributes :
29
65
def __init__ (self , obj ):
30
66
self .first_floor_sqft = obj .get ('1st_floor_sqft' , None )
@@ -575,7 +611,7 @@ def __str__(self):
575
611
576
612
class GeoReferenceOutputCategories :
577
613
def __init__ (self , obj ):
578
-
614
+
579
615
self .census_block = get_geo_reference_census_block (obj .get ('census_block' , None ))
580
616
self .census_county_division = get_geo_reference_census_county_division (obj .get ('census_county_division' , None ))
581
617
self .census_tract = get_geo_reference_census_tract (obj .get ('census_tract' , None ))
@@ -669,4 +705,112 @@ def get_geo_reference_place(geo_reference_place_obj):
669
705
return None
670
706
output = []
671
707
output .append (GeoReferencePlace (geo_reference_place_obj ))
672
- return output
708
+ return output
709
+
710
+ class SecondaryRootAddress :
711
+ def __init__ (self , obj ):
712
+ self .secondary_count = obj .get ('secondary_count' , None )
713
+ self .smarty_key = obj .get ('smarty_key' , None )
714
+ self .primary_number = obj .get ('primary_number' , None )
715
+ self .street_predirection = obj .get ('street_predirection' , None )
716
+ self .street_name = obj .get ('street_name' , None )
717
+ self .street_suffix = obj .get ('street_suffix' , None )
718
+ self .street_postdirection = obj .get ('street_postdirection' , None )
719
+ self .city_name = obj .get ('city_name' , None )
720
+ self .state_abbreviation = obj .get ('state_abbreviation' , None )
721
+ self .zipcode = obj .get ('zipcode' , None )
722
+ self .plus4_code = obj .get ('plus4_code' , None )
723
+
724
+ def __str__ (self ):
725
+ lines = ['' ]
726
+ for key , val in vars (self ).items ():
727
+ if type (val ) is list :
728
+ lines .append (key + ': ' )
729
+ for item in val :
730
+ for subkey , subval in vars (item ).items ():
731
+ lines += ' {}: {}' .format (subkey , subval ).split ('\n ' )
732
+ else :
733
+ lines .append (key + ': ' + str (val ))
734
+ return '\n ' .join (lines )
735
+
736
+ def get_secondary_root_address (secondary_root_address_obj ):
737
+ if secondary_root_address_obj is None :
738
+ return None
739
+ output = []
740
+ output .append (SecondaryRootAddress (secondary_root_address_obj ))
741
+
742
+ return output
743
+
744
+ class SecondaryAliases :
745
+ def __init__ (self , obj ):
746
+ self .smarty_key = obj .get ('smarty_key' , None )
747
+ self .primary_number = obj .get ('primary_number' , None )
748
+ self .street_predirection = obj .get ('street_predirection' , None )
749
+ self .street_name = obj .get ('street_name' , None )
750
+ self .street_suffix = obj .get ('street_suffix' , None )
751
+ self .street_postdirection = obj .get ('street_postdirection' , None )
752
+ self .city_name = obj .get ('city_name' , None )
753
+ self .state_abbreviation = obj .get ('state_abbreviation' , None )
754
+ self .zipcode = obj .get ('zipcode' , None )
755
+ self .plus4_code = obj .get ('plus4_code' , None )
756
+
757
+ def __str__ (self ):
758
+ lines = ['' ]
759
+ for key , val in vars (self ).items ():
760
+ if type (val ) is list :
761
+ lines .append (key + ': ' )
762
+ for item in val :
763
+ for subkey , subval in vars (item ).items ():
764
+ lines += ' {}: {}' .format (subkey , subval ).split ('\n ' )
765
+ else :
766
+ lines .append (key + ': ' + str (val ))
767
+ return '\n ' .join (lines )
768
+
769
+ def get_secondary_aliases (secondary_aliases_obj ):
770
+ if secondary_aliases_obj is None :
771
+ return None
772
+ output = []
773
+ output_list = []
774
+ for item in secondary_aliases_obj :
775
+ output .append (SecondaryAliases (item ))
776
+ output_list .append (output )
777
+ output = []
778
+ return output_list
779
+
780
+ class SecondarySecondaries :
781
+ def __init__ (self , obj ):
782
+ self .smarty_key = obj .get ('smarty_key' , None )
783
+ self .secondary_designator = obj .get ('secondary_designator' , None )
784
+ self .secondary_number = obj .get ('secondary_number' , None )
785
+ self .plus4_code = obj .get ('plus4_code' , None )
786
+
787
+ def __str__ (self ):
788
+ lines = ['' ]
789
+ for key , val in vars (self ).items ():
790
+ if type (val ) is list :
791
+ lines .append (key + ': ' )
792
+ for item in val :
793
+ for subkey , subval in vars (item ).items ():
794
+ lines += ' {}: {}' .format (subkey , subval ).split ('\n ' )
795
+ else :
796
+ lines .append (key + ': ' + str (val ))
797
+ return '\n ' .join (lines )
798
+
799
+ def get_secondary_secondaries (secondary_secondaries_obj ):
800
+ if secondary_secondaries_obj is None :
801
+ return None
802
+ output = []
803
+ output_list = []
804
+ for item in secondary_secondaries_obj :
805
+ output .append (SecondarySecondaries (item ))
806
+ output_list .append (output )
807
+ output = []
808
+ return output_list
809
+
810
+ class SecondaryCountAttributes :
811
+ def __init__ (self , obj ):
812
+ self .smarty_key = obj .get ('smarty_key' , None )
813
+ self .count = obj .get ('count' , None )
814
+
815
+ def __str__ (self ):
816
+ return self .__dict__ .__str__ ()
0 commit comments