示例#1
0
def insertUser(total):
    user_list = RandomUser.generate_users(total, {'nat': 'us'})
    headers = {
        "Host":
        "localhost",
        "Content-Type":
        "application/x-www-form-urlencoded",
        "Referer":
        "http://localhost:8080",  # 必须带这个参数,不然会报错
        "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
    }
    url = "http://localhost:8080/result"
    password = "******"
    for i in range(total):
        form_data = {
            "password": password,
            "passwordCheck": password,
            "emailAddress": user_list[i].get_email(),
            "lastName": user_list[i].get_last_name(),
            "firstName": user_list[i].get_first_name(),
            "passport": user_list[i].get_id_number(),
            "phoneNumber": user_list[i].get_phone(),
            "nickname": user_list[i].get_username(),
            "role": random.randint(1, 2)
        }
        results = requests.post(url, data=form_data, headers=headers).text
示例#2
0
def insertPolicy(total):
    # Generate a list of 10 random users
    user_list = RandomUser.generate_users(total, {'nat': 'us'})
    for i in range(total):
        serial_no = list('0123456789')
        random.shuffle(serial_no)
        serial_no = int(''.join(serial_no[:8]))
        place_from = "Beijing" if random.randint(0, 1) else "Dublin"
        place_to = "Dublin" if place_from is "Beijing" else "Beijing"
        policy_type = "Single" if random.randint(0, 1) else "Return"
        validate_from = datetime(2019, random.randint(1, 12),
                                 random.randint(1, 15), random.randint(0, 23),
                                 random.randint(0, 59))
        validate_to = validate_from + timedelta(days=random.randint(1, 3))
        customer_id = random.randint(51, 100)
        temp = list('0123456789')
        random.shuffle(temp)
        flight_no = "BD" + ''.join(
            temp[:6]) if place_from is "Beijing" else "DB" + ''.join(temp[:6])
        policy_holder = user_list[i].get_first_name(
        ) + " " + user_list[i].get_last_name()
        insurance_type = "Luggage Lost"
        pieces_of_luggage = random.randint(1, 10)
        print(serial_no, place_from, place_to, validate_from, validate_to,
              customer_id, flight_no, policy_holder, insurance_type,
              pieces_of_luggage)
        sql = "INSERT INTO policy (serial_no, place_from,place_to,policy_type,validate_from,validate_to,customer_id," \
              "flight_no,policy_holder,insurance_type,pieces_of_luggage,is_claimed) VALUES ('%d', '%s','%s','%s','%s','%s','%d','%s'," \
              "'%s','%s','%d','%d')" % (serial_no, place_from, place_to, policy_type, validate_from,
                                        validate_to, customer_id, flight_no, policy_holder, insurance_type,
                                        pieces_of_luggage, 0)
        cursor.execute(sql)
    connection.commit()
    connection.close()
示例#3
0
def create_random_person_data(how_many: int) -> List[PersonData]:
    # import is in function because circular import
    from .DataDeserializer import DataDeserializer
    users = RandomUser.generate_users(how_many)

    users_data = [user._data for user in users]

    return DataDeserializer.deserialize_many(users_data)
def gen_hundred_users():
    user_list = RandomUser.generate_users(100, {'gender': 'male'})
    formatted_users = []
    for user in user_list:
        formatted_user = (user.get_first_name(), user.get_last_name(),
                          user.get_age(), user.get_gender(), user.get_email())
        formatted_users.append(formatted_user)
    return formatted_users
示例#5
0
 def _get_random_users(qty: int = 1000):
     while True:
         try:
             return RandomUser.generate_users(qty,
                                              get_params=dict(nat='GB'))
         except Exception:
             print('Sleeping 1 sec and trying again')
             time.sleep(1)
def generateUsers(n):
    from randomuser import RandomUser

    users = {"abc": "123"}
    temp = RandomUser.generate_users(5)

    for user in temp:
        users[user.get_username()] = user.get_password()

    with open('users.json', 'w') as outfile:
        json.dump(users, outfile, indent=2)
示例#7
0
    def handle(self, *args, **options):
        user_list = RandomUser.generate_users(options['count'])

        for i in user_list:
            user = User()
            user.username = i.get_username()
            user.first_name = i.get_first_name()
            user.last_name = i.get_last_name()
            user.email = i.get_email()
            user.password = i.get_password()
            user.date_joined = datetime.now(tz=timezone.utc)
            user.save()
        self.stdout.write(self.style.SUCCESS(f'successfully published '))
示例#8
0
def insertPolicyAndClaim(total):
    print("insertPolicyAndClaim")
    # Generate a list of total random users
    user_list = RandomUser.generate_users(total, {'nat': 'us'})
    for i in range(total):
        serial_no = list('0123456789')
        random.shuffle(serial_no)
        serial_no = int(''.join(serial_no[:8]))
        place_from = "Beijing" if random.randint(0, 1) else "Dublin"
        place_to = "Dublin" if place_from is "Beijing" else "Beijing"
        policy_type = "Single" if random.randint(0, 1) else "Return"
        validate_from = datetime(2019, random.randint(1, 4),
                                 random.randint(1, 25), random.randint(0, 23),
                                 random.randint(0, 59))
        validate_to = validate_from + timedelta(days=random.randint(1, 3))
        customer_id = random.randint(51, 100)
        temp = list('0123456789')
        random.shuffle(temp)
        flight_no = "BD" + ''.join(
            temp[:6]) if place_from is "Beijing" else "DB" + ''.join(temp[:6])
        policy_holder = user_list[i].get_first_name(
        ) + " " + user_list[i].get_last_name()
        insurance_type = "Luggage Lost"
        pieces_of_luggage = random.randint(1, 10)
        if random.randint(0, 1):
            employee_id = random.randint(1, 50)
            result = "Approved" if random.randint(0, 1) else "Rejected"
        else:
            employee_id = 0
            result = "Unprocessed"
        print(serial_no, place_from, place_to, validate_from, validate_to,
              customer_id, flight_no, policy_holder, insurance_type,
              pieces_of_luggage)
        sql = "INSERT INTO policy (serial_no, place_from,place_to,policy_type,validate_from,validate_to,customer_id," \
              "flight_no,policy_holder,insurance_type,pieces_of_luggage,is_claimed) VALUES ('%d', '%s','%s','%s','%s','%s','%d','%s'," \
              "'%s','%s','%d','%d')" % (serial_no, place_from, place_to, policy_type, validate_from,
                                        validate_to, customer_id, flight_no, policy_holder, insurance_type,
                                        pieces_of_luggage, 1)
        cursor.execute(sql)
        print(serial_no,
              user_list[i].get_street() + " " + user_list[i].get_city(),
              customer_id, validate_from, str(user_list[i].get_picture()), 0,
              flight_no)
        sql = "INSERT INTO claim (serial_no, billing_address, customer_id, submit_date, details, employee_id, flight_no, result" \
              ") VALUES ('%d','%s', '%d', '%s', '%s', '%d', '%s', '%s')" % \
              (serial_no, user_list[i].get_street() + " " + user_list[i].get_city(), customer_id, validate_from,
               str(user_list[i].get_picture()), employee_id, flight_no, result)
        cursor.execute(sql)
    connection.commit()
    connection.close()
示例#9
0
文件: app.py 项目: yuriichornyii/Task
def random_users():
    db.drop_all()
    db.create_all(app=app)
    users = RandomUser.generate_users(100, {'gender': 'male'})
    for user in users:
        user = UserModel(first_name=user.get_first_name(),
                         last_name=user.get_last_name(),
                         dob=user.get_dob(),
                         gender=user.get_gender()
                         # may add more fields(city, number ...)
                         )
        db.session.add(user)
        db.session.commit()
    return app
示例#10
0
def generate_fake_providers(num_customers: int = 10):
    def generate_address(user):
        street = user.get_street()
        city = user.get_city()
        state = user.get_state()
        address = ','.join([street, city, state])
        return address

    user_list = RandomUser.generate_users(10)
    user_list = list(
        map(
            lambda x: dict(first_name=x.get_first_name(),
                           last_name=x.get_last_name(),
                           email=x.get_email(),
                           address=generate_address(x),
                           pincode=x.get_zipcode(),
                           cellphone=x.get_cell()), user_list))
    return user_list
def load_rows(rows: int):
    """
    loading db data when starting app
    """
    initialize_db()

    for user in RandomUser.generate_users(rows):

        # gallery loads
        img_file = open(f"static/img/users/{user.get_first_name()}.jpg", "wb")
        img_file.write(requests.get(user.get_picture().format()).content)
        img_file.close()

        # db data loads
        User.create(
            first_name=user.get_first_name(),
            last_name=user.get_last_name(),
            gender=user.get_gender(),
            phone=user.get_phone(),
            email=user.get_email(),
            state=user.get_state(),
        ).save()
示例#12
0

def getAverage(subjects):
    avg = 0
    for subject in subjects:
        avg = (avg + subject['avgRating']) / 2
    return avg


if __name__ == "__main__":
    db = initFirestore()
    collection_name = "users"

    # Write a test of 10 (American) users to Firestore database
    numUsers = 20
    users = RandomUser.generate_users(numUsers, {"nat": "us"})
    print(f"[INFO]: Adding {numUsers} to Firestore database...")

    for user in tqdm(users):
        userData = parseUser(user)
        # For now, just use the email for Document IDs
        doc_ref = db.collection(collection_name).document(user.get_email())
        doc_ref.set(userData)
        subjects = []

        # Add 3 random subjects to proficientStudies sub-collection
        for subject in userData['proficientStudies']:
            subject_ref = doc_ref.collection("proficientStudies").document(
                subject)
            subject = parseSubject(subject)
            subject_ref.set(subject)
示例#13
0
  id=""
  name=""

class Car_Manufacturer:
  id=""
  company_name=""
  is_user=""
  username=""
  password=""
  email=""
  phone=""
  hashed_password =""
  whatamI = 0
  sessionID =0

user_list = RandomUser.generate_users(100)
energy_suppliers=['Harz Energie','BS Energie','EV Energy Group (FCN)','eVgo Network','EVS Energieversorgung Sylt','Evway','EWB','EWI Energiewerke Isernhagen','Fenie Energía (Spain)','FLOW Charging','FORTISIS','GardaUno','Gnrgy','GoCharge (IE)','Greenflux']
car_manufacturers=[Car_Manufacturer() for i in range(len(company_names1))]
car_owners = [Car_Owner() for i in range(len(user_list))]
energy_supplier=[Energy_Supplier() for i in range(len(energy_suppliers))]
payment=[Payment() for i in range(len(car_owners))]
banks=[Bank() for i in range(0,4)]

bank=['City Union Bank','Federal Bank','Union Bank','National Bank']

for i in range(0,4):
  banks[i].id=i+1
  banks[i].name=bank[i]


def get_random_users(count=100):
    return RandomUser.generate_users(count)
from randomuser import RandomUser
from python_graphql_client import GraphqlClient
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    pass
else:
    ssl._create_default_https_context = _create_unverified_https_context

randomUser = []

user_list = RandomUser.generate_users(10, {'nat': 'de'})

for user in user_list:
    randomUserProperties = {}
    randomUserProperties["first_name"] = user.get_first_name()
    randomUserProperties["last_name"] = user.get_last_name()
    randomUserProperties["phone_number"] = user.get_phone()
    randomUserProperties["street"] = user.get_street()
    randomUserProperties["zip_code"] = user.get_zipcode()
    randomUserProperties["city"] = user.get_city()

    randomUser.append(randomUserProperties)

    client = GraphqlClient(
        endpoint='http://95.217.162.167:8080/v1/graphql')
    variables = {"first_name": randomUserProperties["first_name"], "last_name": randomUserProperties["last_name"],
                 "phone_number": randomUserProperties["phone_number"], "street": randomUserProperties["street"], "zip_code": randomUserProperties["zip_code"], "city": randomUserProperties["city"]}
    insertQuery = """