# 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/emailsdb.py
# def construct_daily_email(slugs):
# def setup_email_list():
# def add_list_to_email():
# def send_email():
# def log_daily_email(email, recipient_usernames):
# def get_daily_email_log():
# def do_api_request(api_link, method='GET', params={}):


import sys
import settings
import requests
import logging
import csv
from datetime import datetime
from lib import postsdb, emailsdb
# Run by Heroku scheduler every night
# If running locally, uncomment below imports
sys.path.insert(0, '/Users/nick/dev/usv/usv.com')


# 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":

# 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/emailsdb.py
# def construct_daily_email(slugs):
# def setup_email_list():
# def add_list_to_email():
# def send_email():
# def log_daily_email(email, recipient_usernames):
# def get_daily_email_log():
# def do_api_request(api_link, method='GET', params={}):


# Path: scripts/daily_newsletter.py
import sys
import settings
import requests
import logging
import csv
from datetime import datetime
from lib import postsdb, emailsdb

# Run by Heroku scheduler every night
# If running locally, uncomment below imports
sys.path.insert(0, '/Users/nick/dev/usv/usv.com')


# 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()