Skip to content

Commit f1dbcf1

Browse files
committed
Merge pull request #9 from tuftedocelot/CategoryListings
Support CategoryListings
2 parents bb3aab7 + 905e914 commit f1dbcf1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ Batch ``SitesLinkingIn`` requests::
3333

3434
tree = api.sites_linking_in(['metmuseum.org', 'wikipedia.org'])
3535

36+
Making ``CategoryListings`` requests::
37+
38+
api = AwisApi(ACCESS_ID, SECRET_ACCESS_KEY)
39+
tree = api.category_listings("Top/Business/Financial_Services")
40+
for item in tree.findall("//{%s}DataUrl" % api.NS_PREFIXES["awis"]): print(item.text)
41+
3642

3743
Changelog
3844
=========

awis/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class AwisApi(object):
6666
}
6767
MAX_BATCH_REQUESTS = 5
6868
MAX_SITES_LINKING_IN_COUNT = 20
69+
MAX_CATEGORY_LISTINGS_COUNT = 20
6970

7071
def __init__(self, access_id, secret_access_key):
7172
self.access_id = access_id
@@ -107,6 +108,24 @@ def request(self, params, tries=3, as_xml=True):
107108
),
108109
)
109110

111+
def category_listings(self, path, SortBy="Popularity", Recursive=False, Start=1, Count=MAX_CATEGORY_LISTINGS_COUNT, Descriptions=False):
112+
params = { "Action": "CategoryListings", "ResponseGroup": "Listings" }
113+
params.update({ "Path": urllib.quote(path) })
114+
params.update({"SortBy": SortBy})
115+
if not Recursive:
116+
params.update({"Recursive": "False"})
117+
else:
118+
params.update({"Recursive": "True"})
119+
params.update({"Start":str(Start)})
120+
if Count > self.MAX_CATEGORY_LISTINGS_COUNT:
121+
raise RuntimeError, "Max number of returned listings is %s." % self.MAX_CATEGORY_LISTINGS_COUNT
122+
if not Descriptions:
123+
params.update({"Descriptions": "False"})
124+
else:
125+
params.update({"Descriptions": "True"})
126+
127+
return self.request(params)
128+
110129
def url_info(self, urls, *response_groups, **kwargs):
111130
params = { "Action": "UrlInfo" }
112131
if not isinstance(urls, (list, tuple)):

0 commit comments

Comments
 (0)