-1

I have a CSV file in which all time mentioned, and I want to run my python code file every day on time which is given in CSV file. enter image description here

I saw some code on the Schedule library, but I don't understand how should I write that code. as well as, I have to write schedule code in that same file that I want to run, or should I create new file and write schedule code there and give that file link that I want to run?

and my file name is - send_mesaage.ipynb

  • What platform are you using? This seems like a use case for a cron job or a Windows scheduled task. – Axe319 Jan 04 '22 at 14:57
  • @Axe319 my machine is Windows, but I don't want to use Windows task scheduler, I want to run my code every that time which I have given in excel sheet. – Krishna Gupta Jan 04 '22 at 14:59
  • As far as I understand you want to sleep until the next time in your CSV. This could be done by looping through your the timestamps. And then maybe utilizing one of the solutions found in SO question [In Python, how can I put a thread to sleep until a specific time?](https://stackoverflow.com/questions/2031111/in-python-how-can-i-put-a-thread-to-sleep-until-a-specific-time) – Asger Weirsøe Jan 04 '22 at 15:05

1 Answers1

0

From geeksforgeeks i found this:

import sched
import time

# instance is created
scheduler = sched.scheduler(time.time,
                            time.sleep)

# function to print time
# and name of the event
def print_event(name):
    print('EVENT:', time.time(), name)

# printing starting time
print ('START:', time.time())

# first event with delay of
# 1 second
e1 = scheduler.enter(1, 1,
                    print_event, ('1 st', ))

# second event with delay of
# 2 seconds
e1 = scheduler.enter(2, 1,
                    print_event, (' 2nd', ))

# executing the events
scheduler.run()

How this works: Its simple,
event_schedule.enter(Sleep_Time, Priority, Function_to_run)
and event_schedule.run() starts the event_schedule.enter() do you have

redystum
  • 334
  • 2
  • 8