I am currently writing a support rota for my workplace.
The code itself is simple
import itertools
names = ["P1", "P2", "P3"]
extns = {'P1': 'xxxx', 'P2': 'xxxy', 'P3': 'xxyy'}
for _ in itertools.repeat(None, 5):
for name in names:
print name + " | " + extns[name]
(Names replaced with Pn and numbers replaced with "x/y" substitutes)
This works great so far and gives me the expected output of
P1 | xxxx
P2 | xxxy
P3 | xxyy
repeated 5 times.
However the desired output is
| <Todays Date> | P1 | xxxx |
Obviously I could just use a calendar Lib and use the data from there and then just do something such a today+1
for tomorrow's date etc.
The problem occurs when trying to skip weekend.
Working a 5 day week means we do not allocate support on weekends (Saturday/Sunday 0000-2400)
For example for September the 1st was a monday so I would want the dates to be
01-09-14
02-09-14
03-09-14
04-09-14
05-09-14
08-09-14
09-09-14
As you can see it skips the 6th and 7th as that is a saturday and sunday.
I have looked at the calendar
module and found code for:
calendar.setfirstday()
Which sounds promising, I can also use
iterweekdays()
to return and iterator for weekdays.
I'm not sure though whether this would give dates if I were to iterate through it. I am also unsure how I would actually iterate through it.
EDIT:
Below is expected output:
| 10-09-14 | P1 | xxxx |
| 11-09-14 | P2 | xxxy |
| 12-09-14 | P3 | xxyy |
| 15-09-14 | P1 | xxxx |
| 16-09-14 | P2 | xxxy |
| 17-09-14 | P3 | xxyy |
| 18-09-14 | P1 | xxxx |
| 19-09-14 | P2 | xxxy |
| 22-09-14 | P3 | xxxy |
| 23-09-14 | P1 | xxxx |
| 24-09-14 | P2 | xxxy |
| 25-09-14 | P3 | xxyy |
| 26-09-14 | P1 | xxxx |
| 29-09-14 | P2 | xxxy |
| 30-09-14 | P3 | xxyy |
Currently I can get todays date and check whether or not it is a weekday. The problem then is going ahead in time.