Advertisement
Guest User

generic_shiftdates_with_emailer.py

a guest
Jan 22nd, 2018
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.30 KB | None | 0 0
  1. import datetime
  2. from emailer_live import mailer
  3. from monthly_tally import EOM
  4. ''' calculates shift pattern of 6 nights 3 off for a set period, along with the shidts and hours.worked in every month for that period '''
  5. class Shift_Pattern_Dates:
  6.     def pattern_generator_2(self, sdate, edate, ons, offs):
  7.         """ons who the shifts scheduled amd offs the immediate off days for the corresponding shift in ons """
  8.         result =''
  9.         new_month = False
  10.         startdate = datetime.datetime.strptime(sdate, '%d/%m/%Y')
  11.         enddate = datetime.datetime.strptime(edate,'%d/%m/%Y' )
  12.         monthly_tally = 0
  13.         oneday = datetime.timedelta(days = 1)
  14.         current_month = startdate.month
  15.         while startdate <= enddate:    
  16.             for i in range(0, 6):
  17.                 current_month, startdate, result, monthly_tally = EOM.tally(current_month, startdate, new_month, monthly_tally)
  18.                 mnth_name = startdate.strftime('%B')
  19.                 if new_month:
  20.                     result += '='*40+'\n'        
  21.                     result += mnth_name + ':  Shifts = ' + str(monthly_tally)+ ' Hours Total = ' + str(monthly_tally * 12) +'\n' +'='*40+'\n'
  22.                 monthly_tally = monthly_tally + 1
  23.                 result += startdate.strftime('%A, %B %d, %Y') + ' - On' +'\n'
  24.                 startdate = startdate + oneday    
  25.           #skip current day and following 2 days
  26.             for j in range(0, 3):
  27.                 current_month, startdate, result, monthly_tally = EOM.tally(current_month, startdate, new_month, monthly_tally)
  28.                 mnth_name = startdate.strftime('%B')
  29.                 if new_month:
  30.                     result += '='*40+'\n'        
  31.                     result += mnth_name + ':  Shifts = ' + str(monthly_tally)+ ' Hours Total = ' + str(monthly_tally * 12) +'\n' +'='*40+'\n'              
  32.                 result += startdate.strftime('%A, %B %d, %Y') +  ' - Off' + '\n'
  33.                 startdate = startdate + oneday
  34.         return result + summary
  35.                      
  36. c = Shift_Pattern_Dates()
  37. e = mailer()
  38. # startdate, enddate, days, off, nights, off
  39. shifts_and_tally = c.pattern_generator_2('27/01/2018', '31/12/2018', [3,0],[3,3])
  40. print(shifts_and_tally)
  41. e.smtp_mailer(shifts_and_tally, 'Rota For Period: 27/01/2018 - 31/12/2018', 'dsthecheduler', ['denis.seale@gmail.com'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement