import shutil
import pyodide
WIDTH = shutil.get_terminal_size()
def get_proton():
# Set up the URL for the text file
url = "https://services.swpc.noaa.gov/text/ace-swepam.txt"
# Download the text file
response = pyodide.http.open_url(url)
data = response.read()
# Split the text file into lines
lines = data.split("\n")
# Extract the most recent solar wind data from the second-to-last line
last_line = lines[-2]
fields = last_line.split()
# Extract the solar wind speed, density, and temperature from the fields
s = float(fields[6])
density = float(fields[7])
speed = float(fields[8])
temperature = fields[9]
# Returning values
return s, speed, density, temperature
s, speed, density, temperature = get_proton()
wind_speed = str("The current solar wind speed is: " + str(speed) + " km/s")
wind_density = str("The current solar wind density is: " + str(density) + " protons/cc")
wind_temp = str("The current solar wind temperature is: " + str(temperature) + chr(176) + " K")
if s == 0 or s == 1:
print(wind_speed.center(270))
print(wind_density.center(270))
print(wind_temp.center(270))
else:
print("Current solar wind data is either corrupt, or unavailable, please try again in 1 minute".center(270))