from model import *
import util
import datetime
from sqlalchemy import and_

#MNPY_RECEIVER = 'weiyi@papayamobile.com'
MNPY_RECEIVER = 'appflood_engineer@papayamobile.com'

MNPY_SNIPPET = """
<h4 style="margin:0;margin-bottom:6px;margin-top:6px">
<a style="font-size:14px;line-height:22px;font-weight:bold;text-decoration:none;color:#259;border:none;outline:none" href="%s" target="_blank">%s</a>&nbsp;&nbsp;</h4>
"""

def notify(body='\xe4\xbb\x80\xe4\xb9\x88\xe9\x83\xbd\xe6\xb2\xa1\xe6\x9c\x89......'):
    title = '[Python]\xe7\xa0\x81\xe5\x86\x9c\xe5\x91\xa8\xe5\x88\x8aPython\xe7\x9b\xb8\xe5\x85\xb3\xe4\xb8\xbb\xe9\xa2\x98\xe6\x9b\xb4\xe6\x96\xb0'
    util.send_email(title, body, MNPY_RECEIVER)


def task():
    today = datetime.datetime.now()
    yesterday = today - datetime.timedelta(1)
    mps = ManongPython.query.filter(and_(ManongPython.create_time>yesterday, ManongPython.create_time<today)).all()
    print '=============', len(mps)
    body = ''
    if mps:
        for mp in mps:
            body += MNPY_SNIPPET % (mp.url, mp.title)
        notify(body)
        html()

def html():
    mps = ManongPython.query.all()
    body = ''
    for mp in mps:
        body += MNPY_SNIPPET % (mp.url, mp.title)
    #print body
    with open('/var/server/www/mnpy.html', 'w') as f:
        f.write(body.encode('utf8'))


@@ -904,24 +904,60 @@
 day)).all()%0A
+    #mps = ManongPython.query.all()%0A
     print '=
@@ -988,25 +988,154 @@
     body = '
-'
+%3Cmeta charset=%22UTF-8%22%3E'%0A    body += MNPY_SNIPPET %25 ('http://appflood.ml/mnpy.html', u'%5Cu6240%5Cu6709%5Cu7ed3%5Cu679c%5Cu7684%5Cu9875%5Cu9762')
 %0A    if mps:

add html