33import logging
44import os
55from datetime import datetime
6+ from pprint import pformat as pf
67
78from asyncache import cached
89from cachetools import TTLCache
1617from . import LocationService
1718
1819LOGGER = logging .getLogger ("services.location.jhu" )
19-
20+ PID = os . getpid ()
2021
2122class JhuLocationService (LocationService ):
2223 """
@@ -53,20 +54,21 @@ async def get_category(category):
5354 """
5455 # Adhere to category naming standard.
5556 category = category .lower ()
57+ data_id = f"jhu.{ category } "
5658
5759 # URL to request data from.
5860 url = BASE_URL + "time_series_covid19_%s_global.csv" % category
5961
6062 # Request the data
61- LOGGER .info (f"pid: { os . getpid () } : jhu Requesting data..." )
63+ LOGGER .info (f"{ data_id } Requesting data..." )
6264 async with httputils .CLIENT_SESSION .get (url ) as response :
6365 text = await response .text ()
6466
65- LOGGER .info ( "jhu Data received" )
67+ LOGGER .debug ( f" { data_id } Data received" )
6668
6769 # Parse the CSV.
6870 data = list (csv .DictReader (text .splitlines ()))
69- LOGGER .info ( "jhu CSV parsed" )
71+ LOGGER .debug ( f" { data_id } CSV parsed" )
7072
7173 # The normalized locations.
7274 locations = []
@@ -99,18 +101,20 @@ async def get_category(category):
99101 "latest" : int (latest or 0 ),
100102 }
101103 )
102- LOGGER .info ( "jhu Data normalized" )
104+ LOGGER .debug ( f" { data_id } Data normalized" )
103105
104106 # Latest total.
105107 latest = sum (map (lambda location : location ["latest" ], locations ))
106108
107109 # Return the final data.
108- return {
110+ results = {
109111 "locations" : locations ,
110112 "latest" : latest ,
111113 "last_updated" : datetime .utcnow ().isoformat () + "Z" ,
112114 "source" : "https://github.com/ExpDev07/coronavirus-tracker-api" ,
113115 }
116+ LOGGER .info (f"{ data_id } results:\n { pf (results , depth = 1 )} " )
117+ return results
114118
115119
116120@cached (cache = TTLCache (maxsize = 1024 , ttl = 3600 ))
@@ -121,6 +125,8 @@ async def get_locations():
121125 :returns: The locations.
122126 :rtype: List[Location]
123127 """
128+ data_id = "jhu.locations"
129+ LOGGER .info (f"pid:{ PID } : { data_id } Requesting data..." )
124130 # Get all of the data categories locations.
125131 confirmed = await get_category ("confirmed" )
126132 deaths = await get_category ("deaths" )
@@ -174,6 +180,7 @@ async def get_locations():
174180 },
175181 )
176182 )
183+ LOGGER .info (f"{ data_id } Data normalized" )
177184
178185 # Finally, return the locations.
179186 return locations
0 commit comments