skip to Main Content

I have backend code written in python where it returns a number, I want to show the number in different color for certain threshold.

For example if the number is 15 and above it should show in red color

Here is the code:

def zulu_extracts(weather_input,datis=None):
    
    # This could be work intensive. Make your own conversion if you can avoid using datetime
    raw_utc = Root_class().date_time(raw_utc='HM')[-4:]
    raw_utc_dt = datetime.strptime(raw_utc,"%H%M")
    
    if datis:
        zulu_item_re = re.findall('[0-9]{4}Z', weather_input)
    else:
        zulu_item_re = re.findall('[0-9]{4}Z', weather_input)
        
    if zulu_item_re:
        zulu_weather = zulu_item_re[0][:-1]
        zulu_weather_dt = datetime.strptime(zulu_weather,"%H%M")
        diff = raw_utc_dt - zulu_weather_dt
        diff = int(diff.seconds/60)
        return diff
    else:
        zulu_weather = 'N/A'
        return zulu_weather

The front end is based on html,css and JS

I already searched on google and tried chat GPT but nothing seems to work

2

Answers


  1. enter code here:
    from colorama import Fore
    numero = int(input("Tell me a numbern"))
    if numero < 50:
    print(Fore.RED + str(numero))
    else:
    print(Fore.BLUE + str(numero))
    
    Login or Signup to reply.
  2. If you need to generate HTML with zulu_extracts then change the lines

    diff = int(diff.seconds/60)
    return diff
    

    to

    diff = int(diff.seconds/60)
    if diff >= 15:
        return '<span style="color: red">{}</span>'.format(diff)
    return diff
    

    But it would be much better to do this kind of styling in the place where the rest of your HTML is generated.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search