Beispiel #1
0
def main():
	# The configuration is merged from the different sources
	configuration= Configuration.getInstance()
	logging= configuration["loggingModule"]
	random.seed()
	
	configuration["stats"]= {
		"emailsSuccessfully" : 0, # emails were sent
		"emailsFailed" : 0, # emails could not be sent
		"groupsSuccessfully" : 0, # groups were processed and removed from the db
		"groupsFailed" : 0, # groups could not be processed because of failing emails
		"remainingNotifications" : 0,  # notifications are still remaining in the database
		"remainingGroups" : 0,  # notifications are still remaining in the database
		"remainingEmails" : 0, } # notifications are still remaining in the database
	
	# The notifications to be sent are fetched from the database
	logging.debug("Connecting to the database server \"%s\"..." % (configuration["DB"]["host"],))
	
	try:
		connection= MySQLdb.connect(**configuration["DB"])
		
		connection.query("""
			select 
				`notifications`.`unique`, 
				`notifications`.`email`, 
				`groups`.`unique`, 
				`groups`.`name`, 
				`groups`.`theory_or_lab`, 
				`groupsT`.`teacher`, 
				`groupsL`.`teacher`, 
				`courses_semester`.`course_type`, 
				`courses`.`symbol`, 
				`courses`.`title` 
			from `notifications` 
			inner join `groups` on 
				`notifications`.`group` = `groups`.`unique` 
			left join `groups` as `groupsT` on 
				`groups`.`course_semester` = `groupsT`.`course_semester` and 
				`groups`.`name` = `groupsT`.`name` and 
				`groupsT`.`theory_or_lab` = 'C' 
			left join `groups` as `groupsL` on 
				`groups`.`course_semester` = `groupsL`.`course_semester` and 
				`groups`.`name` = `groupsL`.`name` and 
				`groupsL`.`theory_or_lab` = 'L' 
			inner join `courses_semester` on 
				`groups`.`course_semester` = `courses_semester`.`unique` 
			inner join `courses` on 
				`courses_semester`.`course` = `courses`.`unique` 
			where `groups`.`closed` = '0'
			order by `notifications`.`email`
		""")
	except MySQLdb.MySQLError, message:
		logging.critical("MySQL error %d: %s" % (message[0], message[1]))
		return 1
Beispiel #2
0
def getTemplateValues(notification):
	configuration= Configuration.getInstance()
	
	values= {
		"symbol" : notification["courses.symbol"], 
		"title" : notification["courses.title"], 
		"name" : notification["groups.name"],}
	
	if notification["courses_semester.course_type"] == "TL":
		values["theory_or_lab"]= "combinée théorique et laboratoire"
		values["teacher"]= "\n\tThéorie: %s\n\tLab: %s" % (notification["groupsT.teacher"], notification["groupsL.teacher"],)
	elif notification["groups.theory_or_lab"] == "C":
		values["theory_or_lab"]= "théorique"
		values["teacher"]= notification["groupsT.teacher"]
	elif notification["groups.theory_or_lab"] == "L":
		values["theory_or_lab"]= "laboratoire"
		values["teacher"]= notification["groupsL.teacher"]
	else:
		raise(Exception("Unknown course type"))
	
	return values