From 436d42a72f2fd82b687dc6bcf7aaabf956fc8cbe Mon Sep 17 00:00:00 2001 From: David Bures <12524436+PiDiBi@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:00:04 -0700 Subject: [PATCH] performance - not splitting again and again with new line --- locationdata.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/locationdata.py b/locationdata.py index cfba686..38d64cb 100644 --- a/locationdata.py +++ b/locationdata.py @@ -99,12 +99,14 @@ def get_weather(lat=0, lon=0, unit=0): rows = table.find_all('div', class_="row") # extract data from rows - for row in rows: + for index, row in enumerate(rows): # shrink the text line = replace_weather(row.text) # only grab a few days of weather - if len(weather.split("\n")) < DAYS_OF_WEATHER: - weather += line + "\n" + print(f"weather: {index}") + weather += line + "\n" + if index >= DAYS_OF_WEATHER-1: + break # trim off last newline weather = weather[:-1]