Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time event
#1
I looked everywhere and it look like Chinese for me..
I can't figure how to get a simple time event as following:
if time is between x and y
this happen ..

I can't figure how to get the value out of the time parameter to write my code..
Can anyone help me out with that ? Huh

I need a simple code who would make A=1 if the current time is between 0700 and 2100...
As simple as It sound I can't seem to figure it out.. Undecided
Reply
#2
Chinese looks fine if you know Chinese.
I have no idea what you are talking about as you haven't posted any code
Reply
#3
start by reading docs for
time module and on PyMOTW
datetime module and on PyMOTW

then post your code and asl specdific questions as advised by Larz
Reply
#4
I rode those multiple time.. here a short script to explain my issue:

import time
time.ctime()
time.strftime('%l:%M%p %Z on %b %d, %Y')

while time.strftime('%l')>7 and time.strftime('%l')<21:
#event happen here..
Reply
#5
import time
time.ctime()
time.strftime("%a, %d %b %Y %H:%M:%S")
 
h = int(time.strftime('%H'))
if h > 7 and h<21:
    print("f")
prints "f" if the time is between 0700 and 2100. Elsewise, instead of print("f"), you can make it A=1
Reply
#6
Awesome, il give a try. THANK !

Work great ! thank.
complete code if you need some light for your plant:

#A2.1
import RPi.GPIO as GPIO
import datetime
import time
time.ctime()
time.strftime("%a, %d %b %Y %H:%M:%S")

h = int(time.strftime('%H'))

light = 21

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

if h>=7 and h<21:
    GPIO.setup(light, GPIO.OUT)
    GPIO.output(light, GPIO.LOW)
    now = datetime.datetime.now()
    path = '/media/pi/34BF-2414/log.txt'
    log = open(path,'a')
    log.write(now.strftime('\n' + "%Y-%m-%d %H:%M"))
    log.write('  Main light ON')
    log.close()
else:
    
    GPIO.output(light, GPIO.HIGH)
    now = datetime.datetime.now()
    path = '/media/pi/34BF-2414/log.txt'
    log = open(path,'a')
    log.write(now.strftime('\n' + "%Y-%m-%d %H:%M"))
    log.write('  Main light OFF')
    log.close()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020