def parse_item(self, item, index, package_type): ''' Parses an individual entry from the main listing. This is how the majority of the updates will be occuring. We will mostly be using these updates for awareness of auctions that have been added. While we are here we will continue to track the price of the auction even though it is not closed, as this may become relevent in some searches. ''' aid = item.findChild('input', {'name': 'frmAuctionID%s' % index}).get('value') bid = item.findChild('input', {'name': 'frmBrandCode%s' % index}).get('value') auction = Auction.query.filter_by(aid=aid, site='cigarauctioneer').first() brand = Brand.query.filter_by(ca_id=bid).first() if not brand: brand = Brand() brand.name = item.findChild('input', {'name': 'frmBrandDesc%s' % index}).get('value') brand.ca_id = bid db.session.add(brand) if not auction: # as we haven't seen this action before, we will need to get all of # the usual information and store that into a new Auction database # object. auction = Auction() auction.type = package_type auction.name = item.findChild('input', {'name': 'frmItemDesc%s' % index}).get('value') auction.aid = aid auction.site = 'cigarauctioneer' auction.close = self.timestamp_gen(item.findChild('div', text='Time Left:').findNext('div').text) auction.link = item.findChild('a', {'itemprop': 'url'}).get('href') if package_type is not 'singles': auction.quantity = int(item.findChild('input', {'name': 'frmItemsPerPack%s' % index}).get('value')) else: auction.quantity = 1 brand.auctions.append(auction) db.session.add(auction) # now we need to get the current price and update the timestamp. auction.price = float(item.findChild('div', {'itemprop': 'price'}).text.strip('$')) auction.timestamp = datetime.now() # Now we need to commit the changes to the database ;) db.session.commit()