@@ -38,28 +38,41 @@ def get_locations():
3838 locations = []
3939
4040 for i , item in enumerate (data ):
41+ # General info.
4142 state = item ['State Name' ]
4243 county = item ['County Name' ]
44+
45+ # Ensure country is specified.
4346 if county == "Unassigned" or county == "Unknown" :
4447 continue
4548
46- confirmed = int (item ['Confirmed' ] or 0 )
47- death = int (item ['Death' ] or 0 )
48- coordinates = Coordinates (float (item ['Latitude' ]), float (item ['Longitude' ]))
49+ # Coordinates.
50+ coordinates = Coordinates (
51+ item ['Latitude' ],
52+ item ['Longitude' ]
53+ )
54+
55+ # Date string without "EDT" at end.
56+ last_update = ' ' .join (item ['Last Update' ].split (' ' )[0 :2 ])
4957
50- # Parse time to ISO format
51- last_update = item ['Last Update' ]
52- date = last_update .split ("-" )
53- year = int (date [0 ])
54- month = int (date [1 ])
55- date = date [2 ].split (" " )
56- day = int (date [0 ])
57- time = date [1 ].split (":" )
58- hour = int (time [0 ])
59- minute = int (time [1 ])
60- d = datetime (year = year , month = month , day = day , hour = hour , minute = minute )
61- last_update = d .isoformat () + 'Z'
58+ # Append to locations.
59+ locations .append (CSBSLocation (
60+ # General info.
61+ i , state , county ,
62+
63+ # Coordinates.
64+ Coordinates (
65+ item ['Latitude' ],
66+ item ['Longitude' ]
67+ ),
6268
63- locations .append (CSBSLocation (i , state , county , coordinates , last_update , confirmed , death ))
69+ # Last update (parse as ISO).
70+ datetime .strptime (last_update , '%Y/%m/%d %H:%M' ).isoformat () + 'Z' ,
71+
72+ # Statistics.
73+ int (item ['Confirmed' ] or 0 ),
74+ int (item ['Death' ] or 0 )
75+ ))
6476
77+ # Return the locations.
6578 return locations
0 commit comments