Code: Select all
diary_root = "C:"
code_page = eg.systemEncoding
from datetime import date as date, datetime as dt
from os.path import isfile
import codecs
import re
WEEK = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
YEAR = (
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
)
ptrn = '((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\\s?(?:am|pm))?)'
rg = re.compile(ptrn,re.IGNORECASE|re.DOTALL)
am = {'12':'00','01':'01','02':'02','03':'03','04':'04','05':'05','06':'06',
'07':'07','08':'08','09':'09','10':'10','11':'11'}
pm = {'12':'12','01':'13','02':'14','03':'15','04':'16','05':'17','06':'18',
'07':'19','08':'20','09':'21','10':'22','11':'23'}
def test(txt):
m = rg.search(txt)
if m:
time1 = m.group(1)
else:
return (True, "No timestamp found !")
t_lower = time1.strip().lower()
a = time1.split(':')
res = ""
hr = a[0].zfill(2)
if t_lower.endswith("am"):
if hr in am:
res = am[hr] + ":" + a[1][:2]
else:
return (True, time1 + " (wrong format)") # When an error occurs, it is preferable to return True
elif t_lower.endswith("pm"):
if hr in pm:
res = pm[hr] + ":" + a[1][:2]
else:
return (True, time1 + " (wrong format)") # When an error occurs, it is preferable to return True
if res == "":
#res = time1
return (True, time1 + " (wrong format)") # When an error occurs, it is preferable to return True
if len(a) == 3:
res += ":" + a[2][:2]
else:
res += ":00"
now = dt.now()
ts = dt.now()
slots = res.split(":")
ts = ts.replace(hour = int(slots[0]),minute = int(slots[1]),second = int(slots[2]))
return (now < ts, ts)
today = date.today()
iso = today.isocalendar()
month = 12 if today.year > iso[0] else today.month
today_file = r"%s\%i Diary\%s\Week %i\%s.txt" % (diary_root, iso[0], YEAR[month-1], iso[1], WEEK[iso[2]-1])
if not isfile(today_file):
eg.PrintError('File "%s" not found !' % today_file)
eg.Exit()
eg.PrintNotice("File valid for today: " + today_file)
input = codecs.open(today_file, 'r', code_page, 'ignore')
data = input.readlines()
input.close()
speakData = ""
for line in data:
flag, ts = test(line)
if flag:
print "Upcoming event: ",str(ts)
speakData += line
else:
print "Missed event: ",str(ts)
if speakData:
eg.TriggerEvent("Speak", prefix = "Diary", payload = speakData)
I did, but I'm not too excited about.
For me, such a calendar is rather confusing.
Take for example the day January 1, 2017.
It is Sunday and according to ISO calendars belong to the 52nd week of 2016.
It follows that the plan for this Sunday has to be written to the file "
C:\2016 Diary\December\Week 52\Sunday.txt" !!!
It can not be the file "
C:\2017 Diary\December\Week 52\Sunday.txt" because it is Sunday 31 December 2017.
If I wanted to use this "talking diary," I would definitely stay with the status quo, where weeks are numbered separately each month (for example, in January 2016, there are weeks 1-5). For me it would be much clearer.
But I'm certainly not going to use (one of the reasons is that the Czech Windows can speak English only).
allalone747 wrote:... did your last script include a repeat function or ,will a scheduler function needed ...
No, repeater feature is not built.
You must run the script (for example using Schedulghost) whenever you need it.
The function is exactly as I described it on Monday, 11th of January.
This happens every time you run the script.
Pako