<s> import logging <EOL> import random <EOL> from datetime import datetime <EOL> import click <EOL> from faker import Faker <EOL> SEED_ADMIN_EMAIL = None <EOL> ACCEPT_LANGUAGES = None <EOL> try : <EOL> from instance import settings <EOL> SEED_ADMIN_EMAIL = settings . SEED_ADMIN_EMAIL <EOL> ACCEPT_LANGUAGES = settings . ACCEPT_LANGUAGES <EOL> except ImportError : <EOL> logging . error ( '<STR_LIT>' ) <EOL> exit ( <NUM_LIT:1> ) <EOL> except AttributeError : <EOL> from config import settings <EOL> if SEED_ADMIN_EMAIL is None : <EOL> SEED_ADMIN_EMAIL = settings . SEED_ADMIN_EMAIL <EOL> if ACCEPT_LANGUAGES is None : <EOL> ACCEPT_LANGUAGES = settings . ACCEPT_LANGUAGES <EOL> from catwatch . app import create_app <EOL> from catwatch . extensions import db <EOL> from catwatch . blueprints . issue . models import Issue <EOL> from catwatch . blueprints . user . models import User <EOL> from catwatch . blueprints . billing . models . invoice import Invoice <EOL> from catwatch . blueprints . billing . models . coupon import Coupon <EOL> from catwatch . blueprints . billing . gateways . stripecom import Coupon as PaymentCoupon <EOL> fake = Faker ( ) <EOL> app = create_app ( ) <EOL> db . app = app <EOL> def _log_status ( count , model_label ) : <EOL> """<STR_LIT>""" <EOL> click . echo ( '<STR_LIT>' . format ( count , model_label ) ) <EOL> return None <EOL> def _bulk_insert ( model , data , label ) : <EOL> """<STR_LIT>""" <EOL> with app . app_context ( ) : <EOL> model . query . delete ( ) <EOL> db . session . commit ( ) <EOL> db . engine . execute ( model . __table__ . insert ( ) , data ) <EOL> _log_status ( model . query . count ( ) , label ) <EOL> return None <EOL> @ click . group ( ) <EOL> def cli ( ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ click . command ( ) <EOL> def users ( ) : <EOL> """<STR_LIT>""" <EOL> random_emails = [ ] <EOL> data = [ ] <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> random_emails . append ( fake . email ( ) ) <EOL> random_emails . append ( SEED_ADMIN_EMAIL ) <EOL> random_emails = list ( set ( random_emails ) ) <EOL> while True : <EOL> if len ( random_emails ) == <NUM_LIT:0> : <EOL> break <EOL> email = random_emails . pop ( ) <EOL> params = { <EOL> '<STR_LIT>' : random . choice ( User . ROLE . keys ( ) ) , <EOL> '<STR_LIT:email>' : email , <EOL> '<STR_LIT:password>' : User . encrypt_password ( '<STR_LIT:password>' ) , <EOL> '<STR_LIT:name>' : fake . name ( ) , <EOL> '<STR_LIT>' : random . choice ( ACCEPT_LANGUAGES ) <EOL> } <EOL> if email == SEED_ADMIN_EMAIL : <EOL> params [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> params [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> data . append ( params ) <EOL> return _bulk_insert ( User , data , '<STR_LIT>' ) <EOL> @ click . command ( ) <EOL> def issues ( ) : <EOL> """<STR_LIT>""" <EOL> data = [ ] <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:50> ) : <EOL> params = { <EOL> '<STR_LIT:status>' : random . choice ( Issue . STATUS . keys ( ) ) , <EOL> '<STR_LIT:label>' : random . choice ( Issue . LABEL . keys ( ) ) , <EOL> '<STR_LIT:email>' : fake . email ( ) , <EOL> '<STR_LIT>' : fake . paragraph ( ) <EOL> } <EOL> data . append ( params ) <EOL> return _bulk_insert ( Issue , data , '<STR_LIT>' ) <EOL> @ click . command ( ) <EOL> def coupons ( ) : <EOL> """<STR_LIT>""" <EOL> data = [ ] <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:5> ) : <EOL> random_pct = random . random ( ) <EOL> duration = random . choice ( Coupon . DURATION . keys ( ) ) <EOL> redeem_by = fake . date_time_between ( start_date = '<STR_LIT>' , <EOL> end_date = '<STR_LIT>' ) . strftime ( '<STR_LIT:%s>' ) <EOL> params = { <EOL> '<STR_LIT:code>' : Coupon . random_coupon_code ( ) , <EOL> '<STR_LIT>' : duration , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> if random_pct >= <NUM_LIT:0.5> : <EOL> params [ '<STR_LIT>' ] = random . randint ( <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> params [ '<STR_LIT>' ] = random . randint ( <NUM_LIT:15> , <NUM_LIT:50> ) <EOL> else : <EOL> params [ '<STR_LIT>' ] = random . randint ( <NUM_LIT:1> , <NUM_LIT> ) <EOL> params [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if random_pct >= <NUM_LIT> : <EOL> params [ '<STR_LIT>' ] = redeem_by <EOL> if duration == '<STR_LIT>' : <EOL> duration_in_months = random . randint ( <NUM_LIT:1> , <NUM_LIT:12> ) <EOL> params [ '<STR_LIT>' ] = duration_in_months <EOL> PaymentCoupon . create ( ** params ) <EOL> if redeem_by : <EOL> params [ '<STR_LIT>' ] = datetime . utcfromtimestamp ( float ( redeem_by ) ) . strftime ( '<STR_LIT>' ) <EOL> if '<STR_LIT:id>' in params : <EOL> params [ '<STR_LIT:code>' ] = params . get ( '<STR_LIT:id>' ) <EOL> del params [ '<STR_LIT:id>' ] <EOL> data . append ( params ) <EOL> return _bulk_insert ( Coupon , data , '<STR_LIT>' ) <EOL> @ click . command ( ) <EOL> def invoices ( ) : <EOL> """<STR_LIT>""" <EOL> data = [ ] <EOL> users = db . session . query ( User ) . all ( ) <EOL> for user in users : <EOL> for i in range ( <NUM_LIT:0> , random . randint ( <NUM_LIT:1> , <NUM_LIT:12> ) ) : <EOL> created_on = fake . date_time_between ( <EOL> start_date = '<STR_LIT>' , end_date = '<STR_LIT>' ) . strftime ( '<STR_LIT:%s>' ) <EOL> period_start_on = fake . date_time_between ( <EOL> start_date = '<STR_LIT>' , end_date = '<STR_LIT>' ) . strftime ( '<STR_LIT:%s>' ) <EOL> period_end_on = fake . date_time_between ( <EOL> start_date = period_start_on , end_date = '<STR_LIT>' ) . strftime ( '<STR_LIT:%s>' ) <EOL> exp_date = fake . date_time_between ( <EOL> start_date = '<STR_LIT>' , end_date = '<STR_LIT>' ) . strftime ( '<STR_LIT:%s>' ) <EOL> created_on = datetime . utcfromtimestamp ( <EOL> float ( created_on ) ) . strftime ( '<STR_LIT>' ) <EOL> period_start_on = datetime . utcfromtimestamp ( <EOL> float ( period_start_on ) ) . strftime ( '<STR_LIT>' ) <EOL> period_end_on = datetime . utcfromtimestamp ( <EOL> float ( period_end_on ) ) . strftime ( '<STR_LIT>' ) <EOL> exp_date = datetime . utcfromtimestamp ( <EOL> float ( exp_date ) ) . strftime ( '<STR_LIT>' ) <EOL> plans = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> cards = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , "<STR_LIT>" ] <EOL> params = { <EOL> '<STR_LIT>' : created_on , <EOL> '<STR_LIT>' : created_on , <EOL> '<STR_LIT>' : user . id , <EOL> '<STR_LIT>' : fake . md5 ( ) , <EOL> '<STR_LIT:description>' : '<STR_LIT>' . format ( random . choice ( plans ) ) , <EOL> '<STR_LIT>' : period_start_on , <EOL> '<STR_LIT>' : period_end_on , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : random . random ( ) * <NUM_LIT:100> , <EOL> '<STR_LIT>' : random . random ( ) * <NUM_LIT:10> , <EOL> '<STR_LIT>' : random . random ( ) * <NUM_LIT:1000> , <EOL> '<STR_LIT>' : random . choice ( cards ) , <EOL> '<STR_LIT>' : random . randint ( <NUM_LIT:1000> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : exp_date <EOL> } <EOL> data . append ( params ) <EOL> return _bulk_insert ( Invoice , data , '<STR_LIT>' ) <EOL> @ click . command ( ) <EOL> @ click . pass_context <EOL> def all ( ctx ) : <EOL> """<STR_LIT>""" <EOL> ctx . invoke ( users ) <EOL> ctx . invoke ( issues ) <EOL> ctx . invoke ( coupons ) <EOL> ctx . invoke ( invoices ) <EOL> return None <EOL> cli . add_command ( users ) <EOL> cli . add_command ( issues ) <EOL> cli . add_command ( coupons ) <EOL> cli . add_command ( invoices ) <EOL> cli . add_command ( all ) </s>
