예제 #1
0
def test_parse():
    import random
    import string
    from app.utils import parse

    assert parse("") == ""
    assert parse("Ipad pro") == "Ipad+pro"
    assert parse("Macbook pro 13 inch 512 gb") == "Macbook+pro+13+inch+512+gb"
예제 #2
0
def update(pid=None):
    """ Updates the database

    Args:
        pid (str): Package id of the package to update.
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    sync = kwargs.pop('sync', False)
    whitelist = [
        'CHUNK_SIZE', 'ROW_LIMIT', 'ERR_LIMIT', 'MOCK_FREQ', 'TIMEOUT',
        'RESULT_TTL']

    with app.app_context():
        defaults = {
            k.lower(): v for k, v in app.config.items() if k in whitelist}

        opts = defaultdict(int, pid=pid, **defaults)
        opts.update(kwargs)
        base = 'http://%(HOST)s:%(PORT)s%(API_URL_PREFIX)s' % app.config
        endpoint = '%s/age' % base

        if sync:
            resp = {'result': utils.update(endpoint, **opts)}
        else:
            job = q.enqueue(utils.update, endpoint, **opts)
            result_url = '%s/result/%s/' % (base, job.id)

            resp = {
                'job_id': job.id,
                'job_status': job.get_status(),
                'result_url': result_url}

        return jsonify(**resp)
예제 #3
0
def category():
    """Get all eBay categories

    Kwargs:
        country (str): eBay country (one of ['US', 'UK'], default: 'US')
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    return jsonify(objects=get_categories(**kwargs))
예제 #4
0
def search():
    """Perform an eBay site search

    Kwargs:
        q (str): The search term(s) (either this or the 'cid'
            parameter is required)

        cid (int): ID of the category to display (either this or the 'q'
            parameter is required)

        country (str): eBay country (one of ['US', 'UK'], default: 'US')
        verb (str): The type of search to perform (one of ['findCompletedItems',
            'findItemsAdvanced', 'findItemsByCategory', 'findItemsByKeywords',
            'findItemsByProduct', 'findItemsIneBayStores', 'getHistograms'],
            default: 'findItemsAdvanced')

        sort_order (str): Sort order (one of ['BestMatch',
            'CurrentPriceHighest', 'DistanceNearest', 'EndTimeSoonest',
            'PricePlusShippingHighest', 'PricePlusShippingLowest',
            'StartTimeNewest'], default: 'EndTimeSoonest')

        limit (int): Number of results to return (default: 10)
        page (int): The results page to view (default: 1)
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    query = kwargs.pop('q', None)
    cid = kwargs.pop('cid', None)

    if query:
        kwargs.setdefault('keywords', query)

    if cid:
        kwargs.setdefault('categoryId', cid)

    kwargs.setdefault('sortOrder', kwargs.pop('sort_order', 'EndTimeSoonest'))
    kwargs.setdefault('verb', 'findItemsAdvanced')
    limit = kwargs.pop('limit', 10)
    page = kwargs.pop('page', 1)
    finding = Finding(**kwargs)

    options = {'paginationInput': {'entriesPerPage': limit, 'pageNumber': page}}
    options.update(kwargs)

    try:
        response = finding.search(options)
    except ConnectionError as err:
        result = str(err)
        status = 500
    else:
        result = finding.parse(response)
        status = 200

    return jsonify(status, objects=result)
예제 #5
0
def status():
    """ Displays the current status
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    ckan = CKAN(**kwargs)

    resp = {
        'online': True,
        'message': 'Service for checking and updating HDX dataset ages.',
        'CKAN_instance': ckan.address,
        'version': __version__,
        'repository': c.REPO
    }

    return jsonify(**resp)
예제 #6
0
def status():
    """ Displays the current status
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    ckan = CKAN(**kwargs)

    resp = {
        'online': True,
        'message': 'Service for checking and updating HDX dataset ages.',
        'CKAN_instance': ckan.address,
        'version': __version__,
        'repository': c.REPO
    }

    return jsonify(**resp)
예제 #7
0
def ship(item_id):
    """Calculate an item's shipping cost

    Args:
        item_id (str): ID of item to ship

    Kwargs:
        country (str): origin country (one of ['US', 'UK'], default: 'US')
        dest (str): destination country (see
            http://www.airlinecodes.co.uk/country.asp for valid codes,
            default: 'US')

        code (str): destination postal code (required if 'dest' is 'US')
        details (bool): include details? (default: False)
        quantity (int): quantity to ship (default: 1)
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    dest = kwargs.pop('dest', 'US')
    code = kwargs.pop('code', None)
    details = kwargs.pop('details', None)
    quantity = kwargs.pop('quantity', None)
    options = {
        'ItemID': item_id, 'MessageID': item_id, 'DestinationCountryCode': dest}

    if code:
        options['DestinationPostalCode'] = code

    if details:
        options['IncludeDetails'] = details

    if quantity:
        options['QuantitySold'] = quantity

    options.update(kwargs)
    shopping = Shopping(**kwargs)

    try:
        response = shopping.search(options)
    except ConnectionError as err:
        result = str(err)
        status = 500
    else:
        result = shopping.parse(response)
        status = 200

    return jsonify(status, objects=result)
예제 #8
0
def sub_category(name=None, cid=None):
    """Get all subcategories of a given eBay category

    Args:
        cid (int): eBay category ID, e.g., 267
        name (str): eBay category name, e.g., 'Books'

    Kwargs:
        country (str): eBay country (one of ['US', 'UK'], default: 'US')
    """
    if not (name or cid):
        return jsonify(400, objects="Either 'name' or 'id' must be provided")

    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    trading = Trading(**kwargs)
    url = url_for('blueprint.category', _external=True)
    msg = "Category {} doesn't exist. View {} to see valid categories."

    if name and not cid:
        categories = get_categories(**kwargs)
        lookup = trading.make_lookup(categories)

        try:
            cid = lookup[unquote(name.lower())]['id']
        except KeyError:
            pass

    response = trading.get_hierarchy(cid) if cid else None

    try:
        result = trading.parse(response.CategoryArray.Category)
    except AttributeError:
        result = msg.format(name, url)
        status = 404
    except TypeError:
        result = msg.format(cid, url)
        status = 404
    else:
        status = 200

    return jsonify(status, objects=result)
예제 #9
0
def item(item_id):
    """Get an item's details

    Args:
        item_id (str): item ID

    Kwargs:
        country (str): eBay country (one of ['US', 'UK'], default: 'US')
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}

    try:
        trading = Trading(**kwargs)
    except ConnectionError as err:
        result = str(err)
        status = 500
    else:
        response = trading.get_item(item_id)
        result = response['Item']
        status = 200

    return jsonify(status, objects=result)
예제 #10
0
def update(pid=None):
    """ Updates the database

    Args:
        pid (str): Package id of the package to update.
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    sync = kwargs.pop('sync', False)
    whitelist = [
        'CHUNK_SIZE', 'ROW_LIMIT', 'ERR_LIMIT', 'MOCK_FREQ', 'TIMEOUT',
        'RESULT_TTL'
    ]

    with app.app_context():
        defaults = {
            k.lower(): v
            for k, v in app.config.items() if k in whitelist
        }

        opts = defaultdict(int, pid=pid, **defaults)
        opts.update(kwargs)
        base = 'http://%(HOST)s:%(PORT)s%(API_URL_PREFIX)s' % app.config
        endpoint = '%s/age' % base

        if sync:
            resp = {'result': utils.update(endpoint, **opts)}
        else:
            job = q.enqueue(utils.update, endpoint, **opts)
            result_url = '%s/result/%s/' % (base, job.id)

            resp = {
                'job_id': job.id,
                'job_status': job.get_status(),
                'result_url': result_url
            }

        return jsonify(**resp)
예제 #11
0
 def post(self, start=None, end=None):
     info = {"description": "Transfer PriceCloser orders to Cloze"}
     kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
     response = transfer_orders(start=start, end=end, **kwargs)
     response.update(info)
     return jsonify(**response)
예제 #12
0
 def patch(self, order_id):
     info = {"description": "Transfer a PriceCloser order to Cloze"}
     kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
     response = transfer_orders(order_id, **kwargs)
     response.update(info)
     return jsonify(**response)