<s> """<STR_LIT>""" <EOL> import datetime <EOL> import collections <EOL> from cStringIO import StringIO <EOL> from framework . mongo import database <EOL> from website import models <EOL> from website . app import app , init_app <EOL> from scripts . analytics import utils <EOL> from scripts . analytics import settings <EOL> def get_emails ( query = None ) : <EOL> users = database [ '<STR_LIT:user>' ] . find ( query , { '<STR_LIT:username>' : True } ) <EOL> counts = collections . Counter ( <EOL> user [ '<STR_LIT:username>' ] . split ( '<STR_LIT:@>' ) [ - <NUM_LIT:1> ] <EOL> for user in users <EOL> ) <EOL> return counts . most_common ( ) <EOL> def get_emails_since ( delta ) : <EOL> return get_emails ( { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:password>' : { '<STR_LIT>' : None } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : datetime . datetime . utcnow ( ) - delta } , <EOL> } ) <EOL> def main ( ) : <EOL> node = models . Node . load ( settings . TABULATE_EMAILS_NODE_ID ) <EOL> user = models . User . load ( settings . TABULATE_EMAILS_USER_ID ) <EOL> emails = get_emails_since ( settings . TABULATE_EMAILS_TIME_DELTA ) <EOL> sio = StringIO ( ) <EOL> utils . make_csv ( sio , emails , [ '<STR_LIT>' , '<STR_LIT:count>' ] ) <EOL> utils . send_file ( settings . TABULATE_EMAILS_FILE_NAME , settings . TABULATE_EMAILS_CONTENT_TYPE , sio , node , user ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> init_app ( ) <EOL> main ( ) </s>
