Skip to content

Commit e7bc03f

Browse files
remove prints and add logging printout
1 parent 7106cbb commit e7bc03f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

main.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import requests
3-
import json
43
import polars as pl
54
from datetime import datetime
65
import logging
@@ -12,16 +11,19 @@
1211
from utils.os_functions import ensure_data_dir
1312
from utils.paths import LOG_DIR, DATA_DIR
1413

15-
# Create a log filename with the current date (YYYY-MM-DD)
14+
# Create a log file with the current date (YYYY-MM-DD)
1615
log_filename = os.path.join(LOG_DIR,
1716
f"{datetime.now().strftime('%Y-%m-%d')}.log")
1817

1918
logging.basicConfig(
20-
filename=log_filename,
2119
level=logging.INFO,
2220
format=
23-
"%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d - %(funcName)s - %(message)s"
24-
)
21+
"%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d - %(funcName)s - %(message)s",
22+
handlers=[
23+
logging.FileHandler(log_filename),
24+
logging.StreamHandler(
25+
) # This allows logs to be printed to the console as well
26+
])
2527

2628
logging.info("=========================================")
2729
logging.info("Starting data download from ThingsBoard")
@@ -44,8 +46,7 @@
4446
startTS, endTS = download_interval(jwt_token, device_name,
4547
device_id, session)
4648

47-
logging.info(f"Downloading data for device: {device_name}")
48-
print(
49+
logging.info(
4950
f"Downloading data for device: {device_name} with starting timestamp: {datetime.fromtimestamp(startTS / 1000)}"
5051
)
5152

@@ -80,7 +81,11 @@
8081
current_timestamp = df_key.select(
8182
pl.col("ts").max()).to_series()[0] + 1
8283

83-
print(f"Starting pivot for device: {device_name}")
84+
logging.info(f"Starting pivot for device: {device_name}")
85+
86+
if len(df_chunk) == 0:
87+
logging.info(f"No data downloaded for device: {device_name}")
88+
continue
8489

8590
df_long = pl.concat(df_chunk)
8691

@@ -90,7 +95,7 @@
9095
.pivot(index="ts", on="key", values="value") \
9196
.with_columns(pl.from_epoch("ts", time_unit="ms").alias("datetime"))
9297

93-
print(f"Finished pivot for device: {device_name}")
98+
logging.info(f"Finished pivot for device: {device_name}")
9499

95100
# Save the data to a local Parquet file split by year
96101
for year in df_wide["datetime"].dt.year().unique().to_list():

0 commit comments

Comments
 (0)