Example #1
0
  def get(self, feed_type="hot"):
    #action = self.get_argument('action', '')
    page = abs(int(self.get_argument('page', '1')))
    per_page = abs(int(self.get_argument('per_page', '9')))

    posts = []
    if feed_type == 'new':
      # show the newest posts
      posts = postsdb.get_new_posts(per_page, page)
    elif feed_type == 'sad':
      # show the sad posts
      posts = postsdb.get_sad_posts(per_page, page)
    elif feed_type == 'hot':
      # show the sad posts
      posts = postsdb.get_daily_posts_by_sort_score(8)
    elif feed_type == 'superhot':
      # show the sad posts
      posts = postsdb.get_daily_posts_by_sort_score(20)
    elif feed_type == 'superduperhot':
      # show the sad posts
      posts = postsdb.get_daily_posts_by_sort_score(50)
    elif feed_type == 'today':
      posts = postsdb.get_hot_posts_by_day()
    else:
      posts = postsdb.get_hot_posts_by_day()

    self.render('post/feed.xml', posts=posts)
Example #2
0
    def get(self, feed_type="hot"):
        #action = self.get_argument('action', '')
        page = abs(int(self.get_argument('page', '1')))
        per_page = abs(int(self.get_argument('per_page', '9')))

        posts = []
        if feed_type == 'new':
            # show the newest posts
            posts = postsdb.get_new_posts(per_page, page)
        elif feed_type == 'sad':
            # show the sad posts
            posts = postsdb.get_sad_posts(per_page, page)
        elif feed_type == 'hot':
            # show the sad posts
            posts = postsdb.get_daily_posts_by_sort_score(8)
        elif feed_type == 'superhot':
            # show the sad posts
            posts = postsdb.get_daily_posts_by_sort_score(20)
        elif feed_type == 'superduperhot':
            # show the sad posts
            posts = postsdb.get_daily_posts_by_sort_score(50)
        elif feed_type == 'today':
            posts = postsdb.get_hot_posts_by_day()
        else:
            posts = postsdb.get_hot_posts_by_day()

        self.render('post/feed.xml', posts=posts)
Example #3
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
Example #4
0
 def get(self):
     day = datetime.datetime.strptime(self.get_argument('day'), "%Y-%m-%d %H:%M:%S")
     yesterday = day - datetime.timedelta(days=1)
     posts = postsdb.get_hot_posts_by_day(day)
     html = self.render_string('post/daily_posts_list_snippet.html', today=day, yesterday=yesterday, posts=posts, current_user_can=self.current_user_can)
     response = {}
     response['html'] = html
     self.api_response(response)
Example #5
0
    def get(self, extra_path=''):
        view = self.get_argument('view', 'sidebar')
        if extra_path != '':
            self.render('post/widget_demo.html')
        else:
            # list posts
            num_posts =abs(int(self.get_argument('num_posts', '5')))

            # get the current hot posts
            day = datetime.datetime.today()
            posts = postsdb.get_hot_posts_by_day(day)
            addl_posts = []
            if len(posts) < 5:
                yesterday = day - datetime.timedelta(days=1)
                addl_posts = postsdb.get_hot_posts_by_day(yesterday)
            all_posts = posts + addl_posts
            if view == "sidebar":
                # get the current hot posts
                posts = postsdb.get_hot_posts_24hr()
                self.render('post/widget.js', posts=posts, num_posts=num_posts)
            else:
                posts = postsdb.get_hot_posts_24hr()
                self.render('post/widget_inline.js', posts=posts, num_posts=3)
Example #6
0
    def get(self, extra_path=''):
        view = self.get_argument('view', 'sidebar')
        if extra_path != '':
            self.render('post/widget_demo.html')
        else:
            # list posts
            #action = self.get_argument('action', '')
            page = abs(int(self.get_argument('page', '1')))
            per_page = abs(int(self.get_argument('per_page', '9')))
            num_posts = abs(int(self.get_argument('num_posts', '5')))

            if view == "sidebar":
                # get the current hot posts
                posts = postsdb.get_hot_posts(per_page, page)
                self.render('post/widget.js', posts=posts, num_posts=num_posts)
            else:
                posts = postsdb.get_hot_posts_by_day()
                self.render('post/widget_inline.js', posts=posts, num_posts=3)
Example #7
0
  def get(self, extra_path=''):
    view = self.get_argument('view', 'sidebar')
    if extra_path != '':
      self.render('post/widget_demo.html')
    else:
      # list posts
      #action = self.get_argument('action', '')
      page = abs(int(self.get_argument('page', '1')))
      per_page = abs(int(self.get_argument('per_page', '9')))
      num_posts = abs(int(self.get_argument('num_posts', '5')))

      if view == "sidebar":
        # get the current hot posts
        posts = postsdb.get_hot_posts(per_page, page)
        self.render('post/widget.js', posts=posts, num_posts=num_posts)
      else: 
        posts = postsdb.get_hot_posts_by_day()
        self.render('post/widget_inline.js', posts=posts, num_posts=3)
Example #8
0
    def get(self, day="today", page=1, sort_by="hot"):
        view = "list"
        sort_by = self.get_argument('sort_by', sort_by)
        page = abs(int(self.get_argument('page', page)))
        per_page = abs(int(self.get_argument('per_page', '20')))
        msg = self.get_argument('msg', '')
        slug = self.get_argument('slug', '')
        new_post = None
        if slug:
            new_post = postsdb.get_post_by_slug(slug)

        featured_posts = postsdb.get_featured_posts(1)
        posts = []
        post = {}
        hot_tags = tagsdb.get_hot_tags()

        is_today = False
        if day == "today":
            is_today = True
            day = datetime.datetime.today()
        else:
            day = datetime.datetime.strptime(day, "%Y-%m-%d")
        previous_day = day - datetime.timedelta(days=1)
        two_days_ago = previous_day - datetime.timedelta(days=1)

        day_str = str(datetime.date(day.year, day.month, day.day))
        previous_day_str = str(
            datetime.date(previous_day.year, previous_day.month,
                          previous_day.day))
        two_days_ago_str = str(
            datetime.date(two_days_ago.year, two_days_ago.month,
                          two_days_ago.day))

        show_day_permalink = True
        infinite_scroll = False
        if self.request.path == ('/'):
            show_day_permalink = False
            infinite_scroll = True

        is_blacklisted = False
        if self.current_user:
            is_blacklisted = self.is_blacklisted(self.current_user)

        posts = postsdb.get_hot_posts_by_day(day)
        #posts = postsdb.get_hot_posts_24hr()
        previous_day_posts = postsdb.get_hot_posts_by_day(previous_day)

        #midpoint = (len(posts) - 1) / 2
        # midpoint determines where post list breaks from size=md to size=sm
        midpoint = 7
        hot_posts_past_week = postsdb.get_hot_posts_past_week()

        self.vars.update({
            'is_today': is_today,
            'view': view,
            'msg': msg,
            'posts': posts,
            'previous_day_posts': previous_day_posts,
            'hot_posts_past_week': hot_posts_past_week,
            'featured_posts': featured_posts,
            'post': post,
            #'featured_posts': featured_posts,
            'is_blacklisted': is_blacklisted,
            'tags': hot_tags,
            'day': day,
            'day_str': day_str,
            'previous_day': previous_day,
            'previous_day_str': previous_day_str,
            'two_days_ago': two_days_ago,
            'two_days_ago_str': two_days_ago_str,
            'show_day_permalink': show_day_permalink,
            'infinite_scroll': infinite_scroll,
            'midpoint': midpoint,
            'new_post': new_post,
            'datetime': datetime
        })
        self.render('post/lists_posts.html', **self.vars)
# Run by Heroku scheduler every night
# If running locally, uncomment below imports
import sys
# sys.path.insert(0, '/Users/nick/dev/usv/usv.com')
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
Example #10
0
  def get(self, day="today", page=1, sort_by="hot"):
    view = "list"
    sort_by = self.get_argument('sort_by', sort_by)
    page = abs(int(self.get_argument('page', page)))
    per_page = abs(int(self.get_argument('per_page', '20')))
    msg = self.get_argument('msg', '')
    slug = self.get_argument('slug', '')
    new_post = None
    if slug:
      new_post = postsdb.get_post_by_slug(slug)
      
    featured_posts = postsdb.get_featured_posts(1)
    posts = []
    post = {}
    hot_tags = tagsdb.get_hot_tags()
    
    is_today = False
    if day == "today":
      is_today = True
      day = datetime.datetime.today()
    else:
      day = datetime.datetime.strptime(day, "%Y-%m-%d")
    previous_day = day - datetime.timedelta(days=1)
    two_days_ago = previous_day - datetime.timedelta(days=1)
    
    day_str = str(datetime.date(day.year, day.month, day.day))
    previous_day_str = str(datetime.date(previous_day.year, previous_day.month, previous_day.day))
    two_days_ago_str = str(datetime.date(two_days_ago.year, two_days_ago.month, two_days_ago.day))
    
    show_day_permalink = True
    infinite_scroll = False
    if self.request.path == ('/'):
      show_day_permalink = False
      infinite_scroll = True
    
    is_blacklisted = False
    if self.current_user:
      is_blacklisted = self.is_blacklisted(self.current_user)

    posts = postsdb.get_hot_posts_by_day(day)
    #posts = postsdb.get_hot_posts_24hr()
    previous_day_posts = postsdb.get_hot_posts_by_day(previous_day)
    
    
    #midpoint = (len(posts) - 1) / 2
    # midpoint determines where post list breaks from size=md to size=sm
    midpoint = 7
    hot_posts_past_week = postsdb.get_hot_posts_past_week()

    self.vars.update({
      'is_today': is_today,
      'view': view,
      'msg': msg,
      'posts': posts,
      'previous_day_posts': previous_day_posts,
      'hot_posts_past_week': hot_posts_past_week,
      'featured_posts': featured_posts,
      'post': post,
      #'featured_posts': featured_posts,
      'is_blacklisted': is_blacklisted,
      'tags': hot_tags,
      'day': day,
      'day_str': day_str,      
      'previous_day': previous_day,
      'previous_day_str': previous_day_str,
      'two_days_ago': two_days_ago,
      'two_days_ago_str': two_days_ago_str,
      'show_day_permalink': show_day_permalink,
      'infinite_scroll': infinite_scroll,
      'midpoint': midpoint,
      'new_post': new_post,
      'datetime': datetime
    })
    self.render('post/lists_posts.html', **self.vars)
Example #11
0
# Run by Heroku scheduler every night
# If running locally, uncomment below imports
import sys
sys.path.insert(0, '/Users/nick/dev/usv/usv.com')
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