Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/weather #52

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
English everything
Elefantex committed Nov 24, 2024
commit 5b465e7c5d8c1d75aacb7e5fbe572c453d13f14c
20 changes: 10 additions & 10 deletions gui.py
Original file line number Diff line number Diff line change
@@ -754,15 +754,15 @@ def set_time(self):
def set_weather(self):
city, ok_pressed = QInputDialog.getText(self, "Set Weather", "Enter the city:")

if ok_pressed and city: # Verificar si se ingresó una ciudad
if ok_pressed and city: # Check if there is a city
def get_current_data(city):
url = f"https://api.weatherapi.com/v1/current.json?q={city}&key={api_key}"
response = requests.get(url)
data = response.json()
if response.status_code == 200:
return data
else:
raise ValueError("No se pudo obtener la información meteorológica.")
raise ValueError("It could not get the info")

def draw_digit(draw, x_offset, y_offset, digit):
pattern = digits[digit]
@@ -773,7 +773,7 @@ def draw_digit(draw, x_offset, y_offset, digit):

def draw_colored_pattern(draw, x_offset, y_offset, key):
if key not in patterns:
raise ValueError(f"El patrón '{key}' no está definido.")
raise ValueError(f"The pattern '{key}' is not defined.")
pattern = patterns[key]
for y, row in enumerate(pattern):
for x, pixel in enumerate(row):
@@ -799,7 +799,7 @@ def get_weather_category(condition_code,is_day):
"windy": [1114, 1117]
}
if is_day == 0:
# Si es de noche, cambiamos las categorías
# If it is night , we change the category
weather_switch["moon"] = weather_switch.pop("sun", [1000])
weather_switch["partly cloudy night"] = weather_switch.pop("partly cloudy", [1003])

@@ -810,7 +810,7 @@ def get_weather_category(condition_code,is_day):
return category
return "unknown"

# Obtener datos meteorológicos
# OGet weather data
data_api = get_current_data(city)

current_weather_code = data_api["current"]["condition"]["code"]
@@ -821,24 +821,24 @@ def get_weather_category(condition_code,is_day):

temperature_celsius = int(round(data_api["current"]["temp_c"]))

# Crear imagen de 16x16 píxeles
# Do pixel img
img = Image.new('RGB', (16, 16), color='black')
draw = ImageDraw.Draw(img)

# Extraer los dígitos de la hora
# Extract the celsius digits
first_digit = str(temperature_celsius).zfill(2)[0]
second_digit = str(temperature_celsius).zfill(2)[1]

# Dibujar los dígitos y el patrón meteorológico
# Draw temperature and weather
draw_digit(draw, 3, 8, first_digit)
draw_digit(draw, 9, 8, second_digit)
draw_colored_pattern(draw, 4, 0, weather_category)

# Guardar la imagen
# Save the img
file_path = "weather.png"
img.save(file_path)

# Ejecutar el comando con la imagen generada
# Run the command with the new img
self.run_command([
"--address", self.mac_address,
"--image", "true",
16 changes: 8 additions & 8 deletions utils/utils.py
Original file line number Diff line number Diff line change
@@ -100,15 +100,15 @@
]
}
colors = {
"b": "#000000", # Negro
"y1": "#e5ff00", # Amarillo claro
"y2": "#e6bd09", # Amarillo medio
"y3": "#e6a307", # Amarillo oscuro
"w": "#FFFFFF", # Blanco (nube)
"g": "#AAAAAA", # Gris claro (nube)
"b": "#000000", # Black
"y1": "#e5ff00", # Light yellow
"y2": "#e6bd09", # Medium yellow
"y3": "#e6a307", # Dark yellow
"w": "#FFFFFF", # White
"g": "#AAAAAA", # Dark gray
"gD":"#4f4f4f", # gray dark
"y": "#FFFF00", # Amarillo (trueno)
"c": "#00FFFF", # Azul claro (lluvia)
"y": "#FFFF00", # Yellow (thunder)
"c": "#00FFFF", # Light blue (rain)
"bl":"#0088ff", #blue

}