# -*- coding: utf-8 -*- #!/usr/bin/env python import os import sys import random #: current_dir - 2 from apps.web.agent.define import AGENT_INCOME_SOURCE PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..') sys.path.insert(0, PROJECT_ROOT) import faker from script.base import init_env, get_logger logger = get_logger(__name__) init_env(interactive=True) from apps.web.constant import Const fake = faker.Faker() def simulate(): for _ in xrange(300): random_date_time = fake.date_time_between(start_date='-100d') random_date_time_str = random_date_time.strftime(Const.DATE_FMT) detail_map = { 'ad': {'adId': random.choice(['10001', '10002']), 'logicalCode': '10000', 'dealer': 'robert'}, 'dealer_withdraw_fee': {'name': random.choice(['whoami', 'quick']), 'withdraw': 100}, 'dealer_card_fee': {'name': 'whothedealer'} } random_source = random.choice([_.lower() for _ in dir(AGENT_INCOME_SOURCE) if not _.startswith('_')]) test_payload = { 'agentId': '6417d4456f29257125ebf705', 'date': random_date_time_str, 'detail': detail_map[random_source], 'amount' : random.choice([10.6, 5.5, 3]), 'source' : random_source, 'dateTimeAdded': random_date_time } print 'inserting...', test_payload # record_agent_income(, print 'finished' if __name__ == '__main__': simulate()