Dates

model.DateTime
Returns:

The current day and time

Return type:

datetime (readonly)

model.DayOfWeek
Returns:

the day of the week represented by a number (0-6) 0=Sunday

Return type:

int (readonly)

model.ScheduledTime
Returns:

The 15 minute time frame for the TaskScheduler

Return type:

str (readonly)

This value is populated by the BatchProcess Service running on TouchPoint servers. It is not available at this time for non-TouchPoint clients.

The format is “HHmm” e.g. “0930” for 9:30 AM or “1615” for 4:15 PM

Example:

if model.DayOfWeek == 2 and model.ScheduledTime == '1800':
    model.CallScript("EmailAttendanceReports")

if model.DayOfWeek == 4 and model.ScheduledTime == '0930':
    model.CallScript("EmailReminders")

This could would be located in a Python Script called ScheduledTasks. There would two additional scripts called EmailReminders and EmailAttendanceReports that would run on Thursday morning and Tuesday evening respectively.

model.DateAddDays(date, days)
Returns:

The new date.

Return type:

datetime

Parameters:
  • date (datetime) – The existing date

  • days (int) – The number of days after or before (negative) the existing date.

This function takes the existing date (dt) and adds the number of days and returns the resulting date.

model.DateDiffDays(date1, date2)
Returns:

The number of days between the two dates

Return type:

int

Parameters:
  • date1 (datetime) – The beginning date

  • date2 (datetime) – The ending date

The number of days between the two dates is returned. If the second date is less than the first date, the return value will be negative.

model.DateAddHours(date, hours)
Returns:

The new date.

Return type:

datetime

Parameters:
  • date (datetime) – The existing date and time.

  • hours (int) – The number of hours after or before (negative) the existing date/time.

This function takes the existing date/time (dt) and adds the number of hours and returns the result.

model.MostRecentAttendedSunday(progid)
Returns:

The date on which the most recent attendance occurred for the specified program.

Return type:

date

Parameters:

progid (int) – The id of the Program containing the orgs/meetings on which there is attendance.

model.ParseDate(string dt)
Returns:

The datetime object which is represented by the string.

Return type:

datetime

Parameters:

dt (str) – The string representing the date to be returned.

If the string (dt) will be parsed and use various formats to discover the date. If it does not properly parse out to a date, a Python None value will be returned.

Example:

dt = model.ParseDate('5/30/{}'.format(model.DateTime.Year))
print "Day of Week for my birthday ({:M/d/yyyy}) this year is {:dddd}".format(dt, dt)
model.SetToday(dt)
Parameters:

dt (datetime) – The date to simulate.

This function is for debugging. You can make all functionality of the script behave as if hte date is the one set. All functions called during the script will also behave as if the date is the one set. This value is stored in the user’s session and will not affect other users. This function should never be used in code that will be executed in the batch process.

model.ResetToday()

This function is for debugging. This will revert the current date back to the actual date.

model.SundayForDate(dt)
Returns:

The first day of the week (Sunday) in which the dt parameter occurs.

Return type:

datetime

Parameters:

dt (datetime) – The date for which to find it’s corresponding Sunday (it can be a str or a datetime).

model.SundayForWeek(year, week)
Returns:

The Sunday for the numbered week in the specified.

Return type:

datetime

Parameters:
  • year (int) – The year (e.g. 2016)

  • week (int) – The numbered week, 1-52.

For example:

year = 2016
print '<table class="table" style="width:auto">'
row = '<tr><td>{}</td><td>{:MM/dd/yyyy}</td></tr>'
for week in range(1, 53):
    print row.format(week, model.SundayForWeek(year, week))
print '</table>'

This prints the all the Sundays in the year 2016.

model.WeekNumber(dt)
Returns:

The week number (of the year) for the given date.

Return type:

int

Parameters:

dt (datetime) –

Example:

print model.WeekNumber('7/4/2016')
model.WeekOfMonth(dt)
Returns:

The week number of the month for the given date.

Return type:

int

Parameters:

dt (datetime) –

The week number is determined by the Sunday on or before the given date. The first Sunday in a month is WeekOfMonth = 1

If you only wanted to send emails on the Thursday before the first week of the month, you could do the following:

orgids = [110, 120, 155]
nextWeek = model.DateAddDays(model.DateTime, 7)
nextWeekOfMonth = model.WeekOfMonth(nextWeek)
if model.DayOfWeek == 4 and nextWeekOfMonth == 1:
    for orgid in orgids:
        model.EmailReminders(orgid)