Esempio n. 1
0
 def post(self):
   if not self.current_user_can('send_daily_email'):
     raise tornado.web.HTTPError(401)
     
   action = self.get_argument('action', None)
   
   if not action:
     return self.write("Select an action")
   
   if action == "setup_email":
     posts = postsdb.get_hot_posts_by_day(datetime.today())
     slugs = []
     for i, post in enumerate(posts):
       if i < 5:
         slugs.append(post['slug'])
     response1 = emailsdb.construct_daily_email(slugs)
     print response1
     
     response2 = emailsdb.setup_email_list()
     print response2
   
   if action == "add_list_to_email":
     response3 = emailsdb.add_list_to_email()
     print response3
   
   if action == "send_email":
     response4 = emailsdb.send_email()
     print response4
import settings
import requests
import logging
from datetime import datetime

from lib import postsdb, emailsdb
import csv

# 1) get 5 slugs
posts = postsdb.get_hot_posts_by_day(datetime.today())
slugs = []
for i, post in enumerate(posts):
    if i < 5:
        slugs.append(post['slug'])

# 2) construct email
#request1 = emailsdb.construct_daily_email(slugs)

# Setup list for the day
#if request1['message'] == "success":
#       request2 = emailsdb.setup_email_list()

# Add list to email
#if request2['message'] == "success":
request3 = emailsdb.add_list_to_email()

# 3) send it
if request3['message'] == "success":
    print "READY!"
#result = emailsdb.send_daily_email(email)