Exemple #1
0
def create_email_body(dbname, start_dt, end_dt):
    import FetchRSS2 as FR
    import keywords
    import SMZDMscaner as SZ
    import datetime as dt

    # smzdmitems_query = FR.SmzdmItem.all().ancestor(FR.smzdmitem_key(dbname)).order('-dt')
    smzdmitems_query = (
        FR.SmzdmItem.all()
        .ancestor(FR.smzdmitem_key(dbname))
        .filter("dt >=", start_dt)
        .filter("dt <", end_dt)
        .order("-dt")
    )
    query = smzdmitems_query.fetch(smzdmitems_query.count())
    keywords_list = keywords.Keywords().keywords_list

    # query2 = smzdmitems_query.filter("title like ", '%xbox%')

    # body_html = u"<p>========================================</p>"
    body_html = u""
    for q in query:
        sz = SZ.SMZDMscaner(q.title)
        if sz.SearchForKeywords(keywords_list):
            if q.keyword:
                body_html += u"""<H3>{0}<a href="{1}">直达链接</a></H3>
                                 <p><b>简介:</b>{2}</p>
                                 <p><b>命中关键字:</b>{3}  <b>发布时间:</b><i>{4}</i></p>
                                 <p></p>""".format(
                    q.title, q.link, q.desc, q.keyword, q.dt
                )
            else:
                body_html += u"""<H3>{0}<a href="{1}">直达链接</a></H3>
                                 <p><b>简介:</b>{2}  <b>发布时间:</b><i>{3}</i></p>
                                 <p></p>""".format(
                    q.title, q.link, q.desc, q.dt
                )
            body_html += u"<p>----------------------------------------</p>"

    return body_html
Exemple #2
0
    def get(self):
        smzdmitem_name = "smzdmtest"
        start_dt, end_dt = FR.GetDataDTSection(dt.datetime.now(), period=120)

        # rss_url = 'http://feed.smzdm.com'  # 优惠精选
        # rss_url = 'http://faxian.smzdm.com/feed'  # 发现
        rss_url_list = [
            'http://feed.smzdm.com',
            'http://faxian.smzdm.com/feed'
        ]
        for rss_url in rss_url_list:
            opener = ureq.build_opener()
            opener.addheaders = [('User-agent', 'Mozilla/5.0 (Macintosh Intel Mac OS X 10_10_2) \
                                AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36')]
            rss_file = opener.open(rss_url)
            rss_text = rss_file.read()

            # rss_file = open('rss.txt')
            # rss_text = rss_file.read()
            # # 数据更新开关
            FR.FetchRSS2(rss_text).get_item_list(smzdmitem_name, start_dt, end_dt)

            smzdmitems_query = FR.SmzdmItem.all().ancestor(FR.smzdmitem_key(smzdmitem_name)).order('-dt')
            # query = smzdmitems_query.fetch(smzdmitems_query.count())

            # start_dt, end_dt = FR.GetDataDTSection(dt.datetime(2016, 1, 20, 20, 15), 120)
            # self.response.out.write("Start_dt is: {0} End_dt is {1}".format(start_dt, end_dt))
            # self.response.out.write(smtp2.create_email_body(smzdmitem_name, start_dt, end_dt))

            self.response.out.write("Start_dt is: {0} End_dt is {1}".format(start_dt, end_dt))
            self.response.out.write(smtp2.create_email_body(smzdmitem_name, start_dt, end_dt))

            body_html = smtp2.create_email_body(smzdmitem_name, start_dt, end_dt)
            smtp2.send_email(subject="SMZDM Notification: " + rss_url, body=body_html, send_ind=True)

            rss_file.close()