Created
September 27, 2012 09:10
-
-
Save iezg/3793033 to your computer and use it in GitHub Desktop.
Get the attribute of an iTunes Store's application by bundle Id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
import requests, json | |
APPSTORE_URL = "http://itunes.apple.com/lookup?bundleId="; | |
def get_app_data_by_bundle_id(bundle_id): | |
"""Queries the iTunes store by app's bundle Id and if | |
the app exists, returns the app's data (dict)""" | |
query_result = requests.get(APPSTORE_URL+bundle_id).text | |
query_json = json.loads(query_result) | |
if query_json.get('resultCount') > 0: | |
# bundle_id is unique, no more than 1 result | |
app_data = query_json.get(u'results')[0] | |
return app_data | |
else: | |
raise Exception("Invalid application bundle Id: %s" % bundle_id) | |
def get_app_attr(bundle_id, attr): | |
"""Returns the given attribute from an app by bundle id""" | |
app_data = get_app_data_by_bundle_id(bundle_id) | |
return app_data[attr] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment