include discordian date into mail digest ;-)
This commit is contained in:
parent
d60783b6aa
commit
546ca45337
@ -6,6 +6,7 @@ from models import Base, Feed, Feedinfo, Entry
|
||||
from sqlalchemy import create_engine, desc
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from datetime import datetime
|
||||
from ddate import ddate
|
||||
import feedparser
|
||||
import sys
|
||||
import codecs
|
||||
@ -64,7 +65,7 @@ def mail_daily_digest(session, sender, receiver, prefix):
|
||||
link = entry.resolvedlink
|
||||
try:
|
||||
body = body + '=> %s - %s\n' % (entry.firstfetched.strftime('%y%m%d-%H%M'), feedinfo.title)
|
||||
body = body + ' %s\n' % entry.title
|
||||
body = body + '>> %s\n' % entry.title
|
||||
body = body + '%s\n' % truncate_text(entry.get_text(), 250)
|
||||
body = body + '%s\n\n' % link
|
||||
except:
|
||||
@ -75,6 +76,7 @@ def mail_daily_digest(session, sender, receiver, prefix):
|
||||
if count > 0:
|
||||
today = datetime.now()
|
||||
subject = '%s (%s) - %d entries' % (today.strftime('%y%m%d'), today.strftime('%A'), count)
|
||||
body = '%s\n\n%s\n\n%s' % (subject, ddate(), body)
|
||||
if prefix != '':
|
||||
subject = '%s %s' % (prefix, subject)
|
||||
send_mail(sender, receiver, subject, body)
|
||||
|
43
ddate.py
Normal file
43
ddate.py
Normal file
@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from datetime import datetime
|
||||
from calendar import isleap
|
||||
|
||||
class ddate(object):
|
||||
def __init__(self, aDate = datetime.now()):
|
||||
self.dSeasonNum = 0
|
||||
self.dDayOfWeek = 0
|
||||
self.dDayOfSeason = 0
|
||||
self.dYOLD = 0
|
||||
self.dSeasonHoliday = False
|
||||
self.dApostleHoliday = False
|
||||
self.dStTibs = False
|
||||
|
||||
dayOfYear = aDate.timetuple().tm_yday - 1
|
||||
self.dStTibs = isleap(aDate.year) and (aDate.month == 2) and (aDate.day == 29)
|
||||
if(isleap(aDate.year) and (dayOfYear >= 60)):
|
||||
dayOfYear -= 1
|
||||
self.dDayOfWeek = (dayOfYear % 5)
|
||||
self.dSeasonNum, self.dDayOfSeason = divmod(dayOfYear, 73)
|
||||
self.dDayOfSeason += 1
|
||||
self.dYOLD = aDate.year + 1166
|
||||
if(self.dDayOfSeason==5):
|
||||
self.dApostleHoliday = True
|
||||
if(self.dDayOfSeason==50):
|
||||
self.dSeasonHoliday = True
|
||||
|
||||
def __str__(self):
|
||||
strWeekday = ["Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"][self.dDayOfWeek]
|
||||
suffixes = ["th", "st", "nd", "rd", ] + ["th"] * 16 + (["th", "st", "nd", "rd", ] + ["th"] * 6) * 10
|
||||
strDaynum = '%d%s' % (self.dDayOfSeason, suffixes[self.dDayOfSeason % 100])
|
||||
strSeason = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"][self.dSeasonNum]
|
||||
strHolidayApostle = ["Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"][self.dSeasonNum]
|
||||
strHolidaySeason= ["Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"][self.dSeasonNum]
|
||||
if(self.dStTibs):
|
||||
return 'St. Tib\'s Day, YOLD %d!' % self.dYOLD
|
||||
else:
|
||||
msg = u'Today is %s, the %s day of %s in the YOLD %d.' % (strWeekday, strDaynum, strSeason, self.dYOLD)
|
||||
if(self.dSeasonHoliday):
|
||||
msg = u'%s\nCelebrate %s!' % (msg, strHolidaySeason)
|
||||
if(self.dApostleHoliday):
|
||||
msg = u'%s\nCelebrate %s!' % (msg, strHolidayApostle)
|
||||
return msg
|
Loading…
Reference in New Issue
Block a user