fix lost name

This commit is contained in:
RaspbianProyect by HP3ICC 2023-05-31 14:46:19 +00:00
parent ffa7456dbe
commit 92f72de096
1 changed files with 16 additions and 6 deletions

View File

@ -64,7 +64,6 @@ login = f"user {callsign} pass {password} vers emq-TE1 Python APRS WX 1.4"
mlogin = f"{api_key}"
mid = f"{map_id}"
time.sleep(30)
while True:
try:
# Get weather data from OpenWeatherMap API
@ -72,26 +71,37 @@ while True:
response = requests.get(url)
data = response.json()
if "main" in data and "weather" in data and "wind" in data and "rain" in data:
if "main" in data and "weather" in data and "wind" in data:
name = data["name"]
temperature = int(data["main"]["temp"])
temperature = str(temperature).zfill(3)
presure = data["main"]["pressure"]
wind = int(data["wind"]["speed"])
wind = str(wind).zfill(3)
gust = int(data["wind"]["gust"])
gust = int(data["wind"].get("gust", 0))
gust = str(gust).zfill(3)
deg = int(data["wind"]["deg"])
deg = str(deg).zfill(3)
rain = int(data["rain"]["1h"])
rain = int(data.get("rain", {}).get("1h", 0))
rain = str(rain).zfill(3)
humidity = data["main"]["humidity"]
weather_description = data["weather"][0]["description"]
weather_data = f"{deg}/{wind}g{gust}{temperature}r{rain}p000h{humidity}b{presure}0"
clima = f" / Clima en {name}: " if name else " / Clima: "
weather_data = f"{deg}/{wind}g{gust}t{temperature}r{rain}p000h{humidity}b{presure}0"
else:
name = ""
temperature = "000"
presure = "0000"
wind = "000"
gust = "000"
deg = "000"
rain = "000"
humidity = "00"
weather_description = ""
clima = " / Clima: "
weather_data = "Weather data not available"
current_time_utc = datetime.utcnow().strftime("%d%H%M")
packet = f"{address}@{current_time_utc}z{latitude}{simbol_primary}{longitude}{simbol_secundary}{weather_data}{comment} / Clima en {name}: {weather_description}"
packet = f"{address}@{current_time_utc}z{latitude}{simbol_primary}{longitude}{simbol_secundary}{weather_data}{comment}{clima}{weather_description}"
packet2 = f"{address}>{text}"
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((serverHost, serverPort))