Skip to content

Commit c05c78b

Browse files
committed
fixes for lighthouse script
1 parent edd3dba commit c05c78b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

scripts/script_lighthouse.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ def execute_query_and_insert_result(start_date, end_date):
8585
))) AS lighthouse
8686
FROM
8787
`httparchive.core_web_vitals.technologies`
88-
WHERE
88+
8989
"""
9090

9191
# Construct the WHERE clause based on the provided parameters
9292
if start_date and end_date:
93-
query += f" date >= '{start_date}' AND date <= '{end_date}'"
93+
query += f"WHERE date >= '{start_date}' AND date <= '{end_date}'"
9494

9595
query += " GROUP BY date, app, rank, geo"
9696

@@ -101,10 +101,8 @@ def execute_query_and_insert_result(start_date, end_date):
101101
collection_ref = firestore_client.collection('lighthouse')
102102

103103
idx = 0
104-
104+
batch = firestore_client.batch()
105105
print("Data insert process started.")
106-
107-
batch = collection_ref.batch()
108106
for row in results:
109107
# Convert date
110108
#
@@ -113,14 +111,14 @@ def execute_query_and_insert_result(start_date, end_date):
113111
item = convert_decimal_to_float(item)
114112

115113
record_ref = collection_ref.document(uuid.uuid4().hex)
116-
batch.set(record_ref, row)
114+
batch.set(record_ref, item)
117115
idx += 1
118116

119117
# Commit the batch at every 500th record.
120118
if idx == 499:
121119
batch.commit()
122120
# Start a new batch for the next iteration.
123-
batch = collection_ref.batch()
121+
batch = firestore_client.batch()
124122
idx = 0
125123

126124
batch.commit()

0 commit comments

Comments
 (0)