<commit_before>from __future__ import print_function, division, absolute_import

import os
import hashlib
import datetime
import time
import logging
import uuid
import hashlib
import hmac
import base64
import urlparse

import simplejson as json

#from redis import StrictRedis
import redis # used for collections
Redis = redis.StrictRedis()

from flask import (Flask, g, render_template, url_for, request, make_response,
                   redirect, flash, abort)

from wqflask import app
from pprint import pformat as pf

from wqflask import pbkdf2 # password hashing
from wqflask.database import db_session
from wqflask import model

from utility import Bunch, Struct, after

import logging
from utility.logger import getLogger
logger = getLogger(__name__)

from base.data_set import create_datasets_list

import requests
from utility.elasticsearch_tools import get_elasticsearch_connection, get_user_by_unique_column, get_item_by_unique_column, save_user, es_save_data

from smtplib import SMTP
from utility.tools import SMTP_CONNECT, SMTP_USERNAME, SMTP_PASSWORD, LOG_SQL_ALCHEMY

THREE_DAYS = 60 * 60 * 24 * 3
#THREE_DAYS = 45

def timestamp():
    return datetime.datetime.utcnow().isoformat()

class AnonUser(object):
    """Anonymous user handling"""
    cookie_name = 'anon_user_v1'

    def __init__(self):
        self.cookie = request.cookies.get(self.cookie_name)
        if self.cookie:
            logger.debug("ANON COOKIE ALREADY EXISTS")
            self.anon_id = verify_cookie(self.cookie)

        else:
            logger.debug("CREATING NEW ANON COOKIE")
            self.anon_id, self.cookie = create_signed_cookie()
            res = flask.make_response()
            res.set_cookie(self.cookie_name, self.cookie)
        self.key = "anon_collection:v1:{}".format(self.anon_id)

    def add_collection(self, new_collection):
        collection_dict = dict(name = new_collection.name,
                               created_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p'),
                               changed_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p'),
                               num_members = new_collection.num_members,
                               members = new_collection.get_members())

        Redis.set(self.key, json.dumps(collection_dict))
        Redis.expire(self.key, 60 * 60 * 24 * 5)

    def delete_collection(self, collection_name):
        existing_collections = self.get_collections()<commit_msg>Fixed minor issue in user_manager.py<commit_after>from __future__ import print_function, division, absolute_import

import os
import hashlib
import datetime
import time
import logging
import uuid
import hashlib
import hmac
import base64
import urlparse

import simplejson as json

#from redis import StrictRedis
import redis # used for collections
Redis = redis.StrictRedis()

from flask import (Flask, g, render_template, url_for, request, make_response,
                   redirect, flash, abort)

from wqflask import app
from pprint import pformat as pf

from wqflask import pbkdf2 # password hashing
from wqflask.database import db_session
from wqflask import model

from utility import Bunch, Struct, after

import logging
from utility.logger import getLogger
logger = getLogger(__name__)

from base.data_set import create_datasets_list

import requests
from utility.elasticsearch_tools import get_elasticsearch_connection, get_user_by_unique_column, get_item_by_unique_column, save_user, es_save_data

from smtplib import SMTP
from utility.tools import SMTP_CONNECT, SMTP_USERNAME, SMTP_PASSWORD, LOG_SQL_ALCHEMY

THREE_DAYS = 60 * 60 * 24 * 3
#THREE_DAYS = 45

def timestamp():
    return datetime.datetime.utcnow().isoformat()

class AnonUser(object):
    """Anonymous user handling"""
    cookie_name = 'anon_user_v1'

    def __init__(self):
        self.cookie = request.cookies.get(self.cookie_name)
        if self.cookie:
            logger.debug("ANON COOKIE ALREADY EXISTS")
            self.anon_id = verify_cookie(self.cookie)

        else:
            logger.debug("CREATING NEW ANON COOKIE")
            self.anon_id, self.cookie = create_signed_cookie()
            res = make_response()
            res.set_cookie(self.cookie_name, self.cookie)
        self.key = "anon_collection:v1:{}".format(self.anon_id)

    def add_collection(self, new_collection):
        collection_dict = dict(name = new_collection.name,
                               created_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p'),
                               changed_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p'),
                               num_members = new_collection.num_members,
                               members = new_collection.get_members())

        Redis.set(self.key, json.dumps(collection_dict))
        Redis.expire(self.key, 60 * 60 * 24 * 5)

    def delete_collection(self, collection_name):
        existing_collections = self.get_collections()
{'fraction_non_alphanumeric': 0.07998400319936012, 'fraction_numerical': 0.008398320335932814, 'mean_word_length': 3.2935622317596565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4129162', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1478, 'n_words': 387}