Make a function call itself after set amount of time
Bart Nessux
bart_nessux at hotmail.com
Tue Jan 13 09:43:23 EST 2004
Bart Nessux wrote:
> How do I make a function call itself every 24 hours. Also, is there a
> way to start the program automatically w/o depending on the OS functions
> like 'Task Scheduler' or 'Start Up Items'... this is on Windows 2k and
> xp. Below is an example of what I'm trying to do.
>
> TIA
>
> def ipconfig_email():
> from email.MIMEText import MIMEText
> import smtplib
> import time
> import os
>
> u = "user name" #Change This to user's name.
> f = "my-email-addy"
> t = "my-email-addy"
>
> fp0 = os.popen("ipconfig /all", "r")
> fp1 = os.popen("psinfo -d -s", "rb")
> msg = MIMEText(fp0.read() + fp1.read())
> fp0.close()
> fp1.close()
>
> msg["Subject"] = "%s's IPconfig Report" % u
> msg["From"] = f
> msg["To"] = t
>
> h = "my.smtp.server"
> s = smtplib.SMTP(h)
> s.sendmail(f, t, msg.as_string())
> s.quit()
> time.sleep(86400) #24 hour sleep
> HOW_DO_I_CALL_THE_FUNCTION_AGAIN?
>
> ipconfig_email()
>
I figured it out. I added this to the function definition:
ipconfig_email()
I feel like an ass, sorry to bother you guys!
More information about the Python-list
mailing list