def getBusiness(self): businessList = [] for i, obj in enumerate(self.data): business = Business() if "business_id" in obj.keys(): business.business_id = obj["business_id"] if "name" in obj.keys(): business.name = obj["name"] if "latitude" in obj.keys(): business.location_lat = obj["latitude"] if "longitude" in obj.keys(): business.location_lon = obj["longitude"] if "stars" in obj.keys(): business.stars = obj["stars"] if "open" in obj.keys(): business.open_now = obj["open"] if "categories" in obj.keys(): business.categories = obj["categories"] if "hours" in obj.keys(): business.hours = obj["hours"] if "userRating" in obj.keys(): business.userRating = obj["userRating"] businessList.append(self.processBusinessAttributes(business, obj)) return businessList
class testingBusiness(unittest.TestCase): def setUp(self): self.biz = Business(1, 1, 'las computers', 'location', 'bizCategory', 'bizDescription') def test_bizInstance(self): self.assertIsInstance(self.biz, Business) def test_createBusiness(self): result = self.biz.createBusiness(1, 1, 'anybusiness', 'anylocation', 'anycategory','the best business') self.assertTrue(result) def test_checkBusinessExists(self): result = self.biz.checkBusinessExists(1) self.assertFalse(result) def test_updateBusiness(self): result = self.biz.updateBusiness(1, 1, 'anybusiness', 'anylocation', 'anycategory','the best business') self.assertFalse(result) # def test_deleteBusiness(self): # result = self.biz.deleteBusiness(1) # self.assertFalse(result) def test_getOwnBusiness(self): result = self.biz.getOwnBusinesses(1) self.assertEqual(result, '') def test_getAllBusinesses(self): result = self.biz.getAllBusinesses() self.assertEqual(result, [])
def create(business_id): username = get_jwt_identity() user = User.get_or_none(User.username==username) business = Business.get_or_none(Business.id==business_id, Business.user==user) if user and business: assess = Assessment(year_assessment=request.json.get('y_a'), year_ended=request.json.get('y_e'), business=business) if assess.save(): return jsonify({ "status": True, "message": "Successfully create new assessment year.", "assessment": { "id": assess.id, "business": business.name, "y_a": assess.year_assessment, "y_e": assess.year_ended } }),200 else: return jsonify({ "status": False, "message": "Unable to create new assessment year." }),404 else: return jsonify({ "status": False, "message": "No user/business found." }),401
def load_business_data(self, business_file): business_item_hash = {} print_debug("Starting to read business file from:" + business_file, INFO_INT) f_bus = open(business_file) count = 0 rating = 0 for line in f_bus: business_line = json.loads(line) business_item = Business(business_line) business_item_hash[business_item.business_id] = business_item count += 1 rating += business_item.stars print_debug( "Reading record business_id: " + str(business_item.business_id), DEBUG_INT) all_bus_avg_rating = float(rating) / count print_debug("Total business line read: " + str(count), INFO_INT) print_debug( "Total unique business item read: " + str(len(business_item_hash.keys())), INFO_INT) print_debug("All business avg rating: " + str(all_bus_avg_rating), INFO_INT) data = { 'business_item_hash': business_item_hash, 'all_bus_avg_rating': all_bus_avg_rating } self.data = {'data': data}
def index(): username = get_jwt_identity() user = User.get_or_none(User.username == username) if user: business_list = [{ "id": b.id, "name": b.name } for b in Business.select().where(Business.user == user)] return jsonify({"status": True, "businesses": business_list}) else: return jsonify({"status": False, "message": "No user found."})
def get(self, business_id, type, **kwargs): if type.lower() == 'service': objects = Business.objects(id=ObjectId(business_id)).services print(objects) else: return super(CSV, self).get() csv = '1,2,3\n4,5,6\n' return Response( csv, mimetype="text/csv", headers={"Content-disposition": "attachment; filename=myplot.csv"})
def create(): username = get_jwt_identity() user = User.get_or_none(User.username == username) if user: business = Business(name=request.json.get('name'), user=user) if business.save(): return jsonify({ "status": True, "message": "Successfully create new business.", "business": { "id": business.id, "name": business.name } }), 200 else: return jsonify({ "status": False, "message": "Unable to create new business." }), 400 else: return jsonify({"status": False, "message": "No user found."}), 401
def index(business_id): username = get_jwt_identity() user = User.get_or_none(User.username==username) business = Business.get_or_none(Business.id==business_id, Business.user==user) if user and business: assessments = [{"id":a.id,"y_a":a.year_assessment,"y_e":a.year_ended} for a in Assessment.select().where(Assessment.business==business.id)] return jsonify({ "status": True, "assessments": assessments }),200 else: return jsonify({ "status": False, "message": "No user/business found." }),401
def show(user_id): username = get_jwt_identity() user = User.get_or_none(User.username == username) if user: business_list = [{ "id": b.id, "name": b.name } for b in Business.select().where(Business.user == user)] return jsonify({ 'user': { "id": user.id, "username": user.username, "email": user.email, }, "businesses": business_list, 'status': True }), 200 else: return jsonify({"status": False, 'message': 'No such user.'}), 404
def load_business_data(self, business_file): business_item_hash = {} print_debug("Starting to read business file from:" + business_file, INFO_INT) f_bus = open(business_file) count = 0 cat_count = 0 total_review_count = 0 for line in f_bus: business_line = json.loads(line) business_item = Business(business_line) business_item_hash[business_item.business_id] = business_item cat_count = self.update_categories(business_item, self.category_hash, cat_count) total_review_count+=business_item.review_count count+=1 print_debug("Reading record business_id: " + str(business_item.business_id), DEBUG_INT) self.total_review_count= total_review_count self.count = count self.business_item_hash = business_item_hash
sys.path.insert(0, parentdir) from models.users import User from models.business import Business from models.reviews import Reviews app = Flask(__name__) app.config['SECRET_KEY'] = 'thisissecret' """ Register route and function register user: a method that adds a user to the system """ user = User() review = Reviews() business = Business() @app.route('/api/auth/register', methods=['POST']) def register_user(): request_data = request.get_json() id = len(user.users) + 1 username = request_data['username'] email = request_data['email'] is_valid_email = validate_email(email) # check if user entered value if not (username.strip()): return jsonify({'Message': 'You must enter username, Cannot be blank'}), 401
'email': '*****@*****.**', 'password': '******', 'password_confirmation': 'password' }) if errors: raise Exception(errors) db.session.add(user6) cocacola = Business( id='1', user=user1, name='Coca-Cola Company', description= 'The Coca-Cola Company is an American corporation, and manufacturer, retailer, and marketer of nonalcoholic beverage concentrates and syrups.', image= 'http://www.coca-colamexico.com.mx/content/dam/journey/mx/es/private/historia/2017/agosto/Logo-Coca-Cola-Company.jpg', emmisions='5.52 millions metric tones', energy='52 millions megajules', category='Food and Beverage') db.session.add(cocacola) apple = Business( id='2', user=user1, name='Apple Inc', description= 'Apple Inc. is an American multinational technology company headquartered in Cupertino, California, that designs, develops, and sells consumer electronics, computer software, and online services.', image= 'https://www.apple.com/ac/structured-data/images/open_graph_logo.png?201809210816',
def setUp(self): self.biz = Business(1, 1, 'las computers', 'location', 'bizCategory', 'bizDescription')
def getBusiness(self): businessList = [] # print(self.data) for i, obj in enumerate(self.data): # print obj business = Business() if "business_id" in obj.keys(): business.business_id = obj["business_id"] if "name" in obj.keys(): business.name = obj["name"] if "latitude" in obj.keys(): business.location_lat = obj["latitude"] if "longitude" in obj.keys(): business.location_lon = obj["longitude"] if "stars" in obj.keys(): business.stars = obj["stars"] if "open" in obj.keys(): business.open_now = obj["open"] if "categories" in obj.keys(): business.categories = obj["categories"] if "hours" in obj.keys(): business.hours = obj["hours"] if "userRating" in obj.keys(): business.userRating = obj["userRating"] businessList.append(self.processBusinessAttributes(business, obj)) return businessList
from models.business import Business from models.user import User business = Business("name", "id") user = User("username", "usersID") print(business.name) print(user.name)
from app import app, db from models.business import Business from models.category import Category from models.customer import Customer from models.sale import Sale with app.app_context(): db.drop_all() db.create_all() test_business = Business(name='testing1', type='type1') db.session.add(test_business) db.session.commit() test_category = Category(type='type') db.session.add(test_category) test_sale = Sale(title='title1', content='content1', business=test_business, category=test_category) db.session.add(test_sale) test_customer = Customer(name='name1', phone='phone1', email='email1', catagories=[test_category]) db.session.add(test_customer) db.session.commit()