def setup_test_listings(): l1 = Listing(vendor_id=Vendor.query.filter_by(first_name="Ven").first().id, unit="lbs", quantity="0", name="Broccoli", description="Best Broccoli Around", price=5.00, available=True, product_id=1) l2 = Listing(vendor_id=Vendor.query.filter_by(first_name="Ven").first().id, name="Eggs", unit="oz", quantity="2", description="Best Eggs Around", price=12.00, available=True, product_id=2) l3 = Listing( vendor_id=Vendor.query.filter_by(first_name="Ven2").first().id, name="Salmon", unit="gal", quantity="500", description="Best Salmon Around", price=13.00, available=True, product_id=3) db.session.add(l1) db.session.add(l2) db.session.add(l3) db.session.commit() from sqlalchemy.exc import IntegrityError from random import seed, choice from faker import Faker fake = Faker() seed() count = 0 for i in range(100): u = Listing(vendor_id=3, unit="lbs", quantity=randint(1, 200), name=fake.word(), description=fake.sentence(nb_words=10, variable_nb_words=True), price=randint(1, 100), available=True, product_id=i * 100 % 5) db.session.add(u) try: db.session.commit() except IntegrityError: db.session.rollback()
def new_listing(): form = ListingForm() if form.validate_on_submit(): _listing = Listing(title=form.title.data, body=form.body.data, condition=form.condition.data, price=form.price.data, author=current_user) db.session.add(_listing) db.session.commit() # Image upload filename = secure_filename(form.image.data.filename) [filename, ext] = filename.split('.') # ['image', 'png'] instance = 0 db_image = Image.query.filter_by(name=filename).order_by( Image.instance.desc()).first() if db_image and db_image.instance is not None: instance = int(db_image.instance) + 1 location = filename + str(instance) + '.' + ext form.image.data.save( os.path.join(app.config['IMAGES_FOLDER'], location)) image = Image(name=filename, extension=ext, instance=instance, src=location, listing_id=_listing.id) db.session.add(image) db.session.commit() flash('Listing created') return redirect(url_for('listing', id=_listing.id)) return render_template("new_listing.html", title='Create New Listing', form=form)
def post() : form = AddPost() form.set_context() print(form.errors) if form.is_submitted(): print ("submitted") if form.validate(): print ("valid") print(form.errors) if form.validate_on_submit(): new_listing = Listing( db_title=form.title.data, db_state=form.state.data, db_county=form.county.data, db_acres=form.acres.data, db_short=form.short.data, db_long=form.long.data, timestamp=datetime.now() ) db.session.add(new_listing) db.session.commit() print('Land added to database') # db_images = url_for('static', filename='showcase/') return render_template('posts.html', title = "Land for sale", form=form)
def generate_random_listing(drugs, market, min_price, max_price, start_date, end_date, sellers=[], origins=[]): delta = end_date - start_date int_delta = (delta.days * 24 * 60 * 60) + delta.seconds random_delta = randrange(int_delta) date = start_date + timedelta(seconds=random_delta) price = np.random.randint(min_price, max_price) drug = drugs[np.random.randint(0, len(drugs) - 1)] origin = origins[np.random.randint(0, len(origins) - 1)] if origins else None seller = sellers[np.random.randint(0, len(sellers) - 1)] if sellers else None listing = Listing(market=market, drug=drug, price=price, country=origin, seller=seller, date=date) return listing
def get_listings(): page = min(request.args.get('page', 1, type=int), 10) # Limit page and page number to privatize data per_page = min(request.args.get('per_page', 10, type=int), 20) data = Listing.to_collection_dict(Listing.query, page, per_page, 'api.get_listings') return jsonify(data)
def create_listing_by_user(id): # Request Validation if g.current_user.id != id: abort(403) data = request.get_json() or {} # print(data) # if 'name' not in data: # return bad_request('Must include listing\'s name') # if User.query.filter_by(username=data['name']).first(): # return bad_request('please use a different username') # print(data) #print('space: ', data['spaces'], type(data['spaces'])) listing = Listing() print(listing.id) listing.user_id = id listing.from_dict(data, new_listing=True) if 'spaces' in data: listing.spaces = str(data['spaces']) if 'amenities' in data: listing.amenities = str(data['amenities']) if 'house_rules' in data: listing.house_rules = str(data['house_rules']) if 'completed' in data: listing.completed = str(data['completed']) db.session.add(listing) db.session.commit() if 'sleeping_arrangements' in data: # print(data['sleeping_arrangements']) for room_id, room in enumerate(data['sleeping_arrangements']): for type, number in room.items(): _ = ListingSleepArgm() _.listing_id = listing.id _.argm_type = type _.number = number _.room_id = room_id db.session.add(_) db.session.commit() # Create return value for request response = jsonify(listing.to_dict()) response.status_code = 201 #response.headers['Location'] = url_for('api.get_listing', id=listing.id) return response
def get_listings_by_user(id): user = User.query.get_or_404(id) page = request.args.get('page', 1, type=int) per_page = min(request.args.get('per_page', 10, type=int), 100) data = Listing.to_collection_dict(user.listings, page, per_page, 'api.get_listings_by_user', id=id) return jsonify(data)
def new_listing(): form = ListingForm() print(form.name.data) form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): new_listing = Listing( name=form.name.data, description=form.description.data, image_1=form.image_1.data, image_2=form.image_2.data, image_3=form.image_3.data, category_id=form.category_id.data, shop_id=form.shop_id.data, price=form.price.data, ) db.session.add(new_listing) db.session.commit() return new_listing.to_dict() else: return {"errors": "invalid submission"}
def view_item(item_id): form = ListingForm() if form.validate_on_submit(): if current_user.is_authenticated: item = Item.query.filter_by(id=item_id).first() listing = Listing(name=form.name.data, description=form.description.data, image=form.image.data, price=form.price.data, owner=current_user, item=item) db.session.add(listing) db.session.commit() send_updates(item) item = Item.query.filter_by(id=item_id).first() listings = item.item_listings return render_template("listings/item.html", title="Nontrivial - "+item.name, item=item, listings=listings, form=form)
def import_rechem_data(): c = sqlite3.connect('rechem_listings.db') with open('rechem_drug_titles', 'r') as f: s = f.read() drug_title_dict = ast.literal_eval(s) rechem_pages = pd.read_sql_query("SELECT * FROM Listings", c) rechem_listings = pd.read_sql_query("SELECT * FROM Listing_index", c) for i, row in rechem_listings.iterrows(): rechem_listings.loc[i, 'drug'] = drug_title_dict[row['title']] m = Market.query.filter_by(name="rechem_real").first() if not m: m = Market(name="rechem_real") db.session.add(m) db.session.commit() print("market added") listings = [] for i, row in rechem_listings.iterrows(): drug = Drug.query.filter_by(name=row['drug']).first() if not drug: db.session.add(Drug(name=row['drug'])) db.session.commit() #check if listing for this drug exists. if not, add it. listing = Listing.query.filter_by(drug=drug).first() if not listing: listings.append(Listing(url=row['url'], market=m, drug=drug)) if listings: db.session.add_all(listings) db.session.commit() print("Listings added") pages = [] for i, row in rechem_pages.iterrows(): listing = rechem_listings[rechem_listings['id'] == row['listing_index_id']] listing_drug = listing['drug'].item() listing_name = listing['title'].item() drug = Drug.query.filter_by(name=listing_drug).first() listing = Listing.query.filter_by(drug=drug, market=m).first() # check if a page exsits for this time/listing. If not, add it. timestamp = datetime.strptime(row['scraped_time'], "%Y-%m-%d %H:%M:%S") page = Page.query.filter_by(listing=listing, timestamp=timestamp).first() if not page: pages.append(Page(html=row['page_text'], timestamp=timestamp, name=listing_name, listing=listing)) if pages: db.session.add_all(pages) db.session.commit() print("Pages added") return ('', 204)
def addListing(): if current_user.username != 'soupercell': return redirect(url_for('main.index')) else: # print('poop') form = ListingForm() if form.validate_on_submit(): newListing = Listing(title=form.title.data, imageurl=form.imageurl.data, \ weekdayHrs=form.timeopen.data, weekendHrs=form.timeopen2.data, \ description=form.addedInfo.data, upvotes=0, downvotes=0, \ acronym=form.acronym.data, restaurant=form.isRestaurant.data) db.session.add(newListing) db.session.commit() flash('Listing added.') return redirect(url_for('main.dining')) return render_template('auth/admin.html', form=form)
def add_listing(): form = AddListingForm() if form.validate_on_submit(): # See if the resume exists in the Resume table new_resume = Resume.query.filter_by(file_name=form.resume.data, user_id=current_user.id).first() # If it doesn't exist, insert it if new_resume is None: new_resume = Resume(file_name=form.resume.data, user_id=current_user.id) # Add and commit new resume db.session.add(new_resume) db.session.commit() # Do the same thing for cover letter ## Turn this into a helper function later? new_cl = CoverLetter.query.filter_by(file_name=form.cover_letter.data, user_id=current_user.id).first() if new_cl is None: new_cl = CoverLetter(file_name=form.cover_letter.data, user_id=current_user.id) # Add and commit new cl db.session.add(new_cl) db.session.commit() # Create a new listing object w/ form details and insert it listing = Listing(company=form.company.data, title=form.title.data, description=form.description.data, location=form.location.data, date_added=form.date_added.data, resume=new_resume, cover_letter=new_cl, status=form.status.data, user=current_user) db.session.add(listing) db.session.commit() flash( f"Congratulations, you have added a new application for {listing.title} at {listing.company}" ) # jobs = current_user.listings # return render_template('index.html', title='Home', jobs=jobs, form=FilterListingsForm()) return redirect(url_for('login')) return render_template('add_edit_listing.html', title='Add a New Application/Listing!', form=form)
def add_mock_listings(): market = Market.query.filter_by(id=request.form['market_id']).first() drugs = request.form.getlist('drugs[]') listings = [] for d in drugs: drug = Drug.query.filter_by(name=d).first() url = "www.{}.com/mock_data/{}".format(market.name, drug.name) listings.append(Listing(drug=drug, market=market, url=url)) db.session.add_all(listings) db.session.commit() drugs = Drug.query.all() drugs_not_in_market = [ drug for drug in drugs if not Listing.query.filter_by(market=market, drug=drug).first() ] return render_template('_unused_drug_multi_select.html', drugs=drugs_not_in_market)
def add_listing(request): if request.POST: form = ListingForm(data=request.POST, files=request.FILES) formset = ListingProjectFormSet(request.POST) if form.is_valid(): usr = UserProfile.objects.get(user=request.user) k = form.save(commit=False) formset = ListingProjectFormSet(request.POST, instance=k) if formset.is_valid(): l = form.save(commit=True,user=usr) formset.save(commit=True) return HttpResponseRedirect(reverse('view_listing',kwargs={'lid':l.id})) else: form = ListingForm() formset = ListingProjectFormSet(instance=Listing()) return render(request,'add_listing.html',{'form':form,'formset':formset})
def create_listing(): form = CreateListingForm() if form.validate_on_submit(): listing = Listing(title=form.title.data, body=form.body.data, desired_size=form.desired_size.data, owner=current_user) tags = form.tags.data tags = tags.replace(" ", "").lower().split('#') tags = list(OrderedDict.fromkeys(filter(None, tags))) for _tag in tags: tag = ListingTag.query.filter_by(tag=_tag).first() if tag is None: tag = ListingTag(tag=_tag) listing.tags.append(tag) listing.members.append(current_user) db.session.add(listing) db.session.commit() flash('Your listing is now posted!') return redirect(url_for('index')) return render_template('create_listing.html', title='Create a Listing', form=form)
def report_2(city, service_id): g.service_id = service_id g.city = city form = PostForm2() if form.validate_on_submit(): service = Service.query.filter(Service.id == service_id).first() company = form.company.data listing = Listing.query.filter(Listing.company_id == company.id, Listing.service_id == service.id).all() if len(listing) == 0: # If Listing doesn't exist create it listing = Listing(service_id=service.id, company_id=company.id) db.session.add(listing) db.session.commit() else: listing = listing[0] if current_user.is_authenticated: post = Post(body=form.post.data, author=current_user, service_id=service.id, company_id=company.id, price=form.price.data, rating=form.rating.data, listing=listing) else: post = Post(body=form.post.data, service_id=service.id, company_id=company.id, price=form.price.data, rating=form.rating.data, listing=listing) db.session.add(post) db.session.commit() flash('Your report is now live!') return redirect(url_for('search')) return render_template('report.html', title='Report', form3=form)
def import_rechem(): con = sqlite3.connect('app/rechem_listings.db') con.row_factory = sqlite3.Row # returns sqlite3 query result as dict rather than tuple c = con.cursor() c.execute("SELECT * FROM country") countries = c.fetchall() new_countries = [] for row in countries: country = Country(name=row['name'], c2=row['c2']) if not Country.query.filter_by(name=country.name).first(): new_countries.append(country) db.session.add_all(new_countries) db.session.commit() c.execute("SELECT * FROM drug") drugs = c.fetchall() new_drugs = [] for row in drugs: drug = Drug(name=row['name']) if not Drug.query.filter_by(name=drug.name).first(): new_drugs.append(drug) db.session.add_all(new_drugs) db.session.commit() c.execute("SELECT * FROM market") markets = c.fetchall() new_markets = [] for row in markets: market = Market(name=row['name']) if not Market.query.filter_by(name=market.name).first(): new_markets.append(market) db.session.add_all(new_markets) db.session.commit() c.execute("SELECT * FROM listing") listings = c.fetchall() rechem_listings = [ listing for listing in listings if listing['market_id'] == '4' ] rechem_ids = [d['id'] for d in rechem_listings] new_listings = [] for row in rechem_listings: new_market_id = Market.query.filter_by(name="Rechem").first().id drug_name = [d for d in drugs if d['id'] == int(row['drug_id'])][0]['name'] new_drug_id = Drug.query.filter_by(name=drug_name).first().id # TODO: this is required for sqlite, but may or may not work with sqlalchemy time_format = "%Y-%m-%d %H:%M:%S.%f" timestamp = datetime.strptime(row['timestamp'], time_format) listing = Listing(url=row['url'], seller=None, timestamp=timestamp, market_id=new_market_id, drug_id=new_drug_id, origin_id=None) if not Listing.query.filter_by(url=listing.url).first(): new_listings.append(listing) db.session.add_all(new_listings) db.session.commit() c.execute("SELECT * FROM page") pages = c.fetchall() rechem_pages = [page for page in pages if page['listing_id'] in rechem_ids] new_pages = [] for row in rechem_pages: listing_url = [ d for d in listings if d['id'] == int(row['listing_id']) ][0]['url'] new_listing_id = Listing.query.filter_by(url=listing_url).first().id # TODO: this is required for sqlite, but may or may not work with sqlalchemy time_format = "%Y-%m-%d %H:%M:%S.%f" timestamp = datetime.strptime(row['timestamp'], time_format) page = Page(name=row['name'], html=row['html'], timestamp=timestamp, listing_id=new_listing_id) if not Page.query.filter_by(listing_id=page.listing_id, timestamp=page.timestamp).first(): new_pages.append(page) else: print("page already found:") db.session.add_all(new_pages) db.session.commit() return "", 204
def all_listings(pet_types=None, activities=None, zip_code=None, datetime_range=None): """ Returns a list of all available Listings in the database, filtered by the given parameters. Parameters ---------- pet_types : list or tuple of str or None, optional Filters Listings for pet type in list of pet types *pet_types*, or does not filter if unspecified/None. activities : list or tuple of str or None, optional Filters Listings for those for which every activity is satisfied in the *activities* parameter, or does not filter is unspecified/None. zip_code : str or None, optional Filters Listings for zip code *containing zip_code*, or does not filter if unspecified/None. datetime_range : tuple of datetime or None, optional Filters Listings by those that match the *datetime_range* parameter. Must be either None/unspecified or a tuple of two datetimes, the first one being the start datetime and the second being the end datetime. Looks for listings whose datetime ranges fall completely within the range if *full_time* of the Listing is true, or datetime ranges that intersect with *datetime_range* if *full_time* is False. Returns ------- list of Listing A list of Listings that match the specified paremeters (described above). Raises ------ TypeError If any of the parameters are not of the type described in Parameters above, or if any of the values in *activities*, *pet_types*, or *datetime_range* are not of type str, str, or datetime, respectively. ValueError If datetime_range is a tuple that does not contain exactly 2 datetimes, the second of which is a datetime that is after the first. If a pet type in pet_types is not one of the predefined pet types (defined in enums.py) If an activity in activities is not one of the predefined activities (defined in enums.py) Examples -------- >>> db_service.all_listings(pet_type = 'Dog', activities = ['Walking'], zip_code = '08540') [<Listing ID=15>] """ if pet_types != None: if type(pet_types) != list and type(pet_types) != tuple: raise TypeError( 'pet_type should be a parameter of type None, tuple, or list') for pet_type in pet_types: if type(pet_type) != str: raise TypeError('pet_types tuple/list should only contain str') if pet_type not in enums.pet_types: raise ValueError( 'Pet Type {0} is not in the list of valid pet types {1}'. format(pet_type, enums.pet_types)) if activities != None: if type(activities) != list and type(activities) != tuple: raise TypeError( 'activities should be a parameter of type None, tuple or list') for activity in activities: if type(activity) != str: raise TypeError( 'activities tuple/list should only contain str') if activity not in enums.activities: raise ValueError( 'Activity {0} is not in the list of valid activities {1}'. format(activity, enums.activities)) if type(zip_code) != str and zip_code != None: raise TypeError('zip_code should be a parameter of type None or str') if datetime_range != None: if type(datetime_range) != tuple: raise (TypeError( 'datetime_range should be a parameter of type None or tuple')) if len(datetime_range) != 2: raise ValueError( 'datetime_range should contain exactly 2 elements, not {0}'. format(len(datetime_range))) for time in datetime_range: if type(time) != datetime: raise TypeError( 'datetime_range tuple should only contain datetimes') startTime = datetime_range[0] endTime = datetime_range[1] if startTime >= endTime: raise ValueError( 'start time must be before end time (in datetime_range)') query = Listing.query if pet_types != None: query = query.filter(Listing.pet_type_is_in(pet_types)) if activities != None: query = query.filter(Listing.activities_satisfied(activities)) if zip_code != None: query = query.filter(Listing.zip_code_contains(zip_code)) if datetime_range != None: query = query.filter(Listing.datetime_range_matches(*datetime_range)) return query.all()
import pandas as pd from app import app, db from app.models import Listing raw_data = pd.read_csv('77005data.csv') for i, row in raw_data.iterrows(): print(i) listing = Listing(address=row['address'], price=row['price'] ,description=row['description'], zipcode=row['zipcode'], year=row['yearbuilt'], building_sqft=row['buildingsqft']) db.session.add(listing) try: db.session.commit() except: db.session.rollback()
def sf4fefffdsf(): c = sqlite3.connect('app/rechem_listings.db') countries = pd.read_sql_query("SELECT * FROM country", c) new_countries = [] for i, row in countries.iterrows(): country = Country(name=row['name'], c2=row['c2']) if not Country.query.filter_by(name=country.name).first(): new_countries.append(country) db.session.add_all(new_countries) db.session.commit() drugs = pd.read_sql_query("SELECT * FROM drug", c) new_drugs = [] for i, row in drugs.iterrows(): drug = Drug(name=row['name']) if not Drug.query.filter_by(name=drug.name).first(): new_drugs.append(drug) db.session.add_all(new_drugs) db.session.commit() markets = pd.read_sql_query("SELECT * FROM market", c) new_markets = [] for i, row in markets.iterrows(): market = Market(name=row['name']) if not Market.query.filter_by(name=market.name).first(): new_markets.append(market) db.session.add_all(new_markets) db.session.commit() listings = pd.read_sql_query("SELECT * FROM listing", c) rechem_listings = listings[listings['market_id'] == '4'] new_listings = [] for i, row in rechem_listings.iterrows(): market_name = markets[markets['id'] == int( row['market_id'])]['name'].item() new_market_id = Market.query.filter_by(name=market_name).first().id drug_name = drugs[drugs['id'] == int(row['drug_id'])]['name'].item() new_drug_id = Drug.query.filter_by(name=drug_name).first().id # TODO: this is required for sqlite, but may or may not work with sqlalchemy time_format = "%Y-%m-%d %H:%M:%S.%f" timestamp = datetime.strptime(row['timestamp'], time_format) listing = Listing(url=row['url'], seller=None, timestamp=timestamp, market_id=new_market_id, drug_id=new_drug_id, origin_id=None) if not Listing.query.filter_by(url=listing.url).first(): new_listings.append(listing) db.session.add_all(new_listings) db.session.commit() # Get all pages with a listing id that is from the rechem market pages = pd.read_sql_query("SELECT * FROM page", c) rechem_pages = pages[pages['listing_id'].isin(rechem_listings['id'])] new_pages = [] for i, row in rechem_pages.iterrows(): listing_url = listings[listings['id'] == int( row['listing_id'])]['url'].item() new_listing_id = Listing.query.filter_by(url=listing_url).first().id # TODO: this is required for sqlite, but may or may not work with sqlalchemy time_format = "%Y-%m-%d %H:%M:%S.%f" timestamp = datetime.strptime(row['timestamp'], time_format) page = Page(name=row['name'], html=row['html'], timestamp=timestamp, listing_id=new_listing_id) if not Page.query.filter_by(listing_id=page.listing_id, timestamp=page.timestamp).first(): new_pages.append(page) else: print("page already found:") db.session.add_all(new_pages) db.session.commit() return "data successfully added"
def new_listing(): """ Processes form data in POST request from listing creation page and adds the listing to the database table Listing. The profile photo associated with the user is recorded in the column "photo" in the Profile table. It is stored as <hash>.<file_extension> where <hash> is a hash is a hash of the uploaded photo and <file_extension> is...well, the file extension. The actual photo file is stored as app/photos/<hash>.<file_extension> """ # Get logged in user information net_id = session.get(app.config['CAS_USERNAME_SESSION_KEY'], None) user = Profile.query.filter_by(net_id=net_id).first() # Fields from listing form fields = [ "apartment_name", "description", "address_line_1", "address_line_2", "distance", "rent", "rent_details", "property_size", "number_roommates_needed", "amenities_gym", "amenities_pool", "amenities_pet_friendly", "amenities_computer_room", "amenities_trash_pickup_services" ] # Get user-entered values from form values = {} i = 1 for field in fields: i += 1 values[field] = request.form[field] # Uploaded apartment pictures photos = request.files.getlist('photos[]') # The user selected a photo of an invalid file extension # Redirect the user to an error page for photo in photos: if photo and not allowed_file(photo.filename): data = { "net_id": values["net_id"], "name": values["name"], "year": values["year"], "dob": values["dob"], "college": values["college"], "gender": values["gender"], "bio": values["bio"], "facebook": values["facebook"], "error": "Error: invalid photo file extension ." + str(file_extension(photo.filename)) } # TODO: Make this more elegant return "Sorry, the file extension " + str( file_extension(photo.filename)) + " is not permitted" photo_hashes = [] # Store the user's profile photos on the server for photo in photos: if photo and allowed_file(photo.filename): # Create hash of the uploaded picture photo_hashes.append(str(hash(photo))) filename = secure_filename( photo_hashes[-1]) + "." + file_extension(photo.filename) photo.save( os.path.join(app.config['UPLOAD_FOLDER'] + "/listings", filename)) photo_hashes[-1] += "." + file_extension(photo.filename) print photo_hashes net_id = session.get(app.config['CAS_USERNAME_SESSION_KEY'], None) if net_id is not None: user = Profile.query.filter_by(net_id=net_id).first() print("netid = " + net_id) # Convert unicodes corresponding to numbers into floats or integers values["distance"] = float( str(values["distance"].replace(",", "").split(" ")[0])) values["rent"] = float(str(values["rent"])) values["property_size"] = int(str(values["property_size"])) values["number_roommates_needed"] = int( str(values["number_roommates_needed"])) # Process amenities checkboxes to be consistent with db format - 'true'/'false' (string) values["amenities_gym"] = "true" if str( values["amenities_gym"]) == "on" else "false" values["amenities_pool"] = "true" if str( values["amenities_pool"]) == "on" else "false" values["amenities_pet_friendly"] = "true" if str( values["amenities_pet_friendly"]) == "on" else "false" values["amenities_computer_room"] = "true" if str( values["amenities_computer_room"]) == "on" else "false" values["amenities_trash_pickup_services"] = "true" if str( values["amenities_trash_pickup_services"]) == "on" else "false" # Get Yelp review information (review_url, review_rating, review_snippet) = get_yelp_reviews(values["address_line_1"] + ", " + values["address_line_2"]) review_snippet = review_snippet.replace('\n', ' ').replace('\r', '') # Create a new listing from the Listing model listing = Listing( net_id, values["apartment_name"], values["description"], values["address_line_1"], values["address_line_2"], values["distance"], values["rent"], values["rent_details"], values["property_size"], values["number_roommates_needed"], universal.timestamp().split(" ")[0], review_url, review_rating, review_snippet, values["amenities_gym"], values["amenities_pool"], values["amenities_pet_friendly"], values["amenities_computer_room"], values["amenities_trash_pickup_services"]) # Add this new listing to the database db.session.add(listing) db.session.commit() print("listing id") print listing.id # Create new photo db columns based on Photo model and save them in the database new_photos = [ Photo(photo_hash, net_id, listing.id) for photo_hash in photo_hashes ] db.session.add_all(new_photos) db.session.commit() return redirect('/listing/' + str(listing.id))
def get_listings(): page = request.args.get('page', 1, type=int) per_page = min(request.args.get('per_page', 10, type=int), 100) data = Listing.to_collection_dict(Listing.query, page, per_page, 'api.get_listings') return jsonify(data)
def listing_new_endpoint(): logger.trace('User', current_user.id, 'attempting to create new listing with form values', str(request.form)) if not current_user.is_owner: logger.info('Non-owner {0} attempted to create a listing'.format( current_user.id)) return redirect( url_for('error', error='User must be owner to create a listing')) activities = [] for activity in enums.activities: if request.form.get('activity_{0}'.format(activity.lower().replace( ' ', '_'))) == 'true': activities.append(activity) pet_name = request.form.get('pet_name') # split and construct start_date start_date = request.form.get('start_date') start_time = request.form.get('start_time') start_date_array = start_date.split('/') start_time_array = start_time.split(':') start = datetime(int(start_date_array[2]), int(start_date_array[0]), int(start_date_array[1]), int(start_time_array[0]), int(start_time_array[1])) # split and construct end_date end_date = request.form.get('end_date') end_time = request.form.get('end_time') end_date_array = end_date.split('/') end_time_array = end_time.split(':') end = datetime(int(end_date_array[2]), int(end_date_array[0]), int(end_date_array[1]), int(end_time_array[0]), int(end_time_array[1])) pet_type = request.form.get('pet_type') zip_code = request.form.get('zip_code') lat = request.form.get('lat') lng = request.form.get('lng') try: lat = float(lat) lng = float(lng) except Exception as e: return redirect( url_for('error', error='Please use autocomplete for address input.')) address_id = request.form.get('address_id') address_str = request.form.get('address_input') extra_info = request.form.get('extra_info') pet_image_url = request.form.get('pet_image_url') if pet_image_url == '': pet_image_url = None listing = Listing(pet_name=pet_name, pet_type=pet_type, start_time=start, end_time=end, full_time=True, zip_code=zip_code, lat=lat, lng=lng, address_id=address_id, address_str=address_str, pet_image_url=pet_image_url, extra_info=extra_info, activities=activities, user_id=current_user.id) try: logger.debug( 'Attempting to persist listing with fields: (pet_name={0},pet_type={1},start_time={2},end_time={3},full_time={4},zip_code={5},lat={6},lng={7},address_id={8},address_str={9},pet_image_url={10},extra_info={11},activities={12},user_id={13})' .format(pet_name, pet_type, start.isoformat(), end.isoformat(), True, zip_code, lat, lng, address_id, address_str, pet_image_url, extra_info, activities, current_user.id)) new_listing = db_service.create_listing(listing) if type(new_listing) != str: logger.info('Listing created for user {0} with id {1}'.format( current_user.id, new_listing.id)) return redirect( url_for('listing_details', listing_id=new_listing.id)) else: logger.warn('Listing creation failed for user {0}: {1}'.format( current_user.id, new_listing)) return redirect( url_for( 'error', error='Listing creation failed: {0}'.format(new_listing))) except Exception as e: logger.warn('Listing creation failed for user {0}: {1}'.format( current_user.id, str(e))) return redirect( url_for('error', error='Listing creation failed: {0}'.format(str(e))))
def seed_listings(): # EucalyptusBlooms listing1 = Listing( name= "Petite 15 Stem Eucalyptus Bouquet | Short Stems | Aromatic Scent | Therapeutic | Relaxation | Floral Bouquet | Decongest", description= "Fresh petite short stemmed eucalyptus great for a short, wide vase or bowl. This 12 stem bunch is great for display in your kitchen, bathroom or end table.", image_1= "https://i.etsystatic.com/22078381/r/il/fd7b85/2196412465/il_1588xN.2196412465_1w9e.jpg", image_2= "https://i.etsystatic.com/22078381/r/il/f9e3f2/2424632030/il_794xN.2424632030_ff4v.jpg", image_3= "https://i.etsystatic.com/22078381/r/il/5375a4/2424591528/il_794xN.2424591528_bsu1.jpg", shop_id=1, price=10.00) listing2 = Listing( name= "Large Fresh Eucalyptus Bunch | Huge 20 Stems | Aromatic Scent | Therapeutic | Relaxation | Decongestant | Eucalyptus Bouquet | Fresh Flowers", description= "Stunning large bunch of fresh eucalyptus with 20 stems. Fresh bouquets straight from the farm. Perfect home accent to place in your favorite large opening vase.", image_1= "https://i.etsystatic.com/22078381/r/il/08a28a/2309671307/il_1588xN.2309671307_i4vf.jpg", image_2= "https://i.etsystatic.com/22078381/r/il/3e3940/2148757282/il_794xN.2148757282_650v.jpg", image_3= "https://i.etsystatic.com/22078381/r/il/1859ee/2197085491/il_794xN.2197085491_rxz6.jpg", shop_id=1, price=20.00) listing3 = Listing( name= "Large Fresh Shower Eucalyptus & Lavender Bundle | Aromatherapy | Cold, Sinuses and Congestion Relief | Relax and Refresh | House Plants", description= "If you've tried and enjoyed a fresh eucalyptus bunch in the shower, the aromatic addition of dried lavender will take your shower to the next level! Each bundle is tightly wrapped with ivory twine, leaving a loop for product hanging. A sleek stainless steel self adhesive hook is included for easy application and display.", image_1= "https://i.etsystatic.com/22078381/r/il/194e65/2714402477/il_1588xN.2714402477_nbrr.jpg", image_2= "https://i.etsystatic.com/22078381/r/il/dbba07/2698336805/il_794xN.2698336805_boh0.jpg", image_3= "https://i.etsystatic.com/22078381/r/il/2b67e8/2698336653/il_794xN.2698336653_aevz.jpg", shop_id=1, price=24.00) listing4 = Listing( name= "Lavender Loofah Soap | Fresh Lavender | Lavender & Tea Tree Oils | Built In Loofah | Exfoliation | Extreme Hydration | Shave Legs", description= "Fresh lavender soap bar with a “built in” loofah. The perfect combo! Handmade using: Fresh lavender, Goats milk, Lavender essential oil, Tea tree essential oil, Homegrown exfoliating loofah", image_1= "https://i.etsystatic.com/22078381/r/il/741a47/2585030975/il_794xN.2585030975_21jv.jpg", image_2= "https://i.etsystatic.com/22078381/r/il/d10624/2537383618/il_794xN.2537383618_v4hy.jpg", image_3= "https://i.etsystatic.com/22078381/r/il/ec0e7c/2585030921/il_794xN.2585030921_5p3q.jpg", shop_id=1, price=12.00) listing5 = Listing( name= "Dried Lavender Stems | Fresh Flowers | Lavender Bunch | English Lavender |Table Decor | Fresh Lavender | Lavender Plant | Boho Decor", description= "Beautiful Lavender bunch with approximately 100 stems of dried english lavender that are around 14 inches in length. It is grown right here at home in North Carolina giving it a beautiful purple hue and a smell that will truly make you happy. Our stems are dried for maximum aroma released and it also helps keep them lasting for months!", image_1= "https://i.etsystatic.com/22078381/r/il/620f7e/2436253723/il_1588xN.2436253723_1k4s.jpg", image_2= "https://i.etsystatic.com/22078381/r/il/8df223/2388636090/il_794xN.2388636090_3pt0.jpg", image_3= "https://i.etsystatic.com/22078381/r/il/1f62c9/2378227828/il_794xN.2378227828_n0ws.jpg", shop_id=1, price=16.00) # thenewplantco listing6 = Listing( name="Alocasia zebrina", description= "In time, plants can grow to just over 5 feet tall and equally as wide. Their creamy petioles are covered with brownish bands before ending in a triangular, spade shaped leaf. Being native to a rainforest in the Philippines, they do appreciate high relative humidity with an ideal range of ~70%, or more. High humidity is not a must for this species. But, as with most Alocasia, this species does enjoy being watered regularly and does not tolerate drying out too much. If plants do dry out, dried and yellowing leaf tips will develop.", image_1= "https://i.etsystatic.com/21880724/r/il/e2067a/2978070410/il_1588xN.2978070410_f7ft.jpg", image_2= "https://i.etsystatic.com/21880724/r/il/6b61e4/2978071966/il_794xN.2978071966_iszb.jpg", image_3="", shop_id=2, price=27.00) listing7 = Listing( name="Sansevieria cylindrica - 5 Pack", description= "Sansevieria cylindrica is one of the more elegant species due to how “clean” the foliage lines are. It’s ideal for a great many situations, but lends itself perfectly to creating a mini screen of sorts. While this species isn’t commonly seen in the US, especially at this size, it certainly doesn’t mean it’s not as easy to care for as most Sansevieria species.", image_1= "https://i.etsystatic.com/21880724/r/il/2ed2a1/3012618977/il_1588xN.3012618977_ek5h.jpg", image_2= "https://i.etsystatic.com/21880724/r/il/b80fcb/2964915186/il_794xN.2964915186_5q26.jpg", image_3= "https://i.etsystatic.com/21880724/r/il/d93646/2964916034/il_794xN.2964916034_1biy.jpg", shop_id=2, price=18.00) listing8 = Listing( name="Polyscias fruiticosa ‘Aurea Variegata’ - Golden Ming Aralia", description= "If your plant collection isn’t dripping in gold, you need to add a Golden Ming! Quite seriously one of our favorite plants to use in interiorscapes due to how well they thrive in low light levels, but also tolerate fairly high levels. We grow ours under higher light so the golden variegation really comes through at its finest.", image_1= "https://i.etsystatic.com/21880724/r/il/93d5fd/2961363944/il_1588xN.2961363944_1h2b.jpg", image_2= "https://i.etsystatic.com/21880724/r/il/ff4164/3009070975/il_794xN.3009070975_phmy.jpg", image_3="", shop_id=2, price=36.00) listing9 = Listing( name="Calathea ‘Fusion White’ - Cosmetically Damaged", description= "Where do we even begin with those one?! It has ALL the colors and patterns you could want: white, purple, and green streaked on every leaf with no two being the same. Calathea, in general and this is no exception, require consistently moist media without sitting in water. We recommend watering 2-3 times a week and providing dappled or morning sunlight only. If you’re worried about overwatering, check out our Aroid Pro Mix. It drains really well, yet holds plenty of moisture for the plants. We grow 90 % of our plants in that mix!", image_1= "https://i.etsystatic.com/21880724/r/il/3b9f17/2334624323/il_1588xN.2334624323_cwf4.jpg", image_2="", image_3="", shop_id=2, price=20.00) listing10 = Listing( name="Macodes petola / Single Plug", description= "This Jewel Orchid is so called because of the metallic gold veins running throughout the vibrant green foliage. Contrary to popular belief, these orchids are relatively easy to grow! If you're an experienced plant grower, you should give yourself a bit of a challenge and try growing these. Just keep in mind that they are relatively slow growing so don't expect them to take off. Slow and steady is their motto.", image_1= "https://i.etsystatic.com/21880724/r/il/d4fc5e/2243106369/il_1588xN.2243106369_2yb2.jpg", image_2="", image_3="", shop_id=2, price=16.00) # TropicalTouchPlants listing11 = Listing( name="Air Plant Xerographica Medium", description= 'Medium Xerographica are approximately 5"-7" inches wide.Xerographica are known as the "Queen of Air Plants". They are the quintessential air plant due to their beautiful curly leaf structure and amazing bloom spike.', image_1= "https://i.etsystatic.com/23670694/r/il/289e82/2355122334/il_1588xN.2355122334_nffe.jpg", image_2="", image_3="", shop_id=3, price=14.95) listing12 = Listing( name="Air Plant 3 pc. Abdita / Juncifolia pack", description= "This 3 plant variety pack comes with one green Abdita, One red Abdita(enchanced with floral tint) and one Juncifolia. This unique combination allows for the perfect contrast in color and texture that will allow you to create your own unique designs or just add variety to your collection. The two rosette shaped Abditas are approximately 3 inches wide and the grass like foliage of the Juncifolia stands approximately 4 to 5 inches tall.", image_1= "https://i.etsystatic.com/23670694/r/il/c8ac5f/2647949081/il_1588xN.2647949081_4fa7.jpg", image_2="", image_3="", shop_id=3, price=8.95) listing13 = Listing( name="Air Plant Tectorum Medium", description= "Tectorum medium size ranges from 2-3 inches wide. Although small it will be the talk of your arrangement or collection. These fuzzy and silver in color plants will make their presence known. The Tectorum from Ecuador grows high in the mountains of Ecuador and Peru. Its appearance is fuzzy and silver, due to its abundance of trichomes, which help protect it from the sun as well as gather moisture and nutrients from the air. This xeric Tillandsia like lots of air movement, bright sun-light, and low humidity. These fuzzy snow-ball looking plants should not be soaked, but rather just misted from time to time with water.", image_1= "https://i.etsystatic.com/23670694/r/il/b911ee/2594482708/il_1588xN.2594482708_azeg.jpg", image_2= "https://i.etsystatic.com/23670694/r/il/7f6d5e/2594483234/il_794xN.2594483234_8dgp.jpg", image_3="", shop_id=3, price=7.95) listing14 = Listing( name="Xerographica With Metal Air Plant Holder", description= "The Xerographica with its curly unique shape is the perfect plant for this modern planter. The metal planter stands 12 inches tall and is made specifically to display air plants.", image_1= "https://i.etsystatic.com/23670694/r/il/9553fd/2553488879/il_1588xN.2553488879_dgxv.jpg", image_2="", image_3="", shop_id=3, price=19.95) listing15 = Listing( name="Air Plant Capitata Maroon Jumbo", description= "Jumbo Capitata Maroon is a mature specimen ranging from 14” - 16” wide. Also availble in small size at about 8 inches tall. This colorful species of Tillandsia has thick green leaves that blush maroon towards the center. These large growing plants will keep their maroon color if displayed in an area of bright light.", image_1= "https://i.etsystatic.com/23670694/r/il/cf0194/2402807291/il_1588xN.2402807291_1ba7.jpg", image_2= "https://i.etsystatic.com/23670694/r/il/740c0d/2535981947/il_794xN.2535981947_hhqt.jpg", image_3="", shop_id=3, price=9.95) # ElementalBonsaiGardn listing16 = Listing( name= "Small Giraffe Planter with mini palm or Hypoestes, ferns, animal pottery, wedding favor, baby shower, House warming,holiday, birthday gift", description= "Small Giraffe Planter with mini palm, animal pottery, wedding favor, baby shower, House warming,holiday, birthday gift.", image_1= "https://i.etsystatic.com/18504939/r/il/8a7299/1776946693/il_1588xN.1776946693_1l3q.jpg", image_2="", image_3="", shop_id=4, price=16.00) listing17 = Listing( name= "Juniper live Bonsai Tree in a 7 inch Bonsai pot, outdoor plant, informal upright style, Housewarming and Unique birthday gift.", description= "Juniper live Bonsai Tree in a 7 inch Bonsai pot, outdoor plant, informal upright style, Housewarming and Unique birthday gift.", image_1= "https://i.etsystatic.com/18504939/r/il/7e1d08/2982812714/il_1588xN.2982812714_qrvk.jpg", image_2= "https://i.etsystatic.com/18504939/r/il/833dc7/3030528659/il_794xN.3030528659_jp0g.jpg", image_3="", shop_id=4, price=59.00) listing18 = Listing( name= "Begonia 'Harmony's Red Robin' (Begonia rex hybrid) Indoor or outdoor plants 4 inch pot, dish garden, Fairy Garden, bright rich color", description= "'Red Robin'It's colors are very rich with black, gray, red and chocolate brown. Begonias favor bright filtered light with no exposure to harsh midday sun. They need good ventilation to help prevent fungal diseases.", image_1= "https://i.etsystatic.com/18504939/r/il/139973/2571788175/il_1588xN.2571788175_de88.jpg", image_2= "https://i.etsystatic.com/18504939/r/il/bf4204/2571788541/il_794xN.2571788541_1efd.jpg", image_3= "https://i.etsystatic.com/18504939/r/il/e28300/2571788583/il_794xN.2571788583_8q1g.jpg", shop_id=4, price=9.00) listing19 = Listing( name= "Patio fruit tree, banana, pineapple, figs,passion fruit, mulberry, black berry. indoor outdoor plant, unique gift", description= "Patio fruit tree, banana, pineapple, figs, passion fruit, mulberry, black berry. indoor outdoor plant, unique gift. limited quantity, unique gift. Come with instruction care tag specific to each plant! Most of them can produce fruit in 1 or 2 years. You can plant these trees in a container and just have them on your patio. These are all self-fertile, meaning there is no need for cross-pollination to produce fruits. Late Spring and Early Summer is a great time to start!", image_1= "https://i.etsystatic.com/18504939/r/il/71a9ec/1932957183/il_1588xN.1932957183_a4x4.jpg", image_2= "https://i.etsystatic.com/18504939/r/il/22ce9a/1885421000/il_794xN.1885421000_gqxu.jpg", image_3= "https://i.etsystatic.com/18504939/r/il/ca99d3/2979044765/il_794xN.2979044765_svda.jpg", shop_id=4, price=14.99) listing20 = Listing( name= "Bonsai live tree Green Island Ficus in a 4 inch grow pot, indoor or outdoor tree, Housewarming and Unique birthday, Holiday Gift", description= "Bonsai live tree Green Island Ficus, indoor or outdoor tree, Housewarming and Unique birthday, Holiday Gift.", image_1= "https://i.etsystatic.com/18504939/r/il/190786/2828612283/il_1588xN.2828612283_d6dp.jpg", image_2= "https://i.etsystatic.com/18504939/r/il/6ee289/2828612085/il_794xN.2828612085_99u5.jpg", image_3="", shop_id=4, price=16.00) # IntoThePot listing21 = Listing( name="Escargot Rex Begonia starter plant in 4” pot", description= "Begonia Rex escargot plants have striking swirls of colors through their foliage. These were fully rooted 2” plugs recently uppotted into 4” pots. This listing is for one plant in a 4” pot.", image_1= "https://i.etsystatic.com/23984094/r/il/85516c/2962916013/il_1588xN.2962916013_iv79.jpg", image_2= "https://i.etsystatic.com/23984094/r/il/4312c5/2915229032/il_794xN.2915229032_chcm.jpg", image_3= "https://i.etsystatic.com/23984094/r/il/754fff/2962916011/il_794xN.2962916011_m9ni.jpg", shop_id=5, price=15.00) listing22 = Listing( name="Variegated Hoya carnosa compacta Hoya hindu rope 4”", description= "Hoya carnosa compacta Variegata, or variegated Hoya hindu rope plant. This listing is for one plant in a 4” pot.", image_1= "https://i.etsystatic.com/23984094/r/il/07ae6c/2810994669/il_794xN.2810994669_1nta.jpg", image_2= "https://i.etsystatic.com/23984094/r/il/546832/2709993112/il_794xN.2709993112_4bjn.jpg", image_3= "https://i.etsystatic.com/23984094/r/il/bf462d/2763306542/il_794xN.2763306542_8pdv.jpg", shop_id=5, price=50.00) listing23 = Listing( name="String of pearls in 4” pot", description="String of pearls in 4” pot", image_1= "https://i.etsystatic.com/23984094/r/il/8c939e/2865578626/il_1588xN.2865578626_bjh4.jpg", image_2= "https://i.etsystatic.com/23984094/r/il/00665c/2913258945/il_794xN.2913258945_obvm.jpg", image_3= "https://i.etsystatic.com/23984094/r/il/c50876/2865578870/il_794xN.2865578870_lu9q.jpg", shop_id=5, price=13.00) listing24 = Listing( name="White butterfly syngonium 4” pot", description="Syngonium white butterfly starter plant in 4” pot", image_1= "https://i.etsystatic.com/23984094/r/il/650950/2763437364/il_1588xN.2763437364_cxsi.jpg", image_2= "https://i.etsystatic.com/23984094/r/il/ea282d/2763437246/il_794xN.2763437246_by0m.jpg", image_3= "https://i.etsystatic.com/23984094/r/il/1a1daa/2811125871/il_794xN.2811125871_9hpy.jpg", shop_id=5, price=6.00) listing25 = Listing( name="African violet with blue purple flowers in 4” pot", description="", image_1= "https://i.etsystatic.com/23984094/r/il/172db3/2954072178/il_794xN.2954072178_om1n.jpg", image_2= "https://i.etsystatic.com/23984094/r/il/6f813f/3001778855/il_1588xN.3001778855_qzuz.jpg", image_3="", shop_id=5, price=14.00) # TwistedAcres listing26 = Listing( name= "Air Plant Iona 3 for 1 Deal Airplant, Tillandsia, wholesale, Bulk, Sale, Wedding Favors, Terrariums", description= "You order one you get a total of three iona plants you can't go wrong. We will pick you out three of our very best Iona air plants for you.", image_1= "https://i.etsystatic.com/6434562/r/il/f67754/324649642/il_1588xN.324649642.jpg", image_2= "https://i.etsystatic.com/6434562/r/il/34c5b2/324649994/il_794xN.324649994.jpg", image_3="", shop_id=6, price=4.15) listing27 = Listing( name= "Hot Pink Capitata Airplant, Tillandsia, wholesale, Bulk, Sale, Wedding Favors, Terrariums", description= "Color is an organic enhancement. Color will last as long as an average color change of an air plant 1-2 months minimum if not longer.", image_1= "https://i.etsystatic.com/6434562/r/il/9f4408/747783562/il_1588xN.747783562_604d.jpg", image_2="", image_3="", shop_id=6, price=5.99) listing28 = Listing( name= "Air Plant WHOLESALE Mix quantity of your choice Airplant, Tillandsia, wholesale, Bulk, Sale, Wedding Favors, Terrariums", description= "Easy care!!! Do not put in soil. Can put in any container glass, wire, plate, metal, stone, wood, the ideas are endless as long as it is waterproof and not made of copper Can be grown outside in warmer temperatures, partial shade or bright indirect light. Place in your favorite tree next to your hammock. Water weekly.", image_1= "https://i.etsystatic.com/6434562/r/il/ead643/1664098565/il_1588xN.1664098565_qsz8.jpg", image_2= "https://i.etsystatic.com/6434562/r/il/d94006/1647559340/il_794xN.1647559340_kptm.jpg", image_3= "https://i.etsystatic.com/6434562/r/il/07f027/1647560464/il_794xN.1647560464_1ub5.jpg", shop_id=6, price=6.00) listing29 = Listing( name= "Air Plant Small medusa Airplant, Tillandsia, wholesale, Bulk, Sale, Wedding Favors, Terrariums", description= "Small medusa. Wonderfully fun, whimsical and fascinating plant. Will eventually bloom red and purple.", image_1= "https://i.etsystatic.com/6434562/r/il/c21431/762336863/il_1588xN.762336863_eewh.jpg", image_2= "https://i.etsystatic.com/6434562/r/il/e24958/762215560/il_794xN.762215560_n4vo.jpg", image_3="", shop_id=6, price=2.85) listing30 = Listing( name="Air Plant large stricta hybrid", description= "Large stricta hybrid. Beautiful plant with large bloom and velvet soft leaves.", image_1= "https://i.etsystatic.com/6434562/r/il/95be63/1587497839/il_1588xN.1587497839_8p0d.jpg", image_2= "https://i.etsystatic.com/6434562/r/il/ad0b1e/649290028/il_794xN.649290028_1kod.jpg", image_3= "https://i.etsystatic.com/6434562/r/il/fef43a/1540032696/il_794xN.1540032696_hibz.jpg", shop_id=6, price=9.00) # 9Tree7 listing31 = Listing( name="Mini Potted Red Prayer Plant in Terra-Cotta - Maranta Leuconeura", description= "Looking for a plant to go with the flow? Look no further than the prayer plant! Prayer plants move their leaves in accordance to the time of day and light available, similar to praying hands!", image_1= "https://i.etsystatic.com/12134093/r/il/02953c/2923249270/il_1588xN.2923249270_cs6o.jpg", image_2= "https://i.etsystatic.com/12134093/r/il/198d8f/2923249608/il_794xN.2923249608_8i0t.jpg", image_3="", shop_id=7, price=6.00) listing32 = Listing( name= "Coffee Plant - Coffee Arabica Plant in Terra-cotta Pot Mini Plant", description= "Love coffee? Love plants? This is a must-have! This coffee plant is fully rooted and planted in a 2.5 inch terra-cotta pot! The plant will arrive packaged with care instructions to allow it to grow into a large, happy plant.", image_1= "https://i.etsystatic.com/12134093/r/il/d673e9/2903337026/il_1588xN.2903337026_jbi6.jpg", image_2= "https://i.etsystatic.com/12134093/r/il/139e9d/2951021377/il_794xN.2951021377_179r.jpg", image_3="", shop_id=7, price=6.50) listing33 = Listing( name= "Monstera Adansonii Narrow Form RARE - Little Swiss Cheese Plant Fully Rooted", description= "This monstera adansonii is fully rooted and planted in a 2.5 inch terra-cotta pot! The plant will arrive packaged with care instructions to allow it to grow into a large, happy plant.", image_1= "https://i.etsystatic.com/12134093/r/il/654688/2951087133/il_1588xN.2951087133_rw6v.jpg", image_2="", image_3="", shop_id=7, price=7.00) listing34 = Listing( name= "Mini Potted Marble Queen Pothos in Terra-Cotta - Epipremnum Aureum Devil's Ivy", description= "This pothos is fully rooted and planted in a 2.5 inch grey clay pot! The plant will arrive packaged with care instructions to allow it to grow into a large, happy plant.", image_1= "https://i.etsystatic.com/12134093/r/il/bd89db/2970898695/il_1588xN.2970898695_18uw.jpg", image_2= "https://i.etsystatic.com/12134093/r/il/7c8563/2970899227/il_794xN.2970899227_6xvl.jpg", image_3="", shop_id=7, price=8.00) listing35 = Listing( name= "Golden Pothos in Glazed Hanging Pot - Epipremnum Aureum Golden Pothos Devil's Ivy Macrame", description= "This pothos is fully rooted and planted in a white and blue glazed, 5 inch clay pot! It also has a macrame braided hanger. The plant will arrive packaged with care instructions to allow it to grow into a large, happy plant. These plants are very easy to grow, as they only need watered ~once per week, and are happy to live in low light conditions. However, the more light it has, the more variegation the leaves will produce! Pothos grow quickly, and they love to trail and climb, so this pot would be very happy placed on a shelf to allow the vines to cascade.", image_1= "https://i.etsystatic.com/12134093/r/il/2008fd/2799787400/il_1588xN.2799787400_ddhx.jpg", image_2= "https://i.etsystatic.com/12134093/r/il/4bc400/2799410986/il_794xN.2799410986_mpcp.jpg", image_3= "https://i.etsystatic.com/12134093/r/il/8e689c/2847082841/il_794xN.2847082841_e6zw.jpg", shop_id=7, price=30.00) # SnakeRiverGarden listing36 = Listing( name="Kalanchoe luciae ‘Flapjack’ (Paddle Plant) - 3.5” Growers Pot", description= "The Flapjack features thick, rounded, paddle-shaped leaves that are pale-aqua and blush red on the edges. It produces small pale yellow flowers on stalks.", image_1= "https://i.etsystatic.com/22605970/r/il/64ea7a/2943429793/il_1588xN.2943429793_jvge.jpg", image_2="", image_3="", shop_id=8, price=13.99) listing37 = Listing( name= "Lavandula angustifolia 'Hidcote' (English Lavender) - 4 inch Growers Pot", description= "Hidcote Lavender features subtle gray-green leaves and a sweet fragrance. Purple stalks rose above the foliage.", image_1= "https://i.etsystatic.com/22605970/r/il/bd27d7/2890331799/il_1588xN.2890331799_f0p8.jpg", image_2= "https://i.etsystatic.com/22605970/r/il/c25ebb/2820613861/il_794xN.2820613861_cp0j.jpg", image_3="", shop_id=8, price=8.99) listing38 = Listing( name= "Euphorbia milii 'Zephyr’ (Crown of Thorns) - 2.5 inch Growers Pot", description= "Crown of Thorns is recognized for its eye-catching blooms, which are not real flowers in the real sense, but spathaceous red bracts conveniently situated at the shoot tips. These conspicuous, saucer-shaped bracts surround the real flowers. The narrow, obovate, smooth-edged leaves that are spirally arranged on the stem naturally drop off as the plant gets older. This gives a scrawny appearance in older plants – an awesome vintage aesthetic for your living room or office.", image_1= "https://i.etsystatic.com/22605970/r/il/5283dc/2857932464/il_1588xN.2857932464_nt4y.jpg", image_2= "https://i.etsystatic.com/22605970/r/il/788a6a/2905602883/il_794xN.2905602883_ozbf.jpg", image_3= "https://i.etsystatic.com/22605970/r/il/fbde70/2905602977/il_794xN.2905602977_tli8.jpg", shop_id=8, price=10.99) listing39 = Listing( name="Hordeum vulgare (Cat Grass) - 4 inch Growers Pot", description= "Variegated Cat Grass is a healthy treat for your favorite felines. This attractive barley grass is solid green green. Why do cats eat grass? It helps them toss up hairballs and many have a natural taste for greens.", image_1= "https://i.etsystatic.com/22605970/r/il/086097/2924870731/il_1588xN.2924870731_m5ge.jpg", image_2= "https://i.etsystatic.com/22605970/r/il/fa308d/2877186696/il_794xN.2877186696_cn6y.jpg", image_3= "https://i.etsystatic.com/22605970/r/il/2ea9df/2924870737/il_794xN.2924870737_iw9p.jpg", shop_id=8, price=8.99) listing40 = Listing( name= "Hypoestes phyllostachya 'Splash Red' (Polka Dot Plant) - 4 inch Growers Pot", description= "ka dot plant is one of the cheeriest foliage plants around -- and most colorful. This beauty shows off red, pink, or white leaves marked with splashes of dark green. Polka dot plant forms a relatively low mound of foliage that looks good by itself or outstanding when mixed with other plants such as calathea that have fun foliage.", image_1= "https://i.etsystatic.com/22605970/r/il/fcd73f/2974983033/il_794xN.2974983033_e1iw.jpg", image_2= "https://i.etsystatic.com/22605970/r/il/635aab/2927284360/il_1588xN.2927284360_de7d.jpg", image_3="", shop_id=8, price=12.99) # Dorology listing41 = Listing( name="Raven ZZ (Zamioculas Zamiifolia) Plant - Rare", description= "You will receive a small live plant. It will be shipped bare root, no soil, no pot.", image_1= "https://i.etsystatic.com/17074812/r/il/43cf0e/2800576490/il_794xN.2800576490_tvyw.jpg", image_2= "https://i.etsystatic.com/17074812/r/il/a3d958/2862757814/il_794xN.2862757814_ofjg.jpg", image_3="", shop_id=9, price=9.99) listing42 = Listing( name="Begonia Maculata - Polkadot Begonia Rooted Cutting", description="It will be shipped bare root, no soil, no pot.", image_1= "https://i.etsystatic.com/17074812/r/il/f8c793/2989777445/il_1588xN.2989777445_f9ji.jpg", image_2= "https://i.etsystatic.com/17074812/r/il/448993/2989777585/il_794xN.2989777585_qut0.jpg", image_3= "https://i.etsystatic.com/17074812/r/il/30a417/3012377389/il_794xN.3012377389_7l3w.jpg", shop_id=9, price=19.99) listing43 = Listing( name="Gymnocalycium horstii Sider Cactus 2”", description= "Gymnocalycium horstii is a globular cactus resembling a loaf of bread from a bakery. Plants have a squat appearance and spines that are curved back towards the body. Plants usually offset over time, creating interesting specimens. The body of this species is glossy and the flower is always white. Its close relative Gymnocalycium buenekeri which occurs 200 km westward has a very similar but dull body with always pink flowers. Gymnocalycium horstii is a very rare and threatened South American species and occurs only in the southern Brazilian province of Rio Grande do Sul.", image_1= "https://i.etsystatic.com/17074812/r/il/dc1ae5/2989758617/il_1588xN.2989758617_nd1r.jpg", image_2= "https://i.etsystatic.com/17074812/r/il/ff2dd9/2942062412/il_794xN.2942062412_h6ko.jpg", image_3= "https://i.etsystatic.com/17074812/r/il/407420/2989758691/il_794xN.2989758691_9kcs.jpg", shop_id=9, price=9.99) listing44 = Listing( name="Gymnocalycium baldianum 2”", description= "Gymnocalycium baldianum, the spider-cactus or dwarf chin cactus, is a species of flowering plant in the cactus family Cactaceae, native to the Catamarca Province in Argentina.", image_1= "https://i.etsystatic.com/17074812/r/il/78017c/2946885166/il_1588xN.2946885166_exml.jpg", image_2= "https://i.etsystatic.com/17074812/r/il/76e2e7/2964690214/il_794xN.2964690214_oo8m.jpg", image_3="", shop_id=9, price=5.99) listing45 = Listing( name="Echinopsis subdenudata Domino Cactus 2”", description= "Echinopsis subdenudata (commonly called domino cactus, night blooming hedgehog, Easter lily cactus) is a species of cactus. It has a globular shape, few spines, with large, white flowers attached to long, green tubes. It occurs in Bolivia, at altitudes of 600–1800 meters. Under its synonym Echinopsis ancistrophora it has gained the Royal Horticultural Society’s Award of Garden Merit.", image_1= "https://i.etsystatic.com/17074812/r/il/52dc31/2968420970/il_1588xN.2968420970_i91u.jpg", image_2= "https://i.etsystatic.com/17074812/r/il/71b942/3016128947/il_794xN.3016128947_kcb6.jpg", image_3= "https://i.etsystatic.com/17074812/r/il/29dca2/3016129341/il_794xN.3016129341_liyl.jpg", shop_id=9, price=8.99) # GreenGardenFinds listing46 = Listing( name="Mimosa Pudica - Sensitive Plant - Rare Live Plant", description= "You will receive 1 Mimosa Pudica Live plant, 3+ inches. Plants are shipped when younger (approximately 1-2 months old) so they will acclimate easier to new environments and conditions. Be aware that plants may take 24 hours to open up fully and begin to move to touch again due to shipping and acclimating to their new environment. A schedule of 12-16 hours of sunlight/artificial light a day is necessary for this process.", image_1= "https://i.etsystatic.com/28031017/r/il/2612a4/2924604686/il_1588xN.2924604686_krib.jpg", image_2= "https://i.etsystatic.com/28031017/r/il/308ccf/2924604672/il_794xN.2924604672_sxyx.jpg", image_3="", shop_id=1, price=34.00) listing47 = Listing( name="Mortgage Lifter Tomato - 3 Live Plants Per Order - GMO Free", description= "You will receive 3 live Mortgage Lifter Tomato plants! 80 days to harvest", image_1= "https://i.etsystatic.com/28031017/r/il/79a352/2958033274/il_1588xN.2958033274_m67v.jpg", image_2= "https://i.etsystatic.com/28031017/r/il/6fd731/3005737955/il_794xN.3005737955_lhff.jpg", image_3="", shop_id=1, price=25.00) listing48 = Listing( name= "Straight Eight Cucumber - 5 Live Cucumber Plants Per Order - All Season Growers & Producers - Live Arrival Guaranteed!", description="You will receive 5 live Straight Eight Cucumber plants.", image_1= "https://i.etsystatic.com/28031017/r/il/16aab2/3005715447/il_1588xN.3005715447_2jh8.jpg", image_2= "https://i.etsystatic.com/28031017/r/il/0bee87/2968610289/il_794xN.2968610289_2yc5.jpg", image_3="", shop_id=1, price=30.00) listing49 = Listing( name= "California Wonder Green Bell Pepper - 3 Live Plants Per Order - GMO Free", description= "You will receive 3 live California Wonder Green Bell Pepper plants! 75 days to harvest", image_1= "https://i.etsystatic.com/28031017/r/il/5e22cf/2971663152/il_1588xN.2971663152_5uqq.jpg", image_2= "https://i.etsystatic.com/28031017/r/il/b2d31b/2971662748/il_794xN.2971662748_cwm3.jpg", image_3= "https://i.etsystatic.com/28031017/r/il/a4944c/3019371321/il_794xN.3019371321_7grz.jpg", shop_id=1, price=20.00) listing50 = Listing( name="Supersweet 100 - 3 Live Plants Per Order - GMO Free", description= "You will receive 3 live Supersweet 100 Tomato plants! 70 days to harvest", image_1= "https://i.etsystatic.com/28031017/r/il/a4944c/3019371321/il_794xN.3019371321_7grz.jpg", image_2= "https://i.etsystatic.com/28031017/r/il/b2d31b/2971662748/il_794xN.2971662748_cwm3.jpg", image_3= "https://i.etsystatic.com/28031017/r/il/c0c546/2971662744/il_794xN.2971662744_o2nx.jpg", shop_id=1, price=25.00) db.session.add(listing1) db.session.add(listing2) db.session.add(listing3) db.session.add(listing4) db.session.add(listing5) db.session.add(listing6) db.session.add(listing7) db.session.add(listing8) db.session.add(listing9) db.session.add(listing10) db.session.add(listing11) db.session.add(listing12) db.session.add(listing13) db.session.add(listing14) db.session.add(listing15) db.session.add(listing16) db.session.add(listing17) db.session.add(listing18) db.session.add(listing19) db.session.add(listing20) db.session.add(listing21) db.session.add(listing22) db.session.add(listing23) db.session.add(listing24) db.session.add(listing25) db.session.add(listing26) db.session.add(listing27) db.session.add(listing28) db.session.add(listing29) db.session.add(listing30) db.session.add(listing31) db.session.add(listing32) db.session.add(listing33) db.session.add(listing34) db.session.add(listing35) db.session.add(listing36) db.session.add(listing37) db.session.add(listing38) db.session.add(listing39) db.session.add(listing40) db.session.add(listing41) db.session.add(listing42) db.session.add(listing43) db.session.add(listing44) db.session.add(listing45) db.session.add(listing46) db.session.add(listing47) db.session.add(listing48) db.session.add(listing49) db.session.add(listing50) db.session.commit()
def popdb(): #adding tuples to db k1 = Keyword(name='green') k2 = Keyword(name='yellow') k3 = Keyword(name='red') k4 = Keyword(name='white') k5 = Keyword(name='tan') k6 = Keyword(name='orange') k7 = Keyword(name='brown') k8 = Keyword(name='black') k9 = Keyword(name='vegetable') k10 = Keyword(name='starch') k11 = Keyword(name='squash') k12 = Keyword(name='gourd') k13 = Keyword(name='legume') k14 = Keyword(name='maize') k15 = Keyword(name='spicy') k16 = Keyword(name='sweet') k17 = Keyword(name='tart') k18 = Keyword(name='leafy') k19 = Keyword(name='grain') k20 = Keyword(name='cereal') k21 = Keyword(name='cabbage') db.session.add_all([ k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k20, k21 ]) db.session.commit() s1 = Supplier(name='Griggs Farm', address='599 Boston Rd', zipcode=1821, city='Billerica', state='MA') s2 = Supplier(name='Krochmal Farms', address='31 Jennie\'s Way', zipcode=1876, city='Tewksbury', state='MA') s3 = Supplier(name='Great Brook Dairy Farm', address='247 North Rd', zipcode=1741, city='Carlisle', state='MA') s4 = Supplier(name='Farmer Daves', address='437 Parker Rd', zipcode=1826, city='Dracut', state='MA') s5 = Supplier(name='Jones Farm', address='246 Acton Rd', zipcode=1824, city='Chelmsford', state='MA') s6 = Supplier(name='Swenson Farms', address='50 Mill Rd', zipcode=1862, city='Chelmsford', state='MA') s7 = Supplier(name='Drew Farm', address='31 Tadmuck Rd', zipcode=1886, city='Westford', state='MA') s8 = Supplier(name='Clark Farm', address='185 Concord St', zipcode=1741, city='Carlisle', state='MA') s9 = Supplier(name='Parlee Farm', address='135 Pine Hill Rd', zipcode=1824, city='Chelmsford', state='MA') s10 = Supplier(name='Wright-Locke Farm', address='78 Ridge St', zipcode=1890, city='Winchester', state='MA') s11 = Supplier(name='Indian Creek Farm', address='1408 Trumansburg Rd', zipcode=14850, city='Ithaca', state='NY') s12 = Supplier(name='Stick and Stone Farm', address='1605 Trumansburg Rd', zipcode=14850, city='Ithaca', state='NY') s13 = Supplier(name='RoseBarb Farms', address='108 Landon Rd', zipcode=14850, city='Ithaca', state='NY') s14 = Supplier(name='Three Swallows Farm', address='23 Nelson Rd', zipcode=14850, city='Ithaca', state='NY') s15 = Supplier(name='HoneyRock Farm', address='271 Burns Rd', zipcode=14850, city='Ithaca', state='NY') s16 = Supplier(name='Kingdom Farms', address='317 Auburn Rd', zipcode=14882, city='Lansing', state='NY') s17 = Supplier(name='Straw Pocket Farm', address='1388 Ridge Rd', zipcode=14882, city='Lansing', state='NY') s18 = Supplier(name='Dygert Farms', address='260 Central Chapel Rd', zipcode=14817, city='Brooktondale', state='NY') s19 = Supplier(name='TC3 Farm', address='100 Cortland Rd', zipcode=13053, city='Dryden', state='NY') db.session.add_all([ s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19 ]) db.session.commit() p1 = Produce( name='Brocolli', imageRef='https://cdn.mos.cms.futurecdn.net/r8NK24bmcMgSib5zWKKQkW.jpg' ) p2 = Produce( name='Spinach', imageRef= 'https://i.ndtvimg.com/i/2016-11/spinach_620x350_81477995047.jpg') p3 = Produce( name='Kale', imageRef= 'https://post.healthline.com/wp-content/uploads/2020/09/benefits-of-kale-1200x628-facebook-1200x628.jpg' ) p4 = Produce( name='Pumpkin', imageRef= 'https://post.medicalnewstoday.com/wp-content/uploads/sites/3/2020/02/279610_2200-732x549.jpg' ) p5 = Produce( name='Straightneck Squash', imageRef= 'https://d1nw62gticy6e9.cloudfront.net/uploads/Early-Prolific-Straightneck-Squash-Seeds.jpg' ) p6 = Produce( name='Zucchini', imageRef= 'https://www.jessicagavin.com/wp-content/uploads/2018/05/zucchini-2-1200.jpg' ) p7 = Produce( name='Green Beans', imageRef= 'https://images.food52.com/mrPh1x9qA6lTYKO27QJEfDjZ4Y8=/2016x1344/filters:format(webp)/ff7b7650-cacd-42b4-947c-e2e8ba90fa2a--greenbeans.jpg' ) p8 = Produce( name='Lentils', imageRef= 'https://cdn.loveandlemons.com/wp-content/uploads/2019/12/how-to-cook-lentils.jpg' ) p9 = Produce( name='Peas', imageRef= 'https://www.almanac.com/sites/default/files/image_nodes/peas-and-pea-pods.jpg' ) p10 = Produce( name='Potatoes', imageRef= 'https://cdn.cheapism.com/images/081516_national_potato_day_recipes_slide_0_f.max-800x600.jpg' ) p11 = Produce( name='Corn', imageRef= 'https://www.simplyhappyfoodie.com/wp-content/uploads/2018/04/instant-pot-corn-on-the-cob-1-500x500.jpg' ) p12 = Produce( name='Soybean', imageRef= 'https://www.johnnyseeds.com/dw/image/v2/BBBW_PRD/on/demandware.static/-/Sites-jss-master/default/dw3c4875f3/images/products/vegetables/02553_01_tohya.jpg?sw=1120' ) p13 = Produce( name='Oats', imageRef= 'https://post.healthline.com/wp-content/uploads/2020/03/oats-oatmeal-732x549-thumbnail.jpg' ) p14 = Produce( name='Barley', imageRef= 'https://cdn-prod.medicalnewstoday.com/content/images/articles/295/295268/barley-grains-in-a-wooden-bowl.jpg' ) p15 = Produce( name='Flour', imageRef= 'https://www.world-grain.com/ext/resources/Article-Images/2020/05/WholeWheatFlour_Photo-adobe-stock_E.jpg?t=1590171823&width=1080' ) p16 = Produce( name='Turnip', imageRef= 'https://upload.wikimedia.org/wikipedia/commons/d/d3/Turnip_2622027.jpg' ) p17 = Produce( name='Lettuce', imageRef= 'https://i0.wp.com/post.healthline.com/wp-content/uploads/2020/03/romaine-lettuce-1296x728-body.jpg?w=1155&h=1528' ) p18 = Produce( name='Green Peppers', imageRef= 'https://edge.bonnieplants.com/www/tiny/uploads/20200810205434/bonnie-s-green-bell-pepper.jpg' ) p19 = Produce(name='Chili Peppers', imageRef='https://scitechdaily.com/images/Chili-Peppers.jpg') p20 = Produce( name='Cucumber', imageRef= 'https://www.shethepeople.tv/wp-content/uploads/2019/05/cucumber-e1558166231577.jpg' ) db.session.add_all([ p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20 ]) db.session.commit() pk1 = Producetokeyword(kproduct=Produce.query.get(1), tag=Keyword.query.get(1)) pk2 = Producetokeyword(kproduct=Produce.query.get(1), tag=Keyword.query.get(9)) pk3 = Producetokeyword(kproduct=Produce.query.get(1), tag=Keyword.query.get(21)) pk4 = Producetokeyword(kproduct=Produce.query.get(2), tag=Keyword.query.get(1)) pk5 = Producetokeyword(kproduct=Produce.query.get(2), tag=Keyword.query.get(18)) pk6 = Producetokeyword(kproduct=Produce.query.get(2), tag=Keyword.query.get(9)) pk7 = Producetokeyword(kproduct=Produce.query.get(3), tag=Keyword.query.get(1)) pk8 = Producetokeyword(kproduct=Produce.query.get(3), tag=Keyword.query.get(18)) pk9 = Producetokeyword(kproduct=Produce.query.get(3), tag=Keyword.query.get(9)) pk10 = Producetokeyword(kproduct=Produce.query.get(4), tag=Keyword.query.get(6)) pk11 = Producetokeyword(kproduct=Produce.query.get(4), tag=Keyword.query.get(11)) pk12 = Producetokeyword(kproduct=Produce.query.get(4), tag=Keyword.query.get(12)) pk13 = Producetokeyword(kproduct=Produce.query.get(4), tag=Keyword.query.get(16)) pk14 = Producetokeyword(kproduct=Produce.query.get(5), tag=Keyword.query.get(2)) pk15 = Producetokeyword(kproduct=Produce.query.get(5), tag=Keyword.query.get(11)) pk16 = Producetokeyword(kproduct=Produce.query.get(5), tag=Keyword.query.get(12)) pk17 = Producetokeyword(kproduct=Produce.query.get(5), tag=Keyword.query.get(16)) pk18 = Producetokeyword(kproduct=Produce.query.get(6), tag=Keyword.query.get(1)) pk19 = Producetokeyword(kproduct=Produce.query.get(6), tag=Keyword.query.get(11)) pk20 = Producetokeyword(kproduct=Produce.query.get(6), tag=Keyword.query.get(12)) pk21 = Producetokeyword(kproduct=Produce.query.get(6), tag=Keyword.query.get(16)) pk22 = Producetokeyword(kproduct=Produce.query.get(7), tag=Keyword.query.get(1)) pk23 = Producetokeyword(kproduct=Produce.query.get(7), tag=Keyword.query.get(13)) pk24 = Producetokeyword(kproduct=Produce.query.get(7), tag=Keyword.query.get(9)) pk25 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(1)) pk26 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(2)) pk27 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(3)) pk28 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(4)) pk29 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(6)) pk30 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(7)) pk31 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(8)) pk32 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(13)) pk33 = Producetokeyword(kproduct=Produce.query.get(8), tag=Keyword.query.get(9)) pk34 = Producetokeyword(kproduct=Produce.query.get(9), tag=Keyword.query.get(1)) pk35 = Producetokeyword(kproduct=Produce.query.get(9), tag=Keyword.query.get(9)) pk36 = Producetokeyword(kproduct=Produce.query.get(9), tag=Keyword.query.get(13)) pk37 = Producetokeyword(kproduct=Produce.query.get(9), tag=Keyword.query.get(16)) pk38 = Producetokeyword(kproduct=Produce.query.get(10), tag=Keyword.query.get(4)) pk39 = Producetokeyword(kproduct=Produce.query.get(10), tag=Keyword.query.get(3)) pk40 = Producetokeyword(kproduct=Produce.query.get(10), tag=Keyword.query.get(2)) pk41 = Producetokeyword(kproduct=Produce.query.get(10), tag=Keyword.query.get(7)) pk42 = Producetokeyword(kproduct=Produce.query.get(10), tag=Keyword.query.get(10)) pk43 = Producetokeyword(kproduct=Produce.query.get(10), tag=Keyword.query.get(16)) pk44 = Producetokeyword(kproduct=Produce.query.get(11), tag=Keyword.query.get(2)) pk45 = Producetokeyword(kproduct=Produce.query.get(11), tag=Keyword.query.get(16)) pk46 = Producetokeyword(kproduct=Produce.query.get(11), tag=Keyword.query.get(20)) pk47 = Producetokeyword(kproduct=Produce.query.get(11), tag=Keyword.query.get(14)) pk48 = Producetokeyword(kproduct=Produce.query.get(11), tag=Keyword.query.get(19)) pk49 = Producetokeyword(kproduct=Produce.query.get(11), tag=Keyword.query.get(9)) pk50 = Producetokeyword(kproduct=Produce.query.get(12), tag=Keyword.query.get(9)) pk51 = Producetokeyword(kproduct=Produce.query.get(12), tag=Keyword.query.get(13)) pk52 = Producetokeyword(kproduct=Produce.query.get(12), tag=Keyword.query.get(1)) pk53 = Producetokeyword(kproduct=Produce.query.get(13), tag=Keyword.query.get(19)) pk54 = Producetokeyword(kproduct=Produce.query.get(13), tag=Keyword.query.get(20)) pk55 = Producetokeyword(kproduct=Produce.query.get(13), tag=Keyword.query.get(10)) pk56 = Producetokeyword(kproduct=Produce.query.get(13), tag=Keyword.query.get(7)) pk57 = Producetokeyword(kproduct=Produce.query.get(14), tag=Keyword.query.get(19)) pk58 = Producetokeyword(kproduct=Produce.query.get(14), tag=Keyword.query.get(20)) pk59 = Producetokeyword(kproduct=Produce.query.get(14), tag=Keyword.query.get(10)) pk60 = Producetokeyword(kproduct=Produce.query.get(14), tag=Keyword.query.get(7)) pk61 = Producetokeyword(kproduct=Produce.query.get(15), tag=Keyword.query.get(19)) pk62 = Producetokeyword(kproduct=Produce.query.get(15), tag=Keyword.query.get(20)) pk63 = Producetokeyword(kproduct=Produce.query.get(15), tag=Keyword.query.get(10)) pk64 = Producetokeyword(kproduct=Produce.query.get(15), tag=Keyword.query.get(4)) pk65 = Producetokeyword(kproduct=Produce.query.get(16), tag=Keyword.query.get(17)) pk66 = Producetokeyword(kproduct=Produce.query.get(16), tag=Keyword.query.get(3)) pk67 = Producetokeyword(kproduct=Produce.query.get(16), tag=Keyword.query.get(4)) pk68 = Producetokeyword(kproduct=Produce.query.get(16), tag=Keyword.query.get(9)) pk69 = Producetokeyword(kproduct=Produce.query.get(16), tag=Keyword.query.get(16)) pk70 = Producetokeyword(kproduct=Produce.query.get(17), tag=Keyword.query.get(1)) pk71 = Producetokeyword(kproduct=Produce.query.get(17), tag=Keyword.query.get(9)) pk72 = Producetokeyword(kproduct=Produce.query.get(17), tag=Keyword.query.get(18)) pk73 = Producetokeyword(kproduct=Produce.query.get(18), tag=Keyword.query.get(1)) pk74 = Producetokeyword(kproduct=Produce.query.get(18), tag=Keyword.query.get(16)) pk75 = Producetokeyword(kproduct=Produce.query.get(18), tag=Keyword.query.get(9)) pk76 = Producetokeyword(kproduct=Produce.query.get(19), tag=Keyword.query.get(15)) pk77 = Producetokeyword(kproduct=Produce.query.get(19), tag=Keyword.query.get(16)) pk78 = Producetokeyword(kproduct=Produce.query.get(19), tag=Keyword.query.get(3)) pk79 = Producetokeyword(kproduct=Produce.query.get(19), tag=Keyword.query.get(9)) pk80 = Producetokeyword(kproduct=Produce.query.get(20), tag=Keyword.query.get(1)) pk81 = Producetokeyword(kproduct=Produce.query.get(20), tag=Keyword.query.get(16)) pk82 = Producetokeyword(kproduct=Produce.query.get(20), tag=Keyword.query.get(9)) pk83 = Producetokeyword(kproduct=Produce.query.get(20), tag=Keyword.query.get(12)) pk84 = Producetokeyword(kproduct=Produce.query.get(20), tag=Keyword.query.get(11)) db.session.add_all([ pk1, pk2, pk3, pk4, pk5, pk6, pk7, pk8, pk9, pk10, pk11, pk12, pk13, pk14, pk15, pk16, pk17, pk18, pk19, pk20, pk21, pk22, pk23, pk24, pk25, pk26, pk27, pk28, pk29, pk30, pk31, pk32, pk33, pk34, pk35, pk36, pk37, pk38, pk39, pk40, pk41, pk42, pk43, pk44, pk45, pk46, pk47, pk48, pk49, pk50, pk51, pk52, pk53, pk54, pk55, pk56, pk57, pk58, pk59, pk60, pk61, pk62, pk63, pk64, pk65, pk66, pk67, pk68, pk69, pk70, pk71, pk72, pk73, pk74, pk75, pk76, pk77, pk78, pk79, pk80, pk81, pk82, pk83, pk84 ]) db.session.commit() l1 = Listing(price=2.56, quantity=551, lproduct=Produce.query.get(2), owner=Supplier.query.get(16)) l2 = Listing(price=3.27, quantity=1059, lproduct=Produce.query.get(1), owner=Supplier.query.get(4)) l3 = Listing(price=0.59, quantity=710, lproduct=Produce.query.get(2), owner=Supplier.query.get(15)) l4 = Listing(price=2.59, quantity=535, lproduct=Produce.query.get(9), owner=Supplier.query.get(10)) l5 = Listing(price=2.04, quantity=682, lproduct=Produce.query.get(6), owner=Supplier.query.get(3)) l6 = Listing(price=3.3, quantity=1254, lproduct=Produce.query.get(6), owner=Supplier.query.get(7)) l7 = Listing(price=3.19, quantity=612, lproduct=Produce.query.get(10), owner=Supplier.query.get(5)) l8 = Listing(price=1.22, quantity=748, lproduct=Produce.query.get(14), owner=Supplier.query.get(4)) l9 = Listing(price=1.83, quantity=1236, lproduct=Produce.query.get(15), owner=Supplier.query.get(10)) l11 = Listing(price=2.38, quantity=460, lproduct=Produce.query.get(6), owner=Supplier.query.get(15)) l12 = Listing(price=3.02, quantity=588, lproduct=Produce.query.get(16), owner=Supplier.query.get(19)) l13 = Listing(price=2.29, quantity=231, lproduct=Produce.query.get(10), owner=Supplier.query.get(14)) l14 = Listing(price=1.84, quantity=717, lproduct=Produce.query.get(17), owner=Supplier.query.get(1)) l16 = Listing(price=0.75, quantity=709, lproduct=Produce.query.get(14), owner=Supplier.query.get(18)) l17 = Listing(price=0.51, quantity=826, lproduct=Produce.query.get(16), owner=Supplier.query.get(4)) l18 = Listing(price=1.32, quantity=623, lproduct=Produce.query.get(13), owner=Supplier.query.get(17)) l20 = Listing(price=1.19, quantity=996, lproduct=Produce.query.get(2), owner=Supplier.query.get(7)) l21 = Listing(price=1.73, quantity=931, lproduct=Produce.query.get(14), owner=Supplier.query.get(5)) l22 = Listing(price=0.81, quantity=166, lproduct=Produce.query.get(8), owner=Supplier.query.get(8)) l23 = Listing(price=2.68, quantity=204, lproduct=Produce.query.get(3), owner=Supplier.query.get(12)) l24 = Listing(price=3.02, quantity=615, lproduct=Produce.query.get(9), owner=Supplier.query.get(9)) l25 = Listing(price=1.73, quantity=832, lproduct=Produce.query.get(4), owner=Supplier.query.get(13)) l26 = Listing(price=1.53, quantity=181, lproduct=Produce.query.get(6), owner=Supplier.query.get(1)) l27 = Listing(price=0.79, quantity=769, lproduct=Produce.query.get(15), owner=Supplier.query.get(13)) l29 = Listing(price=3.28, quantity=962, lproduct=Produce.query.get(16), owner=Supplier.query.get(11)) l30 = Listing(price=1.1, quantity=1198, lproduct=Produce.query.get(20), owner=Supplier.query.get(6)) l31 = Listing(price=2.44, quantity=259, lproduct=Produce.query.get(10), owner=Supplier.query.get(15)) l32 = Listing(price=3.04, quantity=180, lproduct=Produce.query.get(16), owner=Supplier.query.get(5)) l33 = Listing(price=1.8, quantity=330, lproduct=Produce.query.get(1), owner=Supplier.query.get(17)) l34 = Listing(price=1.94, quantity=353, lproduct=Produce.query.get(1), owner=Supplier.query.get(18)) l35 = Listing(price=3.22, quantity=890, lproduct=Produce.query.get(11), owner=Supplier.query.get(6)) l38 = Listing(price=0.87, quantity=1057, lproduct=Produce.query.get(15), owner=Supplier.query.get(15)) l39 = Listing(price=1.64, quantity=956, lproduct=Produce.query.get(6), owner=Supplier.query.get(5)) l40 = Listing(price=3.28, quantity=670, lproduct=Produce.query.get(17), owner=Supplier.query.get(6)) l41 = Listing(price=1.92, quantity=567, lproduct=Produce.query.get(12), owner=Supplier.query.get(1)) l42 = Listing(price=0.68, quantity=1145, lproduct=Produce.query.get(19), owner=Supplier.query.get(11)) l43 = Listing(price=2.71, quantity=885, lproduct=Produce.query.get(18), owner=Supplier.query.get(9)) l44 = Listing(price=0.69, quantity=190, lproduct=Produce.query.get(15), owner=Supplier.query.get(17)) l45 = Listing(price=2, quantity=1109, lproduct=Produce.query.get(5), owner=Supplier.query.get(2)) l46 = Listing(price=1.63, quantity=354, lproduct=Produce.query.get(7), owner=Supplier.query.get(13)) l48 = Listing(price=1.67, quantity=763, lproduct=Produce.query.get(20), owner=Supplier.query.get(5)) l49 = Listing(price=2.21, quantity=716, lproduct=Produce.query.get(4), owner=Supplier.query.get(19)) l50 = Listing(price=2.47, quantity=383, lproduct=Produce.query.get(13), owner=Supplier.query.get(8)) l51 = Listing(price=3.11, quantity=1229, lproduct=Produce.query.get(17), owner=Supplier.query.get(9)) l52 = Listing(price=2.79, quantity=911, lproduct=Produce.query.get(16), owner=Supplier.query.get(16)) l53 = Listing(price=2.24, quantity=635, lproduct=Produce.query.get(3), owner=Supplier.query.get(18)) l54 = Listing(price=2.08, quantity=999, lproduct=Produce.query.get(7), owner=Supplier.query.get(10)) l55 = Listing(price=2.87, quantity=896, lproduct=Produce.query.get(8), owner=Supplier.query.get(16)) l56 = Listing(price=0.67, quantity=251, lproduct=Produce.query.get(16), owner=Supplier.query.get(7)) l57 = Listing(price=2.41, quantity=508, lproduct=Produce.query.get(12), owner=Supplier.query.get(19)) l58 = Listing(price=3.1, quantity=165, lproduct=Produce.query.get(14), owner=Supplier.query.get(11)) l59 = Listing(price=3.2, quantity=1068, lproduct=Produce.query.get(19), owner=Supplier.query.get(19)) l60 = Listing(price=2.98, quantity=846, lproduct=Produce.query.get(19), owner=Supplier.query.get(12)) l61 = Listing(price=1.91, quantity=481, lproduct=Produce.query.get(1), owner=Supplier.query.get(10)) l62 = Listing(price=2.37, quantity=1165, lproduct=Produce.query.get(18), owner=Supplier.query.get(12)) l63 = Listing(price=1.18, quantity=634, lproduct=Produce.query.get(1), owner=Supplier.query.get(16)) l65 = Listing(price=1.46, quantity=1143, lproduct=Produce.query.get(6), owner=Supplier.query.get(13)) l66 = Listing(price=1.38, quantity=491, lproduct=Produce.query.get(20), owner=Supplier.query.get(11)) l67 = Listing(price=0.69, quantity=331, lproduct=Produce.query.get(14), owner=Supplier.query.get(9)) l68 = Listing(price=3.46, quantity=809, lproduct=Produce.query.get(11), owner=Supplier.query.get(14)) l70 = Listing(price=3.2, quantity=1083, lproduct=Produce.query.get(5), owner=Supplier.query.get(3)) l71 = Listing(price=1.21, quantity=318, lproduct=Produce.query.get(14), owner=Supplier.query.get(1)) l72 = Listing(price=2.29, quantity=544, lproduct=Produce.query.get(6), owner=Supplier.query.get(9)) l73 = Listing(price=2.11, quantity=207, lproduct=Produce.query.get(6), owner=Supplier.query.get(17)) l74 = Listing(price=0.64, quantity=882, lproduct=Produce.query.get(9), owner=Supplier.query.get(15)) l75 = Listing(price=2.59, quantity=185, lproduct=Produce.query.get(18), owner=Supplier.query.get(16)) l76 = Listing(price=1.57, quantity=1143, lproduct=Produce.query.get(18), owner=Supplier.query.get(10)) l78 = Listing(price=1.7, quantity=934, lproduct=Produce.query.get(6), owner=Supplier.query.get(10)) l79 = Listing(price=0.65, quantity=501, lproduct=Produce.query.get(11), owner=Supplier.query.get(19)) l80 = Listing(price=1.84, quantity=741, lproduct=Produce.query.get(3), owner=Supplier.query.get(10)) l83 = Listing(price=3.31, quantity=784, lproduct=Produce.query.get(9), owner=Supplier.query.get(14)) l84 = Listing(price=0.57, quantity=106, lproduct=Produce.query.get(17), owner=Supplier.query.get(8)) l85 = Listing(price=2.99, quantity=1225, lproduct=Produce.query.get(19), owner=Supplier.query.get(7)) l86 = Listing(price=1.13, quantity=865, lproduct=Produce.query.get(6), owner=Supplier.query.get(19)) l87 = Listing(price=1.91, quantity=560, lproduct=Produce.query.get(3), owner=Supplier.query.get(19)) l88 = Listing(price=3.45, quantity=883, lproduct=Produce.query.get(17), owner=Supplier.query.get(16)) l89 = Listing(price=2.34, quantity=326, lproduct=Produce.query.get(15), owner=Supplier.query.get(19)) l90 = Listing(price=2.45, quantity=110, lproduct=Produce.query.get(19), owner=Supplier.query.get(5)) l91 = Listing(price=1.49, quantity=230, lproduct=Produce.query.get(19), owner=Supplier.query.get(6)) l92 = Listing(price=2.61, quantity=889, lproduct=Produce.query.get(19), owner=Supplier.query.get(2)) l93 = Listing(price=0.72, quantity=436, lproduct=Produce.query.get(10), owner=Supplier.query.get(7)) l94 = Listing(price=1.58, quantity=1231, lproduct=Produce.query.get(10), owner=Supplier.query.get(10)) l96 = Listing(price=1.19, quantity=582, lproduct=Produce.query.get(12), owner=Supplier.query.get(6)) l97 = Listing(price=3.4, quantity=972, lproduct=Produce.query.get(3), owner=Supplier.query.get(14)) l98 = Listing(price=1.95, quantity=1260, lproduct=Produce.query.get(13), owner=Supplier.query.get(15)) l100 = Listing(price=1.81, quantity=226, lproduct=Produce.query.get(7), owner=Supplier.query.get(12)) db.session.add_all([ l1, l2, l3, l4, l5, l6, l7, l8, l9, l11, l12, l13, l14, l16, l17, l18, l20, l21, l22, l23, l24, l25, l26, l27, l29, l30, l31, l32, l33, l34, l35, l38, l39, l40, l41, l42, l43, l44, l45, l46, l48, l49, l50, l51, l52, l53, l54, l55, l56, l57, l58, l59, l60, l61, l62, l63, l65, l66, l67, l68, l70, l71, l72, l73, l74, l75, l76, l78, l79, l80, l83, l84, l85, l86, l87, l88, l89, l90, l91, l92, l93, l94, l96, l97, l98, l100 ]) db.session.commit() return "Database has been populated."
def test_listings_average(self): # create company c1 = Company(id=1, company_name='Paint pods', company_address='Boise', company_zipcode='83706', company_website='Paintteam.com', company_phone_number='20867832', company_email='*****@*****.**') c2 = Company(id=2, company_name='Bob Team', company_address='Salt Lake City', company_zipcode='81504', company_website='Paintteam.com', company_phone_number='2086783456', company_email='*****@*****.**') db.session.add(c1) db.session.add(c2) db.session.commit() # create services s1 = Service(parent_id=1, title='plumbing') s2 = Service(parent_id=2, title='electrical') db.session.add(s1) db.session.add(s2) db.session.commit() # create four posts now = datetime.utcnow() p1 = Post(body="post from john", timestamp=now + timedelta(seconds=1), service_id=1, company_id=1, price=35.0, rating=1) p2 = Post(body="post from john", timestamp=now + timedelta(seconds=1), service_id=1, company_id=1, price=36.0, rating=3) p3 = Post(body="test post", timestamp=now + timedelta(seconds=1), service_id=2, company_id=2, price=37.0) p4 = Post(body="test post", timestamp=now + timedelta(seconds=1), service_id=2, company_id=2, price=38.0) db.session.add_all([p1, p2, p3, p4]) db.session.commit() # create listings l1 = Listing(service_id=1, company_id=1) l2 = Listing(service_id=1, company_id=2) db.session.add_all([l1, l2]) db.session.commit() # get posts posts = Post.query.filter(Post.service_id == 1, Post.company_id == 1) # check calculate_averages function l1.calculate_averages(posts) # check that the correct posts are returned self.assertEqual(posts.count(), 2) # check that the average price is correct self.assertEqual(l1.average_price, 35.5) self.assertEqual(l1.average_rating, 2)