@@ -11,7 +11,7 @@ class Location: # pylint: disable=too-many-instance-attributes
1111 """
1212
1313 def __init__ (
14- self , id , country , province , coordinates , last_updated , confirmed , deaths , recovered ,
14+ self , id , country , province , coordinates , last_updated , confirmed , deaths , recovered , timelines
1515 ): # pylint: disable=too-many-arguments
1616 # General info.
1717 self .id = id
@@ -26,6 +26,7 @@ def __init__(
2626 self .confirmed = confirmed
2727 self .deaths = deaths
2828 self .recovered = recovered
29+ self .timelines = timelines
2930
3031 @property
3132 def country_code (self ):
@@ -47,14 +48,14 @@ def country_population(self):
4748 """
4849 return country_population (self .country_code )
4950
50- def serialize (self ):
51+ def serialize (self , timelines = False ):
5152 """
5253 Serializes the location into a dict.
5354
5455 :returns: The serialized location.
5556 :rtype: dict
5657 """
57- return {
58+ serialized = {
5859 # General info.
5960 "id" : self .id ,
6061 "country" : self .country ,
@@ -72,43 +73,6 @@ def serialize(self):
7273 "recovered" : self .recovered ,
7374 },
7475 }
75-
76-
77- class TimelinedLocation (Location ):
78- """
79- A location with timelines.
80- """
81-
82- # pylint: disable=too-many-arguments
83- def __init__ (self , id , country , province , coordinates , last_updated , timelines ):
84- super ().__init__ (
85- # General info.
86- id ,
87- country ,
88- province ,
89- coordinates ,
90- last_updated ,
91- # Statistics (retrieve latest from timelines).
92- confirmed = timelines .get ("confirmed" ).latest or 0 ,
93- deaths = timelines .get ("deaths" ).latest or 0 ,
94- recovered = timelines .get ("recovered" ).latest or 0 ,
95- )
96-
97- # Set timelines.
98- self .timelines = timelines
99-
100- # pylint: disable=arguments-differ
101- def serialize (self , timelines = False ):
102- """
103- Serializes the location into a dict.
104-
105- :param timelines: Whether to include the timelines.
106- :returns: The serialized location.
107- :rtype: dict
108- """
109- serialized = super ().serialize ()
110-
111- # Whether to include the timelines or not.
11276 if timelines :
11377 serialized .update (
11478 {
@@ -119,6 +83,4 @@ def serialize(self, timelines=False):
11983 }
12084 }
12185 )
122-
123- # Return the serialized location.
12486 return serialized
0 commit comments