Example #1
0
    def __init__(self, fake, gender=None, dob=None, city=None, filename=None):

        m = 'profiles/main_config.json'
        main = open(m, 'r').read()
        self.all_profiles = MainConfig(main).config
        self.cities = demographics.make_cities()
        new_cities = {}
        for i in list(self.cities.keys()):
            if self.cities[i].split('|')[0] == city and self.cities[i].split(
                    '|')[1] == 'CO':
                new_cities[i] = self.cities[i]
        if len(new_cities.keys()) > 0:
            self.cities = new_cities
        #age_gender = make_age_gender_dict()

        self.fake = fake
        self.ssn = fake.ssn()
        generated_gender, generated_dob = self.generate_age_gender()
        if gender is not None:
            self.gender = gender[0]
        else:
            self.gender = generated_gender
        #self.age = age
        if dob is not None:
            self.dob = self.convert_date(dob)
        else:
            self.dob = generated_dob
        self.first = self.get_first_name()
        self.last = fake.last_name()
        self.street = fake.street_address()
        self.addy = self.get_random_location()
        #make people under 22 mostly students, and over the age of 65 mostly retired
        if (date.today() - date(self.dob.year, self.dob.month, self.dob.day)
            ).days / 365. <= 22 and random.random() <= .8:
            self.job = 'Student'
        elif (date.today() - date(self.dob.year, self.dob.month, self.dob.day)
              ).days / 365. >= 65 and random.random() <= .8:
            self.job = 'Retired'
        else:
            self.job = fake.job()
        self.cc = fake.credit_card_number()
        self.email = fake.email()
        self.account = fake.random_number(digits=12)
        self.profile = self.find_profile()
        if filename is not None:
            self.save_to_file(filename)
	def pickle_profiles(self):
		# turn all profiles into dicts to work with
		main = [p for p in self.profiles if 'main_config.json' in p][0]
		main = open(main, 'r').read()

		# pickle the main_config.json
		main_config = MainConfig(main).config
		with open('./pickles/all_profiles.pickle', 'wb') as output:
		    pickle.dump(main_config, output, pickle.HIGHEST_PROTOCOL)

		# pickle the profiles
		individual_profiles = [p for p in self.profiles if 'main_config.json' not in p]
		for p, pro in [(p, open(p, 'r').read()) for p in individual_profiles]:
			profile = profile_weights_pickle.Profile(pro, self.start, self.end)
			# skip pickling the template
			if p.split('/')[-1].split('.')[0] == 'template':
				pass
			else:
				with open(p.replace('.json','.profile').\
							replace('/profiles/','/pickles/'), \
							'wb') as output:
				    pickle.dump(profile, output, pickle.HIGHEST_PROTOCOL)
Example #3
0
        print_err(3)
    try:
        m = sys.argv[4]
        ## m = 'profiles/main_config.json'
        main = open(m, 'r').read()

    except:
        print_err(4)

    return num_cust, seed_num, base_home, main


if __name__ == '__main__':
    # read and validate stdin
    num_cust, seed_num, base_home, main = validate()

    # from demographics module
    cities = demographics.make_cities(base_home)
    age_gender = demographics.make_age_gender_dict(base_home)

    fake = Faker()
    Faker.seed(seed_num)

    headers = Headers()

    # turn all profiles into dicts to work with
    all_profiles = MainConfig(main).config

    for _ in range(num_cust):
        Customer()