# Path: lib/mentionsdb.py
# def add_mention(screen_name, slug):
# def get_mentions_by_user(screen_name, per_page, page):
# 
# Path: lib/postsdb.py
# def get_post_by_slug(slug):
# def get_all():
# def get_posts_by_bumps(screen_name, per_page, page):
# def get_posts_by_query(query, per_page=10, page=1):
# def get_posts_by_tag(tag):
# def get_posts_by_screen_name(screen_name, per_page=10, page=1):
# def get_posts_by_screen_name_and_tag(screen_name, tag, per_page=10, page=1):
# def get_featured_posts(per_page=10, page=1):
# def get_new_posts(per_page=50, page=1):
# def get_hot_posts(per_page=50, page=1):
# def get_hot_posts_by_day(day=date.today(), hide_featured=False):
# def get_daily_posts_by_sort_score(min_score=8):
# def get_hot_posts_24hr(start=datetime.now()):
# def get_sad_posts(per_page=50, page=1):
# def get_deleted_posts(per_page=50, page=1):
# def get_unique_posters(start_date, end_date):
# def get_featured_posts_count():
# def get_post_count_by_query(query):
# def get_post_count():
# def get_post_count_for_range(start_date, end_date):
# def get_delete_posts_count():
# def get_post_count_by_tag(tag):
# def get_latest_staff_posts_by_tag(tag, limit=10):
# def get_posts_by_normalized_url(normalized_url, limit):
# def get_posts_with_min_votes(min_votes):
# def get_hot_posts_past_week():
# def get_related_posts_by_tag(tag):
# def add_subscriber_to_post(slug, email):
# def remove_subscriber_from_post(slug, email):
# def save_post(post):
# def update_post_score(slug, score, scores):
# def delete_all_posts_by_user(screen_name):
# def insert_post(post):
# def sort_posts(day="all"):
# 
# Path: lib/tagsdb.py
# def get_user_tags(screen_name):
# def get_all_tags(sort=None):
# def get_hot_tags():
# def get_user_tags(screen_name):
# def save_tag(tag):
# 
# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():
# 
# Path: lib/template_helpers.py
# def tinymce_valid_elements_wrapper(media=True):
# def twitter_avatar_size(url, size):
# def pretty_date(d):
# def post_permalink(p):


import app.basic
import logging
import re
import settings
import tornado.web
import tornado.options
import urllib
import datetime
import time
from urlparse import urlparse
from lib import bitly
from lib import google
from lib import mentionsdb
from lib import postsdb
from lib import sanitize
from lib import tagsdb
from lib import userdb
from lib import disqus
from lib import template_helpers
        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")

        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_24hr(day)

# Path: lib/mentionsdb.py
# def add_mention(screen_name, slug):
# def get_mentions_by_user(screen_name, per_page, page):
# 
# Path: lib/postsdb.py
# def get_post_by_slug(slug):
# def get_all():
# def get_posts_by_bumps(screen_name, per_page, page):
# def get_posts_by_query(query, per_page=10, page=1):
# def get_posts_by_tag(tag):
# def get_posts_by_screen_name(screen_name, per_page=10, page=1):
# def get_posts_by_screen_name_and_tag(screen_name, tag, per_page=10, page=1):
# def get_featured_posts(per_page=10, page=1):
# def get_new_posts(per_page=50, page=1):
# def get_hot_posts(per_page=50, page=1):
# def get_hot_posts_by_day(day=date.today(), hide_featured=False):
# def get_daily_posts_by_sort_score(min_score=8):
# def get_hot_posts_24hr(start=datetime.now()):
# def get_sad_posts(per_page=50, page=1):
# def get_deleted_posts(per_page=50, page=1):
# def get_unique_posters(start_date, end_date):
# def get_featured_posts_count():
# def get_post_count_by_query(query):
# def get_post_count():
# def get_post_count_for_range(start_date, end_date):
# def get_delete_posts_count():
# def get_post_count_by_tag(tag):
# def get_latest_staff_posts_by_tag(tag, limit=10):
# def get_posts_by_normalized_url(normalized_url, limit):
# def get_posts_with_min_votes(min_votes):
# def get_hot_posts_past_week():
# def get_related_posts_by_tag(tag):
# def add_subscriber_to_post(slug, email):
# def remove_subscriber_from_post(slug, email):
# def save_post(post):
# def update_post_score(slug, score, scores):
# def delete_all_posts_by_user(screen_name):
# def insert_post(post):
# def sort_posts(day="all"):
# 
# Path: lib/tagsdb.py
# def get_user_tags(screen_name):
# def get_all_tags(sort=None):
# def get_hot_tags():
# def get_user_tags(screen_name):
# def save_tag(tag):
# 
# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():
# 
# Path: lib/template_helpers.py
# def tinymce_valid_elements_wrapper(media=True):
# def twitter_avatar_size(url, size):
# def pretty_date(d):
# def post_permalink(p):


# Path: app/posts.py
import app.basic
import logging
import re
import settings
import tornado.web
import tornado.options
import urllib
import datetime
import time
from urlparse import urlparse
from lib import bitly
from lib import google
from lib import mentionsdb
from lib import postsdb
from lib import sanitize
from lib import tagsdb
from lib import userdb
from lib import disqus
from lib import template_helpers

        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")

        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_24hr(day)

        previous_day_posts = postsdb.get_hot_posts_24hr(datetime.datetime.now() - datetime.timedelta(hours=24))