def send_comment(comment_text): logging.debug("comment from user: %s" % comment_text) if not comment_text is None and not comment_text == '': user = users.get_current_user() mailer.send(sender=user.email(), recipient=settings.COMMENT_NOTIFICATION_RECIPIENT, subject=settings.COMMENT_NOTIFICATION_SUBJECT, message=comment_text)
def get(self): logging.info('starting batch insert job') users = Student.all().filter("auto =", True).order("-lastrun").fetch(limit=1000) for user in users: if user.calendar_id: try: event_list = bseu_schedule.fetch_and_parse_week(user) except Exception, e: logging.error(e) else: if event_list: create_calendar_events(user, event_list) mailer.send(recipient=user.student.email(), params={'user': user.student, 'events': event_list})
def main(): FROM_ADDRESS = '*****@*****.**' TO_ADDRESS = '*****@*****.**' BCC = '' # トップページのクローリング html = cr.crawling_top_page() # スクレイピングして基本情報をリスト化 result = sc.base_information(html) # 日付による判定の準備 today = datetime.datetime.today() tomorrow = (today + datetime.timedelta(days=1)).date() four_days_later = (today + datetime.timedelta(days=4)).date() today_weekday = today.weekday() # 日付により判定→メール作成 if today_weekday == 2: # もし今日が水曜日なら # 今週末の予定 subject = '今週末の練習予定(自動配信)' mail_content = "今週末の練習予定です。\n\n" for i in result: if four_days_later >= date_formatted(i[1]): # その予定が4日後以内にあるなら html1 = cr.crawling_each_page(i[0]) information = sc.each_information(html1) mail_content += ma.shaping_content(information) if mail_content != "今週末の練習予定です。\n\n": # もし今週末の予定が何かしらあるならメールを送信する。 mail_content += "\n出欠の回答はこちらから→https://hikonii-group-schedule.herokuapp.com" msg = ma.create_message(FROM_ADDRESS, TO_ADDRESS, BCC, subject, mail_content) ma.send(FROM_ADDRESS, TO_ADDRESS, msg) for j in result: if tomorrow == date_formatted(j[1]): # 明日の予定 subject1 = '明日の練習予定(自動配信)' mail_content = '明日の練習予定です。\n\n' html2 = cr.crawling_each_page(j[0]) information = sc.each_information(html2) mail_content += ma.shaping_content(information) mail_content += "\n出欠の回答はこちらから→https://hikonii-group-schedule.herokuapp.com" msg = ma.create_message(FROM_ADDRESS, TO_ADDRESS, BCC, subject1, mail_content) ma.send(FROM_ADDRESS, TO_ADDRESS, msg)