示例#1
0
def save_notice():
    """Записать информацию в БД"""
    local_path = request.args.get('local_path')
    count_files = request.args.get('count_files')

    if local_path:
        api_name = 'PARSER_LOCAL_XML_NAME'

        api_parser_link = ConfigDealer.get_api_links(api_name)
        try:
            response = requests.get(api_parser_link, {'local_path': local_path})
            if response.status_code == 200:
                data = response.json()['data']
                for auction_info in data:
                    auction_model = Auction()
                    auction_model.purchase_number = auction_info.get('purchaseNumber')
                    auction_model.notice_id = auction_info.get('noticeId')
                    auction_model.type_name = auction_info.get('typeName')
                    db.session.add(auction_model)
                count = len(data)
                db.session.commit()
                return jsonify({'status': True,
                                'report': f'saved {count} auctions ID'})

            return jsonify({'status': False,
                            'error': {'code': response.status_code,
                                      'title': response.status_code,
                                      'detail': 'ERROR'}})

        except requests.exceptions.ConnectionError:
            return jsonify({'status': False,
                            'error': {'message': 'Сервис временно не доступен'}})

    return jsonify({'status': False,
                    'error': {'message': 'Ссылка на локальные файлы не получена <local_path>'}})
示例#2
0
def create():
    form = CreateForm()
    all_users = User.query.order_by(db.func.lower(User.username))
    form.usernames.choices = [(u.username, u.username) for u in all_users]
    if form.validate_on_submit():
        users = [
            User.query.filter_by(username=username).first()
            for username in form.usernames.data
        ]
        pool = Pool()
        pool.new_from_cube()
        auction = Auction(starting_balance=form.starting_balance.data,
                          time_limit=form.time_limit.data,
                          default_lot=form.default_lot.data,
                          pool=pool,
                          users=users,
                          creator=current_user)
        if form.first_nom.data:
            auction.add_lot(card=form.first_nom.data)
        else:
            auction.add_lot(size=form.default_lot.data)
        db.session.add(auction)
        db.session.flush()
        for user in users:
            new_balance = Balance(holder=user,
                                  auction=auction,
                                  amount=form.starting_balance.data)
            db.session.add(new_balance)
        db.session.commit()
        return redirect(url_for("auction", auction_id=auction.id))
    return render_template("create.html",
                           title="New Draft",
                           form=form,
                           cube_cards=cube_cards)
示例#3
0
def newbook():
    form = UploadBookForm()

    if 'email' not in session:
        return redirect(url_for('auth.signin'))

    if request.method == 'POST':
        uid = db.session.query(
            User.user_id).filter(User.email == session['email']).scalar()

        isbnImg = "isbn" + str(form.isbn.data)
        image = api.list(isbnImg)

        sThumbnail = image['items'][0]['volumeInfo']['imageLinks'][
            'smallThumbnail']
        lThumbnail = image['items'][0]['volumeInfo']['imageLinks']['thumbnail']

        book = Book(isbn=form.isbn.data,
                    title=form.title.data,
                    volume=form.volume.data,
                    author=form.author.data,
                    publisher=form.publisher.data,
                    year=form.year.data,
                    subject=form.subject.data,
                    user_id=uid,
                    smallThumbnail=sThumbnail,
                    largeThumbnail=lThumbnail)
        db.session.add(book)
        db.session.commit()

        auction = Auction(book_id=book.book_id,
                          start_time=datetime.now(),
                          end_time=form.endDate.data)
        db.session.add(auction)
        db.session.commit()

        return redirect(url_for('member.profile'))

    elif request.method == 'GET':
        return render_template('member/newbook.html', form=form)
示例#4
0
文件: cbid.py 项目: griu/bidhistory
    def parse_item(self, item):
        '''
        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.
        '''
        keywords = [
            'toro', 'robusto', 'belicoso', 'connecticut', 'maduro', 'churchill',
            'torpedo', 'corona', 'single', 'lonsdale', 'corojo', 'sumatra',
            'magnum', 'maestro', 'brillantes', 'series \'a\'', 'imperial',
            'box-press', 'gigante', 'shorty', 
        ]
        aid = item.findChild('td', {'class': 'cb_wcb cb_colsm'}).findNext('span').get('data-id')
        auction = Auction.query.filter_by(aid=aid, site='cbid').first()

        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.
            link = 'http://www.cigarbid.com%s' % item.findNext('a').get('href')
            title = item.findNext('a').text
            category = item.findNext('a').findNext('span').text
            auction = Auction()

            try:
                # Not all Boxes are in the boxes part of the auction.  We will
                # will instead leverage the commonality of the title formatting
                # to pull all of these.
                auction.name, auction.quantity = re.findall(r'^([\W\w]+) \((\d{1,3})\)', title)[0]
                auction.type = 'box'
            except IndexError:
                auction.name = title
                if category == 'Boxes':
                    try:
                        auction.name, auction.quantity = re.findall(r'^([\W\w]+) \((\d{1,3})\)', title)[0]
                        auction.type = 'box'
                    except IndexError:
                        pass
                elif category == '5-Packs':
                    # The next way we can handle this is to look for all of the
                    # 5-Packs in the response and set the quantity to 5.
                    auction.quantity = 5
                    auction.type = '5-pack'
                elif category == 'Singles':
                    # Singles should always be a quantity of 1.
                    auction.quantity = 1
                    auction.type = 'single'
                #elif category in ['Specials', 'Samplers', 'Quick-ies']:
                if not auction.quantity:
                    # These 3 categories are some genetal catch-all categories
                    # and we need to handle the information in a more generic
                    # way.

                    # First lets run through some of the more common paths that
                    # peopl take...
                    if '5 cigars' in title.lower():
                        auction.type = '5-pack'
                        auction.quantity = 5
                    elif '10 cigars' in title.lower():
                        auction.type = '10-pack'
                        auction.quantity = 10
                    if '-pack' in title.lower():
                        matches = re.findall(r'(\d{1,3})-pack', title.lower())
                        if len(matches) > 0:
                            auction.type = '%s-pack' % matches[0]
                            auction.quantity = int(matches[0])
                    elif '5 cigars' in title.lower():
                        auction.type = '5-pack'
                        auction.quantity = 5
                    elif '10 cigars' in title.lower():
                        auction.type = '10-pack'
                        auction.quantity = 10
                    elif 'pack of 5' in title.lower():
                        auction.type = '5-pack'
                        auction.quantity = 5
                    elif 'pack of 10' in title.lower():
                        auction.type = '10-pack'
                        auction.quantity = 10                    
                    elif ' cigars' in title.lower(): 
                        matches = re.findall(r'(\d{1,3})[ -]cigars', title.lower())
                        if len(matches) > 0:
                            auction.type = 'bundle'
                            auction.quantity = int(matches[0])
                    elif 'single' in title.lower():
                        auction.type = 'single'
                        auction.quantity = 1
                    elif 'sampler' in title.lower():
                        auction.type = 'sampler'
                    else:
                        matches = re.findall(r'(\w+) of (\d{1,3})', title.lower())
                        if len(matches) > 0:
                            auction.type = matches[0][0]
                            auction.quantity = int(matches[0][1])
                            if auction.type in ['brick',]:
                                auction.type = 'bundle'

                    if not auction.quantity:
                        for keyword in keywords:
                            # If all else has failed, we have a list of keywords
                            # that would let us know of the title is referring to
                            # cigars or some other merch.  If any of these match,
                            # then we will consider it a single.
                            if keyword in title.lower():
                                auction.quantity = 1
                if not auction.quantity:
                    # Well none of the above options matched, so this doesn't
                    # appear to be a Cigar listing.  Lets abort, throw a pretty
                    # message, and get on with it.
                    logging.debug('ABORTING %s:%s:%s' % (aid, category, title))
                    return
                else:
                    logging.debug('CREATED %s:%s:%s:%s' % (aid, category, auction.quantity, title))
            auction.site = 'cbid'
            auction.link = link
            auction.aid = item.find('span', {'class': 'add'}).get('data-id')
            auction.close = self.timestamp_gen(item.find('td', {'class': 'cb_product_timeleft'}).text)
            #brand.auctions.append(auction)
            db.session.add(auction)

        # now we need to get the current price and update the timestamp.
        cprice = item.find('td', {'class': 'cb_product_current_price'}).findNext('span').text.strip('$')
        if cprice is not u'':
            auction.price = float(cprice)
        auction.timestamp = datetime.now()

        # Now we need to commit the changes to the database ;)
        db.session.commit()
示例#5
0
    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()
示例#6
0
    def parse_item(self, item):
        """
        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.
        """
        keywords = [
            "toro",
            "robusto",
            "belicoso",
            "connecticut",
            "maduro",
            "churchill",
            "torpedo",
            "corona",
            "single",
            "lonsdale",
            "corojo",
            "sumatra",
            "magnum",
            "maestro",
            "brillantes",
            "series 'a'",
            "imperial",
            "box-press",
            "gigante",
            "shorty",
        ]
        aid = item.findChild("td", {"class": "cb_wcb cb_colsm"}).findNext("span").get("data-id")
        auction = Auction.query.filter_by(aid=aid, site="cbid").first()

        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.
            link = "http://www.cigarbid.com%s" % item.findNext("a").get("href")
            title = item.findNext("a").text
            category = item.findNext("a").findNext("span").text
            auction = Auction()

            try:
                # Not all Boxes are in the boxes part of the auction.  We will
                # will instead leverage the commonality of the title formatting
                # to pull all of these.
                auction.name, auction.quantity = re.findall(r"^([\W\w]+) \((\d{1,3})\)", title)[0]
                auction.type = "box"
            except IndexError:
                auction.name = title
                if category == "Boxes":
                    try:
                        auction.name, auction.quantity = re.findall(r"^([\W\w]+) \((\d{1,3})\)", title)[0]
                        auction.type = "box"
                    except IndexError:
                        pass
                elif category == "5-Packs":
                    # The next way we can handle this is to look for all of the
                    # 5-Packs in the response and set the quantity to 5.
                    auction.quantity = 5
                    auction.type = "5-pack"
                elif category == "Singles":
                    # Singles should always be a quantity of 1.
                    auction.quantity = 1
                    auction.type = "single"
                # elif category in ['Specials', 'Samplers', 'Quick-ies']:
                if not auction.quantity:
                    # These 3 categories are some genetal catch-all categories
                    # and we need to handle the information in a more generic
                    # way.

                    # First lets run through some of the more common paths that
                    # peopl take...
                    if "5 cigars" in title.lower():
                        auction.type = "5-pack"
                        auction.quantity = 5
                    elif "10 cigars" in title.lower():
                        auction.type = "10-pack"
                        auction.quantity = 10
                    if "-pack" in title.lower():
                        matches = re.findall(r"(\d{1,3})-pack", title.lower())
                        if len(matches) > 0:
                            auction.type = "%s-pack" % matches[0]
                            auction.quantity = int(matches[0])
                    elif "5 cigars" in title.lower():
                        auction.type = "5-pack"
                        auction.quantity = 5
                    elif "10 cigars" in title.lower():
                        auction.type = "10-pack"
                        auction.quantity = 10
                    elif "pack of 5" in title.lower():
                        auction.type = "5-pack"
                        auction.quantity = 5
                    elif "pack of 10" in title.lower():
                        auction.type = "10-pack"
                        auction.quantity = 10
                    elif " cigars" in title.lower():
                        matches = re.findall(r"(\d{1,3})[ -]cigars", title.lower())
                        if len(matches) > 0:
                            auction.type = "bundle"
                            auction.quantity = int(matches[0])
                    elif "single" in title.lower():
                        auction.type = "single"
                        auction.quantity = 1
                    elif "sampler" in title.lower():
                        auction.type = "sampler"
                    else:
                        matches = re.findall(r"(\w+) of (\d{1,3})", title.lower())
                        if len(matches) > 0:
                            auction.type = matches[0][0]
                            auction.quantity = int(matches[0][1])
                            if auction.type in ["brick"]:
                                auction.type = "bundle"

                    if not auction.quantity:
                        for keyword in keywords:
                            # If all else has failed, we have a list of keywords
                            # that would let us know of the title is referring to
                            # cigars or some other merch.  If any of these match,
                            # then we will consider it a single.
                            if keyword in title.lower():
                                auction.quantity = 1
                if not auction.quantity:
                    # Well none of the above options matched, so this doesn't
                    # appear to be a Cigar listing.  Lets abort, throw a pretty
                    # message, and get on with it.
                    logging.debug("ABORTING %s:%s:%s" % (aid, category, title))
                    return
                else:
                    logging.debug("CREATED %s:%s:%s:%s" % (aid, category, auction.quantity, title))
            auction.site = "cbid"
            auction.link = link
            auction.aid = item.find("span", {"class": "add"}).get("data-id")
            auction.close = self.timestamp_gen(item.find("td", {"class": "cb_product_timeleft"}).text)
            # brand.auctions.append(auction)
            db.session.add(auction)

        # now we need to get the current price and update the timestamp.
        cprice = item.find("td", {"class": "cb_product_current_price"}).findNext("span").text.strip("$")
        if cprice is not u"":
            auction.price = float(cprice)
        auction.timestamp = datetime.now()

        # Now we need to commit the changes to the database ;)
        db.session.commit()