Skip to content

Instantly share code, notes, and snippets.

@iezg
Created September 27, 2012 09:10
Show Gist options
  • Save iezg/3793033 to your computer and use it in GitHub Desktop.
Save iezg/3793033 to your computer and use it in GitHub Desktop.
Get the attribute of an iTunes Store's application by bundle Id
# 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