0

The task I need to do is to write some python codes to make computer can execute another python code which is provided by my colleague at 8 am every day. (The codes he provide me could be used to automatically download something from the internet or processing some excel sheets)

Actually, I have already found a previous post in StackOverflow which could very match what I want: Python script to do something at the same time every day

However, I am a python beginner, so I don't know what is the "exact / practical" way to execute these codes. My questions could stupid but hope someone still can help me.

Let me describe my problems below...

Scenario Background:

Each day, My colleague will push ctrl+L to lock his computer (not log off or shut down) before leaving the office and the computer will go into sleep mode in the final. He will come to the office at around 9 am, but he hopes my python code can automatically execute some of his python codes at 8 am each day.

The final result should be like this:

  1. Automatically wake up the computer (I think this step can be done by windows setting, instead of using python. Would it be easier?)
  2. Even the computer is still locked, my python code should still automatically execute another python code at 8 am.

So my codes are as follow (Based on that previous post in StackOverflow):

from datetime import datetime
from threading import Timer

x=datetime.today()
y=x.replace(day=x.day+1, hour=8, minute=0, second=0)

delta_t=y-x
secs=delta_t.seconds+1

def daily_task():
    # Put my Colleague's codes here

t = Timer(secs, daily_task)

t.start()

My real question is:

  1. I write these codes in Spyder (This is the only environment I know how to use...) Should I just press F5 and execute all my codes and then it's done?

  2. Or should I run these codes on cmd or something like that?

  3. Will my codes still work after I close down my Spyder?

  4. If my code will still work after I close Spyder, then what is the exact way to stop my code?


Sorry, I know my question could be very stupid or even ask the wrong questions.

But I usually only use python to do some very simple data processing and analysis, and never use it to do such a practical thing. So I totally have no idea how to do it even though I have already googled it.

martineau
  • 119,623
  • 25
  • 170
  • 301
codingsnake99
  • 146
  • 1
  • 10
  • As much as I would like to help answer your question, I would first have to ask "But why?" – NotARobot Jan 16 '19 at 23:29
  • Why doesnt his or her code just run on the timer? Why is it time sensitive for that matter? – NotARobot Jan 16 '19 at 23:36
  • There's probably something fundamental to the process you've imagined that would not need this sort of "workflow". Perhaps simplify what changes every day into a set of parameters that need to be entered every night or morning. My spidey senses are telling me that the solution you have arrived at is more complex than it needs to be. – NotARobot Jan 16 '19 at 23:43
  • Hi BrokenRobot, The reason we need this code is: At 8 am, we are not yet in the office. But if the computer can start to run the code my colleague designed to deal with some data, it will be very helpful when we arrived at 9 am – codingsnake99 Jan 17 '19 at 08:20
  • You can design a script that can run indefinitely in the background and fire on a specific function every morning. You just provide it with a place to accept a different set of parameters every day. Also, your question should focus on one specific question with achievable answer per the Stack Overflow guidelines. You might need to review the question and break it up into pieces. – NotARobot Jan 17 '19 at 17:22

0 Answers0