def main(): asin = input("Please enter a vaild ASIN: ") url = amazon.create_url(asin) result = amazon.scrape(url, asin) reg = models.Items(name=result.name, customer_reviews_count=result.count, asin=asin) db.session.add(reg) db.session.commit() selection = input("Do you have another ASIN? (y/n) ") if selection == 'y': print("Cool") else: sys.exit()
def post_item(): form = forms.PostingFormFactory.form() if form.validate_on_submit(): randomString = ''.join( random.choices(string.ascii_uppercase + string.digits, k=30)) new_posting = models.Items() new_posting.product_id = randomString new_posting.seller_username = current_user.username new_posting.category = form.category.data new_posting.condition = form.condition.data new_posting.item_name = form.item_name.data new_posting.price = form.price.data new_posting.quantity = form.quantity.data new_posting.description = form.description.data image = request.files['image'] apiUrl = 'https://api.imgur.com/3/image' b64_image = base64.standard_b64encode(image.read()) params = {'image': b64_image} headers = {'Authorization': 'Client-ID 12aa250c79dba8d'} #client_id = '12aa250c79dba8d' #client_secret = '0e132c4d82850eda1d2a172903f5a85bcea10a0b' response = requests.post(apiUrl, headers=headers, data=params) result = json.loads(response.text) new_posting.image = result['data']['link'] db.session.add(new_posting) db.session.execute( 'UPDATE buyers SET is_seller=\'1\' WHERE username=:username', dict(username=current_user.username)) db.session.commit() db.session.close() current_user.is_seller = '1' flash('Item posted successfully') return redirect(url_for('post_item')) return render_template('post_item.html', form=form)
def edit_item(product_id): try: item = db.session.query( models.Items).filter(models.Items.product_id == product_id).filter( models.Items.seller_username == current_user.username).one() form = forms.ItemEditFormFactory.form(item) if form.validate_on_submit(): form.errors.pop('database', None) if (request.files['image']): image = request.files['image'] apiUrl = 'https://api.imgur.com/3/image' b64_image = base64.standard_b64encode(image.read()) params = {'image': b64_image} headers = {'Authorization': 'Client-ID 12aa250c79dba8d'} #client_id = '12aa250c79dba8d' #client_secret = '0e132c4d82850eda1d2a172903f5a85bcea10a0b' response = requests.post(apiUrl, headers=headers, data=params) result = json.loads(response.text) edit_posting = models.Items() edit_posting.image = result['data']['link'] models.Items.edit(product_id, current_user.username, form.category.data, form.condition.data, form.item_name.data, form.price.data, form.quantity.data, edit_posting.image, form.description.data) else: models.Items.edit(product_id, current_user.username, form.category.data, form.condition.data, form.item_name.data, form.price.data, form.quantity.data, item.image, form.description.data) flash('Item been modified successfully') return redirect(url_for('sales_history')) except: flash('You are not selling this item or this is not a valid item.') return render_template('edit-item.html', item=item, form=form)
def get_item(self, nome): items = self.con.execute("select * from items where nome=?", (nome, )).fetchone() return models.Items(*items)