Skip to content

Commit

Permalink
Merge pull request #13 from SinnieOnFire/issue-11
Browse files Browse the repository at this point in the history
[11] Timestamp fix
  • Loading branch information
SinnieOnFire authored Jul 10, 2023
2 parents 517c737 + c6a40b9 commit f53a96c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cy_airquality_rpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Adafruit_CharLCD as LCD
from unidecode import unidecode
from datetime import datetime
import re

import logging
from logging.handlers import RotatingFileHandler
Expand Down Expand Up @@ -55,15 +56,26 @@
# Get the station city
station_name = h4_header.text.strip()

# Find all pollutant labels and values within the div
# Find all pollutant labels and values within the div along with last update time
pollutant_labels = div_element.find_all(class_="pollutant-label")
pollutant_values = div_element.find_all(class_="pollutant-value")

# Find the element containing the text starting with "Updated on: "
regex_pattern = re.compile(r"^Updated on: (\d{2}/\d{2}/\d{4} \d{2}:\d{2})")
element = soup.find(text=regex_pattern)

if element:
# Extract the time from the text
match = regex_pattern.match(element)
if match:
updated_time = match.group(1)


index = 0
while True:
# Refresh time
now = datetime.now()
current_time = now.strftime('%d.%m.%Y %H:%M:%S')
# now = datetime.now()
# current_time = now.strftime('%d.%m.%Y %H:%M:%S')

# Create a list of formatted pollutant lines
pollutant_lines = []
Expand All @@ -76,7 +88,7 @@
pollutant_lines.append(line)

# Add the timestamp
time_line = f"Last Updated:\n{current_time}"
time_line = f"Last Updated:\n{updated_time}"
pollutant_lines.insert(8, time_line)

# Get the current line to display
Expand Down

0 comments on commit f53a96c

Please sign in to comment.