-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (64 loc) · 1.86 KB
/
main.py
File metadata and controls
81 lines (64 loc) · 1.86 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2014 Google Inc. All Rights Reserved.
"""Simple command-line example for The Google Search
API for Shopping.
Command-line application that does a search for products.
"""
from __future__ import print_function
__author__ = "aherrman@google.com (Andy Herrman)"
from googleapiclient.discovery import build
# Uncomment the next line to get very detailed logging
# httplib2.debuglevel = 4
def main():
p = build("shopping", "v1", developerKey="<YOUR DEVELOPER KEY>")
# Search over all public offers:
print("Searching all public offers.")
res = (
p.products().list(country="US", source="public", q="android t-shirt").execute()
)
print_items(res["items"])
# Search over a specific merchant's offers:
print()
print("Searching Google Store.")
res = (
p.products()
.list(
country="US",
source="public",
q="android t-shirt",
restrictBy="accountId:5968952",
)
.execute()
)
print_items(res["items"])
# Remember the Google Id of the last product
googleId = res["items"][0]["product"]["googleId"]
# Get data for the single public offer:
print()
print("Getting data for offer %s" % googleId)
res = (
p.products()
.get(
source="public",
accountId="5968952",
productIdType="gid",
productId=googleId,
)
.execute()
)
print_item(res)
def print_item(item):
"""Displays a single item: title, merchant, link."""
product = item["product"]
print(
"- %s [%s] (%s)"
% (product["title"], product["author"]["name"], product["link"])
)
def print_items(items):
"""Displays a number of items."""
for item in items:
print_item(item)
if __name__ == "__main__":
main()