Skip to content

Instantly share code, notes, and snippets.

@izelnakri
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save izelnakri/9c436b73a82332711b5e to your computer and use it in GitHub Desktop.

Select an option

Save izelnakri/9c436b73a82332711b5e to your computer and use it in GitHub Desktop.
Putzplan
#Assigns the tasks and sends an email every week.
#Deployed as a heroku worker(requires a Procfile in the same directory)
require 'coffee-script'
require 'colors'
nodemailer = require('nodemailer')
getWeekNumber = (d) ->
# Copy date so don't modify original
d = new Date(+d)
d.setHours 0, 0, 0
# Set to nearest Thursday: current date + 4 - current day number
# Make Sunday's day number 7
d.setDate d.getDate() + 4 - (d.getDay() or 7)
# Get first day of year
yearStart = new Date(d.getFullYear(), 0, 1)
# Calculate full weeks to nearest Thursday
weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7)
# Return array of year and week number
weekNo
names = ["Johannes", "Moriz", "Izel", "Anton", "Martina"]
l = names.length
smtpTransport = nodemailer.createTransport("SMTP",
service: "Gmail"
auth:
user: "hermannmailer@gmail.com"
pass: "censored" #ourwifipass + 148
)
assignJobs = () ->
week = getWeekNumber(new Date()) + 2
jobs = {
toilet: names[week++ % l],
hall: names[week++ % l],
kitchen: names[week++ % l],
bathroom: names[week++ % l],
shopping: names[week++ % l]
}
console.log jobs
errorMail = {
from: "hermannmailer@gmail.com",
to: "contact@izelnakri.com",
subject: "ERROR: PUTZPLAN - #{week} - Automated",
html: "<h1>Error Occured for this weeks putzplan mail</h1>"
}
mailOptions = {
from: "hermannmailer@gmail.com",
to: "herminatorwg@gmail.com",
subject: "PUTZPLAN - #{week} - Automated",
html: "<div>
<h1>Putzplan</h1>
<h2>Toilets/Wash Towels: #{jobs.toilet}</h2>
<ul>
<li>Wash kitchen towels and bathroom rug at 40°</li>
<li>Tidy up trash</li>
<li>Brush toilets</li>
<li>Scrub floor</li>
</ul>
<h2>Hall: #{jobs.hall}</h2>
<ul>
<li>Tidy up trash (cans, ashtrays, glasses etc)</li>
<li>Put shoes into shelf</li>
<li>Tidy up couch</li>
<li>Vacuum floor</li>
<li>Scrub floor</li>
</ul>
<h2>Kitchen: #{jobs.kitchen}</h2>
<ul>
<li>Clean dishes</li>
<li>Clean surfaces</li>
<li>Scrub floor</li>
</ul>
<h2>Bathroom: #{jobs.bathroom}</h2>
<ul>
<li>Clean sink and bathtub</li>
<li>Vacuum floor</li>
<li>Scrub floor</li>
<li>Clean mirror if neccessary</li>
</ul>
<h2>Shopping/Trash: #{jobs.shopping}</h2>
If neccessary, buy:
<ul>
<li>Toilet paper</li>
<li>Sponges</li>
<li>Cleaning supplies</li>
<li>Salt</li>
<li>Washing powder</li>
<li>Dish soap</li>
<li>Kitchen roll</li>
</ul>
Also bring to trashcans:
<ul>
<li>Wastepaper</li>
<li>Trash in kitchen</li>
<li>Trash in bathroom</li>
<li>Trash in hallway</li>
<li>Bottles</li>
</ul>
<hr>
<div>
<small>Week Number #{week}, Code: <a href='https://gist.github.com/izelnakri/9c436b73a82332711b5e'>Here</a>, Website: <a href='http://buesing.at/putzplan'>Here</a>
</small>
</div>
</div>"
}
smtpTransport.sendMail mailOptions, (error, response) ->
if error
console.log error.red
smtpTransport.sendMail errorMail, (error, response) ->
if error
console.log "Error Message not sent".red
else
console.log "Error Message sent".green
else
console.log "Message sent: ".green + response.message
return
# if you don't want to use this transport object anymore, uncomment following line
#smtpTransport.close(); // shut down the connection pool, no more messages
# assignJobs()
setInterval(assignJobs, 605000000)
#1 week ~= 605000000 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment