'Put to programs together

I'm trying to unify this two codes, I just do not know how to do it or even if is possible, maybe the answer is something fast, but I'm learning in the process, help please, I've been fighting with this too many days.

This one turn on and off the lamp when an exact time comes "06:00" <= time <= "18:00"

import RPi.GPIO as GPIO
import datetime
import time
from multiprocessing import Process

#turn off warning
GPIO.setwarnings(False)
#set location mode
GPIO.setmode(GPIO.BCM)
#Light output
GPIO.setup(5, GPIO.OUT)
GPIO.output(5, False)


try:
    while True:
    
        time = datetime.datetime.now().strftime('%H:%M')
        if "06:00" <= time <= 18:00":
            GPIO.output(5, 0)
        else:   
            GPIO.output(5, 1)
            
finally:
    GPIO.cleanup()

both programs work fine, but I need to put them together.

This one, turn on and off a lamp when you click on e button, so 1 click turn on the lights, another click and the lamp turn off, click again and lamp turn on, and continues as I click the button.

import time
import RPi.GPIO as GPIO

def lrelay():
    
    GPIO.setmode(GPIO.BCM)

    GPIO.setwarnings(False)
    GPIO.setup(27, GPIO.IN)
    GPIO.setup(5, GPIO.OUT)
    GPIO.output(5, True)
    
    BS1=False
    
    try:
        def switch(ev=None):
            global BS1
            BS1 = not BS1
            
            if BS1 == True:
                GPIO.output(5, GPIO.HIGH)
            else:
                GPIO.output(5, GPIO.LOW)
        def button():
            GPIO.add_event_detect(27, GPIO.FALLING, callback = switch, bouncetime=300)
            
        def wait():
            while True:
                time.sleep(1)
        
        button()
        wait()

    finally:
        GPIO.cleanup()

Maybe is something super easy, but I never study python, so I'm just discovering things.

The last post was terrible wrong, sorry.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source