<commit_before>from totalimpactwebapp.user import User
from totalimpactwebapp import db
import datetime

# from tasks import update_from_linked_account


"""
requires these env vars be set in this environment:
DATABASE_URL
"""

# TBD
# should this be in webapp library?  if not, implications for logging
# should we have a library for these scripts, somewhere to put page_query?

def page_query(q):
    offset = 0
    while True:
        r = False
        for elem in q.limit(100).offset(offset):
           r = True
           yield elem
        offset += 100
        if not r:
            break


def deduplicate_by_url_slug(url_slug, webapp_api_endpoint):
    url = webapp_api_endpoint + u"/user/{url_slug}/products?action=deduplicate&source=scheduled".format(
        url_slug=url_slug)
    try:
        logger.debug(u"DEDUP POST to {url}".format(
            url=url))
    except UnicodeEncodeError:
        logger.debug(u"UnicodeEncodeError when trying to print url")
    r = requests.post(url)
    return r  

def put_linked_account_users_on_queue():

    i = 0
    # now = datetime.datetime.utcnow().isoformat()
    now = "2015-06-24"
    # for user in page_query(User.query.filter(User.next_refresh < now).order_by(User.next_refresh.asc())):

    # for user in page_query(User.query):
    for user in page_query(User.query.filter(User.next_refresh <= now)):
        tiids = deduplicate_by_url_slug("https://impactstory.org", user.url_slug)
        # linked_accounts_to_sync = {
        #     "figshare": user.figshare_id, <commit_msg>work around logging<commit_after>from totalimpactwebapp.user import User
from totalimpactwebapp import db
import datetime

# from tasks import update_from_linked_account


"""
requires these env vars be set in this environment:
DATABASE_URL
"""

# TBD
# should this be in webapp library?  if not, implications for logging
# should we have a library for these scripts, somewhere to put page_query?

def page_query(q):
    offset = 0
    while True:
        r = False
        for elem in q.limit(100).offset(offset):
           r = True
           yield elem
        offset += 100
        if not r:
            break


def deduplicate_by_url_slug(url_slug, webapp_api_endpoint):
    url = webapp_api_endpoint + u"/user/{url_slug}/products?action=deduplicate&source=scheduled".format(
        url_slug=url_slug)
    try:
        print(u"DEDUP POST to {url}".format(
            url=url))
    except UnicodeEncodeError:
        print(u"UnicodeEncodeError when trying to print url")
    r = requests.post(url)
    return r  

def put_linked_account_users_on_queue():

    i = 0
    # now = datetime.datetime.utcnow().isoformat()
    now = "2015-06-24"
    # for user in page_query(User.query.filter(User.next_refresh < now).order_by(User.next_refresh.asc())):

    # for user in page_query(User.query):
    for user in page_query(User.query.filter(User.next_refresh <= now)):
        tiids = deduplicate_by_url_slug("https://impactstory.org", user.url_slug)
        print tiids
        # linked_accounts_to_sync = {
        #     "figshare": user.figshare_id, 
{'fraction_non_alphanumeric': 0.09554551323434474, 'fraction_numerical': 0.010329244673983214, 'mean_word_length': 3.0722733245729303, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3411587', 'n_tokens_mistral': 1005, 'n_tokens_neox': 972, 'n_words': 250}