Skip to content

Commit f96d926

Browse files
committed
add logger
1 parent 58a1478 commit f96d926

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/acquisition/rvdss/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@
115115

116116
UPDATE_DATES_FILE = "update_dates.txt"
117117
NOW = datetime.now()
118+
119+
LOGGER_FILENAME = "rvdss.log"

src/acquisition/rvdss/database.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
from delphi.utils.epidate import EpiDate
2828
import delphi.utils.epiweek as flu
2929
from delphi.utils.geo.locations import Locations
30+
from delphi_utils import get_structured_logger
31+
from delphi.epidata.acquisition.rvdss.constants import LOGGER_FILENAME
32+
3033

3134

3235
respiratory_detections_cols= (
@@ -139,12 +142,19 @@ def get_num_rows(cursor, table_name):
139142
pass
140143
return num
141144

142-
def update(data_dict):
145+
def update(data_dict,logger):
143146
# connect to the database
144147
u, p = secrets.db.epi
145148
cnx = mysql.connector.connect(user=u, password=p, database="epidata")
146149
cur = cnx.cursor()
147-
150+
151+
# add filename for logger and exceptions
152+
153+
logger = get_structured_logger(
154+
__name__,
155+
filename= LOGGER_FILENAME,
156+
log_exceptions=True,
157+
)
148158

149159
for tt in data_dict.keys():
150160
data = data_dict[tt]
@@ -153,18 +163,16 @@ def update(data_dict):
153163
table_name = expected_table_names[tt]
154164
cols = expected_columns[tt]
155165
place_holders= ', '.join(["?" for _ in cols])
156-
# field_names = ", ".join(
157-
# f"`{name}`" for name in cols)
166+
field_names = ", ".join(
167+
f"`{name}`" for name in cols)
158168

159-
# check rvdss for new and/or revised data
160-
# sql = f"""
161-
# INSERT INTO {table_name} ({field_names})
162-
# VALUES ({place_holders})
163-
# """
169+
field_values = ", ".join(
170+
f"%({name})s" for name in cols)
164171

172+
#check rvdss for new and/or revised data
165173
sql = f"""
166-
INSERT INTO {table_name}
167-
VALUES ({place_holders})
174+
INSERT INTO {table_name} ({field_names})
175+
VALUES ({field_values})
168176
"""
169177

170178
# keep track of how many rows were added
@@ -176,8 +184,7 @@ def update(data_dict):
176184

177185
# keep track of how many rows were added
178186
rows_after = get_num_rows(cur,table_name)
179-
print(f"Inserted {int(rows_after - rows_before)}/{int(total_rows)} row(s)")
180-
187+
logger.info(f"Inserted {int(rows_after - rows_before)}/{int(total_rows)} row(s) into table {table_name}")
181188

182189
# cleanup
183190
cur.close()

0 commit comments

Comments
 (0)