def generate_customer(): phone_number = "899988" + str(ri(1000, 9999)) usernames = [ "schoolboy", "fatherofyourson", "sweetygirl", "neighbors_grandmother", "killer", "superchill", "manofman", "superscalar", "greatestguy" ] domains = ["yandex.ru", "mail.ru", "gmail.ru"] username = usernames[ri(0, len(usernames) - 1)] email = username + "@" + domains[ri(0, len(domains) - 1)] names = [ "Jon", "Yak", "Bob", "Mo", "Ivan", "Lucifer", "Manyak", "Serdol", "Sanek", "Christopher" ] try: Customer.create(phone_number=phone_number, username=username, residential_address=ResidentialAddress.get_by_id( ri(1, ResidentialAddress.select().count())), email=email, full_name=names[ri(0, len(names) - 1)]) except: # KeyError as error: username += str(ri(0, 9999999)) email = username + "@" + domains[ri(0, len(domains) - 1)] Customer.create(phone_number=phone_number, username=username, residential_address=ResidentialAddress.get_by_id( ri(1, ResidentialAddress.select().count())), email=email, full_name=names[ri(0, len(names) - 1)])
def create(): if request.method == "GET": return render_template('new-customer.html') elif request.method == "POST": form = request.form name = form['name'] yob = form['yob'] phone = form['phone'] new_customer = Customer(name=name, yob=yob, phone=phone) #update: set before input value, radio button new_customer.save() return redirect(url_for('admin'))
def add_user(user_email: str, user_pass: str) -> Tuple[int, str]: """ Add new user to DB :param user_email: str, user's email address :param user_pass: str, user hashed password :return: """ hashed_pass: str = get_hash(user_pass) # ADD to DB new customer new_cust: Customer = Customer(first_name='New_user', second_name='flask_August', nickname_telegram='@test', access_type=0, join_date=datetime.datetime.utcnow()) # ADD new bal to user new_bal: Balance = Balance(customer=new_cust, usd_amt=0, eur_amt=0, aed_amt=0) # ADD new password new_pass: Password = Password(customer=new_cust, user_email=user_email, user_pass=hashed_pass) # add_all is similar to git add ... session.add_all([new_cust]) # flush is similar to git commit ... session.flush() # commit is similar to git push ... session.commit() return new_cust.id, hashed_pass
def read(self): rows = Repository().read(self.filename) customers = [ Customer(row['name'], row['address'], row['postal'], row['ssn'], row['phone'], row['email'], row['country'], row['id']) for row in rows ] return customers
def get_Customer(self): #if self.__Customer == []: with open("./data/customer.txt", "r",encoding = "UTF-8-SIG") as Customer_file: for line in Customer_file.readlines(): name,kennitala,phone = line.split(",") new_Customer = Customer(name,kennitala,phone) self.__Customer.append(new_Customer) return self.__Customer
def generate_repairing_event(): time = datetime.datetime(year=ri(2000, 2018), month=ri(1, 12), day=ri(1, 28), hour=ri(0, 23), minute=ri(0, 59), second=ri(0, 59)) RepairingEvent.create( time=time, customer=Customer.get_by_id(ri(1, Customer.select().count())), workshop=Workshop.get_by_id(ri(1, Workshop.select().count())), car=Car.get_by_id(ri(1, Car.select().count())), part=Part.get_by_id(ri(1, Part.select().count())), price=ri(100, 10000))
def generate_charging_event(): # time = datetime.datetime(year=ri(2000, 2018), month=ri(1, 12), day=ri(1, 28), hour=ri(0, 23), minute=ri(0, 59), # second=ri(0, 59)) time = datetime.datetime(year=2018, month=5, day=ri(1, 10), hour=ri(0, 23), minute=ri(0, 59), second=ri(0, 59)) ChargingEvent.create(time=time, car=Car.get_by_id(ri(1, Car.select().count())), customer=Customer.get_by_id( ri(1, Customer.select().count())), charging_station=ChargingStation.get_by_id( ri(1, ChargingStation.select().count())), price=ri(100, 10000))
def search_customer_by_name(self, last_name="", first_name=""): with open("./Data/Customer.csv", "r") as customer_file: for line in customer_file.readlines(): f_name, l_name, address, drivers_license, kennitala, current_rental_number = line.split( ",") if l_name == last_name and f_name == first_name: foundCust = Customer(l_name, f_name, address, drivers_license, kennitala, current_rental_number) return foundCust return None
def search_customer_by_kennitala(self, kennitala): with open("./Data/Customer.csv", "r") as customer_file: for line in customer_file.readlines(): f_name, l_name, address, drivers_license, kt, current_rental_number = line.split( ",") if kennitala == kt: foundCust = Customer(l_name, f_name, address, drivers_license, kt, current_rental_number) return foundCust return None
def generate_trip_event(): pickup_time = datetime.datetime(year=ri(2015, 2018), month=ri(1, 12), day=ri(1, 28), hour=ri(0, 23), minute=ri(0, 59), second=ri(0, 59)) end_time = (pickup_time + datetime.timedelta(hours=int(ri(1, 1000)))) location = [str(i) + " street" for i in range(100, 131)] pickup_location = location[ri(0, 30)] destination_location = location[ri(0, 30)] distance_to_user = ri(0, 30000) trip_duration = ri(0, 2400) TripEvent.create(pickup_location=pickup_location, pickup_time=pickup_time, end_time=end_time, destination_location=destination_location, car=Car.get_by_id(ri(1, Car.select().count())), distance_to_user=distance_to_user, trip_duration=trip_duration, customer=Customer.get_by_id( ri(1, Customer.select().count())))
def customer_menu(self, current_employee): # We need to implement these functions into the repo. # Both of these functiosn are required action = "" options = ["1", "2", "3", "4"] print("=== CUSTOMERS ===\n") while action not in options: print("AVAILABLE OPTIONS:") print( "1. Register a customer\n2. Look up Customer\n3. Remove customer\n4. Go back\n" ) action = input("Enter: ") print("") if action == "1": ## DONE print("Registering a customer") first_name = input("First name: ") last_name = input("Last name: ") address = input("Address: ") drivers_license = input("Drivers license: ") SSN = input("SSN: ") new_customer = Customer(last_name, first_name, address, drivers_license, SSN) self.__car_rental_service.add_customer(new_customer) print("") self.customer_menu(current_employee) elif action == "2": ## NOT DONE print("Looking up customer") SSN = input("SSN: ") print("") self.__car_rental_service.search_customer(SSN) self.customer_menu(current_employee) elif action == "3": ## NOT DONE print("Remove customer") SSN = input("SSN: ") self.__car_rental_service.remove_customer(SSN) self.customer_menu(current_employee) elif action == "4": print("Going back to main menu") self.main_menu(current_employee) else: print("Invalid input") self.customer_menu(current_employee)
def create_fake_names(no_to_create=1): for _ in range(no_to_create): company_name = fake.company() email_id = fake.email() phone = fake.phone_number() mobile = fake.numerify(text="04## ### ###") cust = Customer(company_name) cust.connection = connection cust.emailId = email_id cust.mobileNo = phone cust.insert_record() address = Address() address.connection = connection address.name = cust.name address.email_id = cust.emailId address.phone = fake.phone_number() address.addressLine1 = fake.numerify( text="###") + ' ' + fake.street_name() + ' ' + fake.street_suffix( ) address.suburb = fake.city() address.postCode = fake.postcode() address.state = fake.state() address.insert_record() link = DynamicLink(cust.name, address.name + '-' + address.addressType, 'Address', 'Customer') link.connection = connection link.insert_record() contact = Contact() contact.companyName = cust.name contact.connection = connection contact.firstName = fake.first_name() contact.lastName = fake.last_name() contact.phone = fake.phone_number() contact.mobile = mobile contact.emailID = fake.email() contact.insert_record() link = DynamicLink( cust.name, contact.firstName + '-' + contact.lastName + '-' + cust.name, 'Contact', 'Customer') link.connection = connection link.insert_record() connection.close()
def populate_customer_list(self): """ Opens the database (csv) file and reads its contents. If the file doesn't exist it is created with the columns of the file. """ try: with open("./data/customers.csv", "r") as customer_db: csv_dict = csv.DictReader(customer_db) for line in csv_dict: new_customer = Customer( line["customer_ID"], line["identity_number"], line["first_names"], line["surname"], line["citizenship"], line["passport_ID"], line["credit_card_no"]) self.__customers.append(new_customer) except FileNotFoundError: with open("./data/customers.csv", "a+") as customer_db: customer_db.write( "customer_ID,identity_number,first_names,surname,citizenship,passport_ID,credit_card_no\n" )
def action1(): print("-"*80) print("New customer:") SSN_input = input('Enter The SSN Of The Person You Want To Sign Up: ') SSN = self.__CustomerService.check_SSN(SSN_input) # isFound iterates through the file and if there is a match, it will let you know that the customer already exists isfound = self.__CustomerService.check_Costumer(SSN) if isfound: print('\nCustomer Already Exists!') else: name = input('Enter A Name: ') phonenumber_input = input('Enter A Phone Number: ') phonenumber = self.__CustomerService.check_Phonenumber( phonenumber_input) email = input('Enter An Email: ') new_Costumer = Customer(SSN, name, phonenumber, email) self.__CustomerService.add_customer(new_Costumer) print('\nCustomer Signed!')
def checkCredentials(user_id, password): user = None db = connector.connect(user='******', password='******', host='127.0.0.1', database='python_bank_project') cursor = db.cursor() args = (user_id, password) cursor.execute("Select c.first_name, c.last_name, c.address_id, a.status from customer as c, account as a where c.cust_id = %s and c.password = %s and a.account_no = c.cust_id", args) results = cursor.fetchall(); if len(results) > 0: if(results[0][3] == 'C'): print("Your Account is Closed. Please contact your bank admin.") else: user = Customer(); user.set_first_name(results[0][0]) user.set_last_name(results[0][1]) user.set_address(results[0][2]) db.close() return user
def customer_create(user, storeId): customer_fields = customer_schema.load(request.json) customer = Customer.query.filter_by(email=customer_fields["email"]).first() if customer: return abort(400, description="Email already in use") new_customer = Customer() new_customer.firstname = customer_fields["firstname"] new_customer.lastname = customer_fields["lastname"] new_customer.email = customer_fields["email"] new_customer.phone = customer_fields["phone"] new_customer.store_id = storeId store = Store.query.filter_by(id=storeId, user_id=user.id).first() if not store: return abort(400, description="Incorrect storeID in URL") store.customer.append(new_customer) db.session.commit() return jsonify(customer_schema.dump(new_customer))
def new_Or_Old(): '''Is the Customer new or has he rented from us before''' print("-" * 80) new_Or_Old = input( 'Has The Customer Rented From Us Before? (Y = Yes, N = No) ' ).lower() while new_Or_Old != 'y' or 'n': if new_Or_Old == 'y': print() break elif new_Or_Old == 'n': print("\nSigning A New Customer:") print("-" * 80) SSN_input = input( 'Enter The SSN Of The Person Who Is Putting In An Order: ' ) SSN = self.__CustomerService.check_SSN(SSN_input) # isFound iterates through the file and if there is not match it will allow the user to try again isfound = self.__CustomerService.check_Costumer(SSN) if isfound: print('\nCustomer Already Exists!' ) #we dont need to sign him up else: name = input('Enter A Name: ') phonenumber_input = input('Enter A Phone Number: ') phonenumber = self.__CustomerService.check_Phonenumber( phonenumber_input) email = input('Enter An Email: ') new_Costumer = Customer(SSN, name, phonenumber, email) self.__CustomerService.add_customer(new_Costumer) print("\nCostumer Signed!\n\n") break else: print('Invalid Input, Try Again!') new_Or_Old = input( 'Has The Customer Rented A Car From Us Before? (Y = Yes, N = No) ' ).lower()
def add_Customer(self, Customer): with open("./data/customer.txt", "a+", encoding = "UTF-8-SIG") as Customer_file: name = Customer.get_name() kennitala = Customer.get_kennitala() phone = Customer.get_phone() Customer_file.write("{},{},{}\n".format(name,kennitala,phone))
def seed_db(): from models.User import User from models.Store import Store from models.Product import Product from models.Customer import Customer from models.Order import Order from main import bcrypt from faker import Faker faker = Faker() users = [] stores = [] products = [] customers = [] for i in range(5): user = User() user.email = f"test{i+1}@test.com" user.password = bcrypt.generate_password_hash("123456").decode("utf-8") user.isAdmin = False db.session.add(user) users.append(user) db.session.commit() store = Store() store.storename = faker.bs() store.firstname = faker.first_name() store.lastname = faker.last_name() store.user_id = users[i].id db.session.add(store) stores.append(store) db.session.commit() for j in range(5): product = Product() product.title = faker.numerify(text="Duck ###") product.price = faker.random_int(min=5, max=200, step=5) product.store_id = stores[i].id db.session.add(product) products.append(product) db.session.commit() for j in range(5): customer = Customer() customer.firstname = faker.first_name() customer.lastname = faker.last_name() customer.email = faker.ascii_email() customer.phone = faker.phone_number() customer.store_id = stores[i].id db.session.add(customer) customers.append(customer) db.session.commit() for k in range(5): order = Order() order.order_placed = choice([True, False]) order.customer_id = choice(customers).id db.session.add(order) db.session.commit() for m in range(3): order.orders_products.append(choice(products)) db.session.commit() customers = [] db.session.commit() print("Tables seeded")
async def get_all_customers_count_in_db() -> int: query = Customer.count() count = await database.execute(query) return count
from models.Customer import Customer import mlab from faker import Faker from random import randint, choice mlab.connect() faker = Faker() # name = faker.name() # print(name) for i in range(100): print("Saving customer", i + 1, ".......") new_customer = Customer(name=faker.name(), yob=randint(1940, 2000), gender=randint(0, 1), phone=faker.phone_number(), address=faker.address(), email=faker.email(), job=faker.job(), contacted=choice([True, False])) new_customer.save()
async def find_customer_by_id(_id: UUID) -> CustomerInResp: query = select([Customer, ps.User]).select_from(Customer.join( ps.User)).where(Customer.columns.customer_id == _id) customer = await database.fetch_one(query) return customer
def add_customer(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('id', None) is None): return obj2json(RetModel(31, dict_err_code[31], {})) if (request.form.get('name', None) is None): return obj2json(RetModel(32, dict_err_code[32], {})) if (request.form.get('address', None) is None): return obj2json(RetModel(33, dict_err_code[33], {})) if (request.form.get('longitude', None) is None): return obj2json(RetModel(34, dict_err_code[34], {})) if (request.form.get('latitude', None) is None): return obj2json(RetModel(35, dict_err_code[35], {})) customer = Customer() customer.id = request.form['id'] customer.uid = request.form['uid'] customer.name = request.form['name'] customer.group_name = request.form.get('group_name', '') customer.spell = request.form.get('spell', '') customer.address = request.form['address'] customer.longitude = request.form['longitude'] customer.latitude = request.form['latitude'] customer.boss = request.form.get('boss', '') customer.phone = request.form.get('phone', '') customer.email = request.form.get('email', '') customer.description = request.form.get('description', '') customer.update_date = request.form.get('update_date', int(time.time())) if (True == insert_customer(request.form['uid'], customer)): szRet = obj2json(RetModel(0, dict_err_code[0], {})) else: szRet = obj2json(RetModel(1000, dict_err_code[1000], {})) return szRet
import mlab mlab.connect() # id_to_find = "5b7be22918fca375eafae0d9" # #amanda = Customer.objects(id=id_to_find) ## => [] # #amanda = Customer.objects.get(id=id_to_find) ## => Service object # customer = Customer.objects.with_id(id_to_find) ## => Service object # if customer is not None: # #print(amanda.name) # #customer.delete() # #print("Deleted") # print("Before: ") # print(customer.to_mongo()) #print(customer.yob) # customer.update(set__yob=2005, set__name="Linh cute") # customer.reload() # print("After: ") # print(customer.to_mongo()) # else: # print("Not found") all_customer = Customer.objects() first_customer = all_customer[0] print(first_customer['name'])
async def create_new_customer(obj_in: CustomerBase) -> UUID: query = Customer.insert() values = obj_in.dict() await database.execute(query=query, values=values) customer = await find_customer_by_id(obj_in.customer_id) return customer
def admin(): all_customer = Customer.objects() return render_template('admin.html', all_customer=all_customer)
def init_customer(row): customer = Customer() customer.id = row['id'] customer.uid = row['uid'] customer.name = row['name'] customer.group_name = row['group_name'] customer.spell = row['spell'] customer.address = row['address'] customer.longitude = row['longitude'] customer.latitude = row['latitude'] customer.boss = row['boss'] customer.phone = row['phone'] customer.email = row['email'] customer.description = row['description'] customer.update_date = row['update_date'] customer.is_deleted = row['is_deleted'] return customer
async def get_all_customers_in_db(offset: int = 0, limit: int = 10) -> List[CustomerInResp]: query = select([Customer, ps.User]).select_from(Customer.join( ps.User)).offset(offset).limit(limit) customers = await database.fetch_all(query) return customers
async def update_customer_record_in_db(_id: UUID, values: dict) -> CustomerInResp: query = Customer.update().where(Customer.columns.customer_id == _id) await database.execute(query, values) customer = await find_customer_by_id(_id) return customer
def main_menu(self): update_progress(-1) time.sleep(.4) update_progress(1) time.sleep(.3) cls('') time.sleep(.2) action = "" while (action != "h"): print( "╔════════════════════════════════════════════════════════════════════════════════════╗" ) print( "║ ", "%d" % now.day + "/" + "%d" % now.month + "/" + "%d" % now.year + " | " + now.strftime("%H:%M:%S"), " ║") print( "║--------------------------------------Aðgerðir:-------------------------------------║" ) print( "║1. Leigja út bíl (skrá pöntun) ║" ) print( "║2. Skila bíl í lok leigutíma ║" ) print( "║--------------------------------------Skýrslur:-------------------------------------║" ) print( "║4. Flétta upp pöntun ║" ) print( "║6. Birta yfirlit yfir viðskiptamenn ║" ) print( "║7. Birta lista yfir lausa bíla ║" ) print( "║8. Birta lista yfir lausa bíla eftir flokkum ║" ) print( "║9. Birta lista yfir bíla í útleigu ║" ) print( "║ ║" ) print( "║ ║" ) print( "║ ║" ) print( "║ ║" ) print( "╠════════════════════════════════════════════════════════════════════════════════════╣" ) print( "║--------------------------------Uppsetning / viðhald :------------------------------║" ) print( "║90. Stofna notanda að kerfinu ║" ) print( "║91. Stofna viðskiptamann ║" ) print( "║92. Stofna bíl ║" ) print( "╠════════════════════════════════════════════════════════════════════════════════════╣" ) print( "║ ║" ) print( "║ ║" ) print( "║Sláðu inn 'h' til að hætta ║" ) print( "╚════════════════════════════════════════════════════════════════════════════════════╝" ) action = input("Veldu valmöguleika: ").lower() if action == "1": d = {} cls('start') # now, to clear the screen d["ORDER_ID"] = input("Sláðu inn pöntunarnúmer: ") d["CUSTOMER_ID"] = input("Nr viðskiptamanns: ") d["LICENCE_PLATE_NUMBER"] = input("Bílnúmer: ") d["CAR_LOCATION"] = input("Staðsetning bíls í upphafi ") d["ORDER_DATE"] = input("Pöntun dags: ") d["START_DATE"] = input("Start date: ") """ ret_loc = input('Skilastaðsetning bíls: ') ret_date = input("Skiladags bíls: ") pay_meth = input("Greiðslumáti: ") card_no = input(" Kortanúmer (ef við á): ") ins_bas = input("Grunntrygging: ") ins_xtra = input("Aukatrygging: ") com_ = input("Athugasemdir: ") """ #new_o = Ord(order_n,customer_n,license_plate_n,start_loc,order_d,start_d,ret_loc,ret_date,pay_meth,card_no,ins_bas,ins_xtra,com_) new_o = Ord(d) self.__Ord_service.add_Ord(new_o) cls('end') elif action == "6": cls('') customer = self.__Customer_service.get_Customer() print(customer) cls('end') elif action == "7": cls('') # now, to clear the screen vehicles = self.__Vehicle_service.get_Available_Vehicles() #for row in vehicles: # print(row) cls('end') elif action == "8": cls('') # now, to clear the screen vec_class = input( 'Hvaða flokk viltu skoða? (ath: sýna hér lista yfir mögulega flokka...) ' ) vehicles = self.__Vehicle_service.get_Available_Vehicles_by_Class( vec_class) # does this work? cls('end') elif action == "9": cls('') # now, to clear the screen vehicles = self.__Vehicle_service.get_Occupied_Vehicles() cls('end') elif action == "89": cls('') newuser = input("Sláðu inn notendanafn: ") pwd = input("Sláðu inn lykilorð: ") ssn = input("Sláðu inn kennitölu: ") name = input('Fullt nafn: ') addr = input('Heimilisfang: ') phone = input("Símanúmer: ") e_mail = input("Tölvupóstfang: ") active = 'YES' comments = input('Athugasemd: ') new_employee = System_Maintenance(newuser, pwd, ssn, name, addr, phone, e_mail, active, comments) self.__System_MaintenanceService.add_System_Maintenance( new_employee) cls('end') #new_veh = Vehicle(license_plate, manuf,subt,v_class, prod_year,curr_loc,return_loc,return_date,com) #0D, simply represents that this car isn't rented out (yet) # self.__Vehicle_service.add_Vehicle(new_veh) elif action == "90": cls('') newuser = input("Sláðu inn notendanafn ") pwd = input("Sláðu inn lykilorð ") """ file = open("./data/access.txt","a+") file.write(newuser) file.write(" ") file.write(pwd) file.write("\n") file.close() """ cls('end') elif action == "91": cls('') name = input("Nafn: ") kennitala = input("Kennitala: ") phone = input("Símanúmer: ") new_Customer = Customer(name, kennitala, phone) self.__Customer_service.add_Customer(new_Customer) cls('end') elif action == '92': cls('') license_plate = input("Bílnúmer: ") manuf = input("Framleiðandi: ") subt = input("Undirtegund (týpa) ") v_class = input("Flokkur: ") prod_year = input("Árgerð: ") curr_loc = input("Staðsetning: ") return_loc = '' #doesn't apply to cars - until they are rented out return_date = '0D' com = input("Athugasemdir: ") #self, license_plate, manufacturer, subtype, vec_class, production_year,current_location,return_location,'',comments new_veh = Vehicle( license_plate, manuf, subt, v_class, prod_year, curr_loc, return_loc, return_date, com ) #0D, simply represents that this car isn't rented out (yet) self.__Vehicle_service.add_Vehicle(new_veh) cls('end') elif action == 'h': time.sleep(.2) print('Bíðið - kerfi slekkur á sér og gengur frá') # update_progress() : Displays or updates a console progress bar ## Accepts a float between 0 and 1. Any int will be converted to a float. ## A value under 0 represents a 'halt'. ## A value at 1 or bigger represents 100% update_progress(-1) time.sleep(.3) update_progress(1) time.sleep(.2) print('Sjáumst aftur!') time.sleep(.2) cls("") else: cls('') print('Óleyfilegt gildi slegið inn, reyndu aftur.')