How the HELL is oncall ? (the oncall reminder script)

When you have oncall often sometimes is easy to forget hows oncall and when you are not. So for the last time wonder how is oncall and ask some python for some help,


The script

#!/usr/bin/env python
# Mattias Hemmingsson
# Script for reminder friend when to bet
# Uses and csv file and send email to remind when its time to bet.
import csv
import smtplib
from datetime import datetime, timedelta, date

#Get users and send email to users
sender = ''
emails =[]
better = ""
week = 2
def save_to_file(name):
 Saves the oncall to file
 f = open("oncall.txt", "w")
def read_file():
 read the oncall to file
 f = open("oncall.txt", "r")
 return int(f.readline()) + 1
def send_oncall():
 Send an reminder ho is oncall
#Get cont on oncall staff and next oncall
 numeroncall = str(int(len(open("people.csv").readlines())) +1)
 nextoncall = str(read_file())

 #Loop to begning of file 
 if nextoncall == numeroncall:
 nextoncall = '1'

 #Send email to oncall staff
#Get how is oncall
 with open('people.csv', 'rb') as f:
 reader = csv.reader(f)
 for row in reader:
 if row[0] == nextoncall:
 oncall = row[1]
 #Save oncall to file

 message = """From: SYCO <>
 Subject: {0} IS NOW ONCALL

 This is an reminder that {0} is now oncall.

#Sending the email
def send_email(emails,message):
 sender = ""
 Send the email

 smtpObj = smtplib.SMTP('localhost')
 smtpObj.sendmail(sender, emails, message) 
 print "Successfully sent email"
 except SMTPException:
 print "Error: unable to send email"

 print emails
 print sender + message

And then a file with the oncall staff

1,Mattias Hemmingsson,
2,oncall one,
3,oncall two,
4,oncall tre,


More update in my github