""" If you need to do something irregularly, randomly during the weekday, you
often forget. This script gives you mail, sms or popup window indefinitely in
random interval to remind you of doing it. It runs forever. If you want to
send emails, uncomment the row sendMail() and fill variable me, to, smtp,
name, login in function sendMail(). """
# -*- coding: utf-8 -*-
import time, random, sys, os, smtplib
if sys.version < '3':
from Tkinter import *
else:
from tkinter import *
# ----------------- variables ----------------------------------
mytimefrom=6 # from 6 pm
mytimeto=22 # to 22 am
mydelayfrom=1*3600 # random delay in secs from
mydelayto=5*3600 # random delay in secs to
randommsgnext="randommsgnext.txt" # place to save time of next message
# ----------------- defs ----------------------------------
def showMessage():
# show reminder message window
root=Tk()
x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
root.geometry("+%d+%d" % (x, y))
root.protocol('WM_TAKE_FOCUS', root.update )
root.wait_visibility(root)
root.attributes('-topmost',1)
label=Label(root, text="Do what you should do.").pack({"side": "left"})
button=Button(text="OK", width="10", command=lambda:root.destroy()).pack()
root.mainloop()
def sendMail():
# sends mail
s = smtplib.SMTP(smtp)
s.login(name, password)
subject="Reminder"
fromaddr=fromadr
toaddrs= [toadr]
text= "Do what you should do.\n%s" % time.ctime()
msg = ("Subject: %s\nFrom: %s\nTo: %s\n\n%s" % (subject, fromaddr, ", ".join(toaddrs), text))
s.sendmail(fromaddr, toaddrs, msg)
s.quit()
def sendSMS():
# sends sms
message={'user': user, 'password': password, 'sender': fromnumber, 'recipient': tonumber, 'message': "goodbye"}
if sys.version < '3':
import urllib
params = urllib.urlencode(message)
f=urllib.urlopen(http, params)
else:
import urllib.parse
import urllib.request
params = urllib.parse.urlencode(message)
f = urllib.request.urlopen(http % params)
def checktime(nowtime):
# do not remind at night
if nowtime.tm_hour<=mytimefrom and nowtime.tm_hour>=mytimeto:
return False
return True
def timenextwritef():
# save next time in file
f=open(randommsgnext,"a")
timenext=time.mktime (nowtime)+delaysec
f.write(time.ctime(timenext)+"\n")
f.close()
os.utime(randommsgnext, None)
# ----------------- main app ----------------------------------
nowtime=time.localtime()
os.chdir(os.path.dirname(sys.argv[0])) # to have "randommsgnext" in the same dir
while True:
delaysec=random.randint(mydelayfrom,mydelayto)
timenextwritef()
time.sleep(delaysec)
nowtime=time.localtime()
if checktime(nowtime):
# sendSMS()
# sendMail() # uncomment if you want sending mails
showMessage()
Diff to Previous Revision
--- revision 1 2013-07-10 11:35:10
+++ revision 2 2013-07-11 12:15:55
@@ -1,9 +1,11 @@
-"""If you need to do something irregularly, randomly during the weekday, you often forget. This script send you email and open a windows randomly in random interval to remind you of doing it. It runs forever.
+""" If you need to do something irregularly, randomly during the weekday, you
+often forget. This script gives you mail, sms or popup window indefinitely in
+random interval to remind you of doing it. It runs forever. If you want to
+send emails, uncomment the row sendMail() and fill variable me, to, smtp,
+name, login in function sendMail(). """
-If you want to send email, uncomment the row sendMessage() and fill variable me, to, smtp, name, login in sendMessage() def.
-"""
# -*- coding: utf-8 -*-
-import time, random, sys, os
+import time, random, sys, os, smtplib
if sys.version < '3':
from Tkinter import *
@@ -15,12 +17,12 @@
mytimeto=22 # to 22 am
mydelayfrom=1*3600 # random delay in secs from
mydelayto=5*3600 # random delay in secs to
-randommailnext="randommailnext.txt" # place to save time of next message
+randommsgnext="randommsgnext.txt" # place to save time of next message
# ----------------- defs ----------------------------------
def showMessage():
- # show reminder message
+ # show reminder message window
root=Tk()
x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
@@ -32,21 +34,32 @@
button=Button(text="OK", width="10", command=lambda:root.destroy()).pack()
root.mainloop()
-def sendMessage():
- # If you want to send email, uncomment the row sendMessage() and fill variable me, to, smtp, name, login in sendMessage() def.
- import smtplib, time
+def sendMail():
+ # sends mail
s = smtplib.SMTP(smtp)
s.login(name, password)
subject="Reminder"
- fromaddr=me
- toaddrs=[to]
- msg = ("Subject: %s\r\nFrom: %s\r\nTo: %s\r\n\r\n"
- % (subject, fromaddr, ", ".join(toaddrs)))
+ fromaddr=fromadr
+ toaddrs= [toadr]
text= "Do what you should do.\n%s" % time.ctime()
- msg = msg + text
+ msg = ("Subject: %s\nFrom: %s\nTo: %s\n\n%s" % (subject, fromaddr, ", ".join(toaddrs), text))
+
s.sendmail(fromaddr, toaddrs, msg)
s.quit()
+
+def sendSMS():
+ # sends sms
+ message={'user': user, 'password': password, 'sender': fromnumber, 'recipient': tonumber, 'message': "goodbye"}
+ if sys.version < '3':
+ import urllib
+ params = urllib.urlencode(message)
+ f=urllib.urlopen(http, params)
+ else:
+ import urllib.parse
+ import urllib.request
+ params = urllib.parse.urlencode(message)
+ f = urllib.request.urlopen(http % params)
def checktime(nowtime):
# do not remind at night
@@ -56,16 +69,16 @@
def timenextwritef():
# save next time in file
- f=open(randommailnext,"a")
+ f=open(randommsgnext,"a")
timenext=time.mktime (nowtime)+delaysec
f.write(time.ctime(timenext)+"\n")
f.close()
- os.utime(randommailnext, None)
+ os.utime(randommsgnext, None)
# ----------------- main app ----------------------------------
nowtime=time.localtime()
-os.chdir(os.path.dirname(sys.argv[0])) # to have "randommailnext" in the same dir
+os.chdir(os.path.dirname(sys.argv[0])) # to have "randommsgnext" in the same dir
while True:
delaysec=random.randint(mydelayfrom,mydelayto)
@@ -73,5 +86,6 @@
time.sleep(delaysec)
nowtime=time.localtime()
if checktime(nowtime):
-# sendMessage() # uncomment if you want sending mails
+# sendSMS()
+# sendMail() # uncomment if you want sending mails
showMessage()