def flights(): return [ models.Flight.objects.create( name=f"Flight_{i}", number=Random().custom_code(mask="@@ ####"), departure=Address().city(), destination=Address().city(), scheduled_at=Datetime().datetime(), expected_at=Datetime().datetime(), duration=Numbers().integer_number(start=1, end=100), fare=Numbers().float_number(start=1, end=10000, precision=2), ) for i in range(10) ]
def createPlayers(team): person = Person("en") adress = Address("en") players = [] MAX_N = len(team) arrOfIds = [i + 1 for i in range(MAX_N)] for i in range(MAX_N): positions = [1, 2, 3, 4, 5] numbers = [k for k in range(1, 99, 1)] curTeamID = choice(arrOfIds) arrOfIds.remove(curTeamID) for _ in range(len(positions)): curID = str(len(players) + 1) teamID = str(curTeamID) name = person.full_name() position = choice(positions) height = str(randint(150, 220)) weight = str(person.weight()) number = str(choice(numbers)) age = str(person.age()) country = adress.country(allow_random=True) positions.remove(position) numbers.remove(int(number)) players.append([curID, teamID, name, position, height, weight, number, age, country]) f = open("Players.csv", "w", encoding='utf-8') for player in players: line = str(player[0]) + ',' + str(player[1]) + ',' + str(player[2]) + ',' +\ str(player[3]) + ',' + str(player[4]) + ',' + str(player[5]) + ',' +\ str(player[6]) + ',' + str(player[7]) + ',' + str(player[8]) + '\n' f.write(line) f.close()
def update_db_with_new_entries(count, database): # add 6 * count of lon and lat to the database input_list = [] a = Address() basic_lon, basic_lat = a.coordinates().values() for i in range(count): person = Person('uk') lon1 = basic_lon + 40 * cos(i) lat1 = basic_lat + 40 * sin(i) input_list.append( database( username=person.full_name(), division_order=1, lon1=lon1, lat1=lat1, lon2=lon1 + 1, lat2=lat1 + 2, lon3=lon1 + 3, lat3=lat1 + 2, lon4=lon1 + 4, lat4=lat1 + 0, lon5=lon1 + 3, lat5=lat1 - 2, lon6=lon1 + 1, lat6=lat1 - 2, )) db.session.add_all(input_list) db.session.commit()
class Client(Node): _person = Person() _adresss = Address() def __init__(self): self.__type = 'Client' self.id = uuid4() self.first_name = self._person.name() self.last_name = self._person.surname() self.age = self._person.age() self.email = self._person.email() self.occupation = self._person.occupation() self.political_views = self._person.political_views() self.nationality = self._person.nationality() self.university = self._person.university() if random() < 0.15: self.academic_degree = self._person.academic_degree() else: self.academic_degree = None self.address = self._adresss.address() self.postal_code = self._adresss.postal_code() self.country = self._adresss.country() self.city = self._adresss.city()
def address(locale): """ :param locale: :return: """ return Address(locale)
def address(cls, *, locale=Locales.EN, calling_code=None, city=None, country=None, country_code=None, latitude=None, longitude=None, postal_code=None, state=None, street_name=None, street_number=None, street_suffix=None): ''' Create an Address Data Entity object. All individual fields are automatically randomly generated based on locale. If provided, the corresponding values are overriden. Note: All individual fields are randomly generated. Don't expect correct correlation e.g. correct postal code for the generated city. Keyword Arguments: locale: Approprite Random.locale.<local_name> object. Default is Random.locale.EN calling_code: Calling Code city: City country: Country Name country_code: Country Code latitude: Latitude longitude: Longitde postal_code: Postal Code state: State street_name: Street Name street_number Street Number street_suffix: Street Suffix ''' address = Address(locale=locale) from arjuna.engine.data.entity.address import Address as ArjAddress return ArjAddress( calling_code=calling_code is not None and calling_code or address.calling_code(), city=city and city is not None or address.city(), country=country is not None and country or address.country(), country_code=country_code is not None and country_code or address.country_code(), latitude=latitude is not None and latitude or address.latitude(), longitude=longitude is not None and longitude or address.longitude(), postal_code=postal_code is not None and postal_code or address.postal_code(), state=state is not None and state or address.state(), street_name=street_name is not None and street_name or address.street_name(), street_number=street_number is not None and street_number or address.street_number(), street_suffix=street_suffix is not None and street_suffix or address.street_suffix(), )
def main(): cursor, co = db_connection('fee_test', 'postgres', 'password', host='localhost') sql_quaries(create_table_customer, cursor) sql_quaries(create_table_branch, cursor) # print(create_table_branch) for i in range(1, 21): b = Business().company() sql_insert(INSERT.format(b, b), cursor) co.commit() for i in range(100): a = Address('en').address() + " " + Address( 'en').zip_code() + " " + Address('en').state() sql_insert(INSERT_ADDRESS.format(a, random.randint(1, 20)), cursor) co.commit()
class ATM(Node): _address = Address() def __init__(self): self.__type = 'ATM' self.id = uuid4() self.latitude = self._address.latitude() self.longitude = self._address.longitude()
def get_fake_address(self, loc): address = Address(loc) city = address.city() kind_street = address.street_suffix() street = address.street_name() house = address.street_number() area = address.state() zip = address.zip_code() country = address.country() return zip, city, kind_street, street, house, area, country
class Company(Node): _business = Business() _address = Address() def __init__(self): self.__type = 'Company' self.id = uuid4() self.type = self._business.company_type() self.name = self._business.company() self.country = self._address.country()
def country(cls, *, locale=Locales.EN): ''' Generate a country name Keyword Arguments: locale: (Optional) locale for generating country name Returns: A generated country name ''' return Address(locale).country()
def postal_code(cls, *, locale=Locales.EN): ''' Generate a postal code Keyword Arguments: locale: (Optional) locale for generating postal code Returns: A generated postal code ''' return Address(locale).postal_code()
def street_number(cls, *, locale=Locales.EN): ''' Generate a street number Keyword Arguments: locale: (Optional) locale for generating street number Returns: A generated street number ''' return Address(locale).street_number()
def __init__(self): self.person = Person(locale='zh') self.address = Address(locale='zh') self.code = Code() self.business = Business(locale='zh') self.text = Text(locale='zh') self.datetime = Datetime(locale='zh') self.file = File() self.path = Path() self.internet = Internet() self.structure = Structure()
def create_person(): from mimesis import Person as MimesisPerson, locales, Address person = MimesisPerson(locales.RU) address = Address(locales.RU) with transaction.atomic(): first_name = person.name() last_name = person.surname() gender = person.gender() if gender == 'Муж.': patronymic = choice([ 'Сергеевич', 'Николаевич', 'Артурович', 'Константинович', 'Игоревич' ]) else: patronymic = choice([ 'Александровна', 'Борисовна', 'Петровна', 'Юрьевна', 'Анатольевна' ]) birth_date = generate_birthdate() address = '{}, {}'.format(address.federal_subject(), address.address()) passport_series = randint(1000, 7000) passport_number = randint(100000, 999999) pair = generate_RSA_pair() signature_public_key = pair[1] load_key_to_file( '../../../person_signature_private_keys/{}_{}_{}_{}.pem'.format( passport_series, passport_number, last_name, first_name), pair[0]) person_info = '{} {} {} {} {} {} {} {}'.format( first_name, last_name, patronymic, birth_date, address, passport_series, passport_number, signature_public_key) signature_i = sign_person_info(person_info) Person(first_name=first_name, last_name=last_name, patronymic=patronymic, birth_date=birth_date, address=address, passport_series=passport_series, passport_number=passport_number, signature_public_key=signature_public_key, signature_i=signature_i).save()
def generate_addresses(): address = Address('en-gb') city = address.city() country = address.country() postal_code = address.postal_code() street_name = address.street_name() street_number = address.street_number() return { 'id': id, "street_number": street_number, "street_name": street_name, "city": city, "postal_code": postal_code, "country": country }
class TestUser: person = Person() address = Address() text = Text() username = person.username() first_name = person.first_name() last_name = person.last_name() email = person.email() fake_address = address.address() password = person.password() website = "www.xxxxxxxx.com" phone_number = person.telephone() message = text.sentence()
class BaseGenerator(object): person = Person('en') text = Text('en') generic = Generic('en') address = Address('en') data = set() def get_primary_key_data(self, num): raise NotImplementedError("Необходимо переопределить метод") def get_params(self): raise NotImplementedError("Необходимо переопределить метод") def clear_data(self): if len(self.data) != 0: self.data.clear()
def generate_random_data(): p = Person() a = Address() return { "name": p.full_name(), "email": p.email(), "nationality": p.nationality(), "occupation": p.occupation(), "password": p.password(), "phone": p.telephone(), "address": a.address(), "city": a.city(), "street_no": a.street_number(), "created": Datetime().date().isoformat(), }
def generate_fake_persons(size): """ This function generates a list of dummy persons (email, username, fullname, DOB, address and ssn) """ person = Personal('en') datetime = Datetime() address = Address('en') usa_provider = USASpecProvider() fake_persons = [] for _ in range(0, size): fake_person = (person.email(), person.username(), \ person.full_name(), datetime.date(1970, 2000), \ address.address() + " - " + address.state(), usa_provider.ssn()) fake_persons.append(fake_person) return fake_persons
def generatingData(num, locale, country): person = Person(locale) address = Address(locale) buffer = io.StringIO() writer = csv.writer(buffer, delimiter=';', lineterminator="\n", quoting=csv.QUOTE_NONE, escapechar='\\') for i in range(int(num)): writer.writerow([ person.full_name(), country if randint(0, 1) == 1 else address.country(), ', '.join([address.province(), address.city(), address.address()]), person.telephone() ]) return buffer.getvalue()
def generate(): inserts = [] counter = 350 business = Business('en') address = Address('en') internet = Internet('en') for index in range(counter, 15000, 1): inserts.append( template.substitute(id=index, name=business.company().replace("'", "''"), address=address.address().replace("'", "''"), credit=random.randint(300, 1000000), website=internet.home_page().replace( "'", "''"))) inserts_file = open('result_scripts/customers.sql', 'w', encoding='utf-8') inserts_file.writelines('\n'.join(inserts)) inserts_file.close()
def generate(): inserts = [] counter = 330 person = Person('en') business = Business('en') address = Address('en') internet = Internet('en') for index in range(counter, 15000, 1): inserts.append(template.substitute(id=index, name=person.name().replace("'", "''"), surname=person.surname().replace("'", "''"), email=person.email().replace("'", "''"), phone=person.telephone(), customer_id=random.randint(330, 14999) )) inserts_file = open('result_scripts/contacts.sql', 'w', encoding='utf-8') inserts_file.writelines('\n'.join(inserts)) inserts_file.close()
def generatePeople(row_num: int, region: str): if region == 'en_US': locale = 'en' elif region == 'ru_RU': locale = 'ru' else: locale = 'uk' writer = csv.writer(stdout, quoting=csv.QUOTE_NONE, delimiter=';', escapechar='"') person = Person(locale) address = Address(locale) for i in range(row_num): writer.writerow([ person.full_name(), address.country(), address.region(), address.city(), address.address(), address.zip_code(), person.telephone() ])
from models import * from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import random from mimesis import Person from mimesis import Address from mimesis import Datetime from mimesis.enums import Gender dateTime = Datetime('ru') address = Address('ru') person = Person('ru') count_org = 1 count_bran = 3 count_dep = 10 count_peop = 150 positions = [ 'position0', 'position1', 'position2', 'position3', 'position4', 'position5' ] gender = [Gender.MALE, Gender.FEMALE] def gen_number(): result = str(random.randrange(100, 999)) + '-' + str( random.randrange(10, 99)) + '-' + str(random.randrange(10, 99)) return result
# todo: need to add hook with preset data if # in rules.json exists generators based on data from 'data' folder data_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") class DataObject: pass languages = ["zh", "ru", "en", "es", "ar", "fr"] fake = Generic() text = Text() person = Person() date = Datetime() address = Address() def current_time(): tz = pytz.timezone(config.cfg.timezone) return datetime.datetime.now(tz) last_time = None countries = DataObject() def countries_init(): """ method to read countries and load data for generator :return:
def _address(): return Address()
def getting_started_example(): generic = Generic() #generic = Generic(locales.EN) print('Month =', generic.datetime.month()) print('Datetime =', generic.datetime.datetime(start=1900, end=2035, timezone=None)) # Type: datetime.datetime. print('IMEI =', generic.code.imei()) print('Fruit =', generic.food.fruit()) print('RNA =', generic.science.rna_sequence()) print('Word =', generic.text.word()) with generic.text.override_locale(locales.FR): print('Word =', generic.text.word()) print('Word =', generic.text.word()) generic = Generic('en') generic.add_provider(USASpecProvider) print('SSN =', generic.usa_provider.ssn()) #print('CPF =', generic.usa_provider.cpf()) # AttributeError: 'USASpecProvider' object has no attribute 'cpf'. generic = Generic('pt-br') #generic = Generic(locales.PT_BR) generic.add_provider(BrazilSpecProvider) #print('SSN =', generic.brazil_provider.ssn()) # AttributeError: 'BrazilSpecProvider' object has no attribute 'ssn'. print('CPF =', generic.brazil_provider.cpf()) #-------------------- numbers = Numbers() print('Numbers =', numbers.between()) # Type: int. print('Numbers =', numbers.between(10, 10000000000000000)) # Type: int. #-------------------- person = Person(locales.KO) print('Full name =', person.full_name(gender=Gender.FEMALE)) print('Full name =', person.full_name(gender=Gender.MALE, reverse=True)) with person.override_locale(locales.RU): print('Full name =', person.full_name()) print('Full name =', person.full_name()) print('Telephone =', person.telephone()) print('Telephone =', person.telephone(mask='(###)-###-####')) print('Identifier =', person.identifier()) print('Identifier =', person.identifier(mask='######-#######')) #-------------------- de = Address('de') ru = Address('ru') print('Region =', de.region()) print('Federal subject =', ru.federal_subject()) print('Address =', de.address()) print('Address =', ru.address()) ko = Address('ko') print('Address =', ko.province(), ko.city(), ko.address()) print('Zip code =', ko.zip_code()) #-------------------- business = Business('ko') #print('Price =', business.price(minimum=1.0, maximum=1000000000.0)) # Type: str. #print('Price =', business.price(minimum=1.0, maximum=1000000000.0)[:-2]) # Type: str. print('Price =', business.price(minimum=1.0, maximum=1000000000.0)[:-5]) # Type: str. #-------------------- payment = Payment() print('Credit card =', payment.credit_card_number(card_type=None)) # Type: str.
def ii_push_record(self, in_record: object) -> bool: """ Responsible for pushing records out. Called when an input record is being sent to the plugin. :param in_record: The data for the incoming record. :return: False if there's a downstream error, or if there's an error with the field name, otherwise True. """ if not self.parent.is_initialized: return False #create the new fields record_value = None for field in enumerate(self.record_info_out): if field[1].name == 'address_full_address': mimesis_object = Address(self.parent.Locale) record_value = mimesis_object.address() if field[1].name == 'address_coordinates': mimesis_object = Address(self.parent.Locale) record_value = str(mimesis_object.coordinates()) if field[1].name == 'address_country': mimesis_object = Address(self.parent.Locale) record_value = mimesis_object.country() if field[1].name == 'address_postal_code': mimesis_object = Address(self.parent.Locale) record_value = mimesis_object.postal_code() if field[1].name == 'code_imei': mimesis_object = Code(self.parent.Locale) record_value = mimesis_object.imei() if field[1].name == 'code_isbn': mimesis_object = Code(self.parent.Locale) record_value = mimesis_object.isbn() if field[1].name == 'code_pin': mimesis_object = Code(self.parent.Locale) record_value = mimesis_object.pin() if field[1].name == 'food_dish': mimesis_object = Food(self.parent.Locale) record_value = mimesis_object.dish() if field[1].name == 'food_fruit': mimesis_object = Food(self.parent.Locale) record_value = mimesis_object.fruit() if field[1].name == 'food_vegetables': mimesis_object = Food(self.parent.Locale) record_value = mimesis_object.vegetable() '''if field[1].name == 'game_gaming_platform': mimesis_object = Games(self.parent.Locale) record_value = mimesis_object.gaming_platform() if field[1].name == 'game_titles': mimesis_object = Games(self.parent.Locale) record_value = mimesis_object.game()''' if field[1].name == 'person_blood_type': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.blood_type() if field[1].name == 'person_email': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.email() if field[1].name == 'person_full_name': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.full_name() if field[1].name == 'person_nationality': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.nationality() if field[1].name == 'person_occupation': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.occupation() if field[1].name == 'person_telephone': mimesis_object = Person(self.parent.Locale) record_value = mimesis_object.telephone() if field[1].name == 'science_atomic_number': mimesis_object = Science(self.parent.Locale) record_value = str(mimesis_object.atomic_number()) if field[1].name == 'science_chemical_element': mimesis_object = Science(self.parent.Locale) record_value = mimesis_object.chemical_element() if field[1].name == 'transport_airplane': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.airplane() if field[1].name == 'transport_car': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.car() if field[1].name == 'transport_truck': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.truck() if field[1].name == 'transport_vehicle_reg_code': mimesis_object = Transport(self.parent.Locale) record_value = mimesis_object.vehicle_registration_code() #pdb.set_trace() self.record_info_out[field[0]].set_from_string(self.record_creator, record_value) out_record = self.record_creator.finalize_record() #self.parent.output_anchor.push_record(out_record, False) self.record_creator.reset() # Copy the data from the incoming record into the outgoing record. self.record_creator.reset() self.record_copier.done_adding() self.record_copier.copy(self.record_creator, in_record) # Push the record downstream and quit if there's a downstream error. if not self.parent.output_anchor.push_record(out_record): return False return True
def pi_push_all_records(self, n_record_limit: int) -> bool: """ Called when a tool has no incoming data connection. :param n_record_limit: Set it to <0 for no limit, 0 for no records, and >0 to specify the number of records. :return: True for success, False for failure. """ if not self.is_initialized: return False # Save a reference to the RecordInfo passed into this function in the global namespace, so we can access it later. record_info_out = Sdk.RecordInfo(self.alteryx_engine) # Adds the new field to the record. for field in self.column_name: self.output_field = record_info_out.add_field(field, self.output_type, size=self.field_size) # Lets the downstream tools know what the outgoing record metadata will look like, based on record_info_out. self.output_anchor.init(record_info_out) # Creating a new, empty record creator based on record_info_out's record layout. record_creator = record_info_out.construct_record_creator() #import pdb; pdb.set_trace() #sophs code: for record in range(self.record_limit): for field in enumerate(record_info_out): if field[1].name == 'address_full_address': mimesis_object = Address(self.Locale) record_value = mimesis_object.address() if field[1].name == 'address_coordinates': mimesis_object = Address(self.Locale) record_value = str(mimesis_object.coordinates()) if field[1].name == 'address_country': mimesis_object = Address(self.Locale) record_value = mimesis_object.country() if field[1].name == 'address_postal_code': mimesis_object = Address(self.Locale) record_value = mimesis_object.postal_code() if field[1].name == 'code_imei': mimesis_object = Code(self.Locale) record_value = mimesis_object.imei() if field[1].name == 'code_isbn': mimesis_object = Code(self.Locale) record_value = mimesis_object.isbn() if field[1].name == 'code_pin': mimesis_object = Code(self.Locale) record_value = mimesis_object.pin() if field[1].name == 'food_dish': mimesis_object = Food(self.Locale) record_value = mimesis_object.dish() if field[1].name == 'food_fruit': mimesis_object = Food(self.Locale) record_value = mimesis_object.fruit() if field[1].name == 'food_vegetables': mimesis_object = Food(self.Locale) record_value = mimesis_object.vegetable() '''if field[1].name == 'game_gaming_platform': mimesis_object = Games(self.Locale) record_value = mimesis_object.gaming_platform() if field[1].name == 'game_titles': mimesis_object = Games(self.Locale) record_value = mimesis_object.game()''' if field[1].name == 'person_blood_type': mimesis_object = Person(self.Locale) record_value = mimesis_object.blood_type() if field[1].name == 'person_email': mimesis_object = Person(self.Locale) record_value = mimesis_object.email() if field[1].name == 'person_full_name': mimesis_object = Person(self.Locale) record_value = mimesis_object.full_name() if field[1].name == 'person_nationality': mimesis_object = Person(self.Locale) record_value = mimesis_object.nationality() if field[1].name == 'person_occupation': mimesis_object = Person(self.Locale) record_value = mimesis_object.occupation() if field[1].name == 'person_telephone': mimesis_object = Person(self.Locale) record_value = mimesis_object.telephone() if field[1].name == 'science_atomic_number': mimesis_object = Science(self.Locale) record_value = str(mimesis_object.atomic_number()) if field[1].name == 'science_chemical_element': mimesis_object = Science(self.Locale) record_value = mimesis_object.chemical_element() if field[1].name == 'transport_airplane': mimesis_object = Transport(self.Locale) record_value = mimesis_object.airplane() if field[1].name == 'transport_car': mimesis_object = Transport(self.Locale) record_value = mimesis_object.car() if field[1].name == 'transport_truck': mimesis_object = Transport(self.Locale) record_value = mimesis_object.truck() if field[1].name == 'transport_vehicle_reg_code': mimesis_object = Transport(self.Locale) record_value = mimesis_object.vehicle_registration_code() record_info_out[field[0]].set_from_string(record_creator, record_value) out_record = record_creator.finalize_record() self.output_anchor.push_record(out_record, False) record_creator.reset() # Make sure that the output anchor is closed. self.output_anchor.close() return True