File: ranking.py

package info (click to toggle)
python-googleapi 2.186.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 553,432 kB
  • sloc: python: 11,087; javascript: 249; sh: 114; makefile: 59
file content (47 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2014 Google Inc. All Rights Reserved.

"""Query with ranked results against the shopping search API"""

import pprint

from googleapiclient.discovery import build


SHOPPING_API_VERSION = "v1"
DEVELOPER_KEY = "<YOUR DEVELOPER KEY>"


def main():
    """Get and print a feed of public products in the United States mathing a
    text search query for 'digital camera' ranked by ascending price.

    The list method for the resource should be called with the "rankBy"
    parameter.  5 parameters to rankBy are currently supported by the API. They
    are:

    "relevancy"
    "modificationTime:ascending"
    "modificationTime:descending"
    "price:ascending"
    "price:descending"

    These parameters can be combined

    The default ranking is "relevancy" if the rankBy parameter is omitted.
    """
    client = build("shopping", SHOPPING_API_VERSION, developerKey=DEVELOPER_KEY)
    resource = client.products()
    # The rankBy parameter to the list method causes results to be ranked, in
    # this case by ascending price.
    request = resource.list(
        source="public", country="US", q="digital camera", rankBy="price:ascending"
    )
    response = request.execute()
    pprint.pprint(response)


if __name__ == "__main__":
    main()