def get_app_by_itunes_id(itunes_id, country): try: long(itunes_id) except (ValueError, TypeError): return None try: app = AppStoreApp.objects.get(itunes_id=itunes_id) except AppStoreApp.DoesNotExist: app = None if app and app.app_info_countries and country in app.app_info_countries: appstore_app_info.decorate_app(app, country) return app app_info = appstore_fetch.app_info_with_id(itunes_id, country) if not app_info: return None if not app: app = AppStoreApp(itunes_id=app_info.itunes_id, bundle_id=app_info.bundle_id) if not app.app_info_countries: app.app_info_countries = [country] elif country not in app.app_info_countries: app.app_info_countries.append(country) app.save() appstore_app_info.mark_app_needs_info_ingestion(app) appstore_app_info.update_app_info_with_fetched_data(app, app_info) appstore_app_info.decorate_app(app, country) return app
def fetch_info_and_maybe_update_app(app, country): fetched_app_info = appstore_fetch.app_info_with_id(app.itunes_id, country) if not fetched_app_info: # TODO(Taylor): Increment some counter or something so we can stop checking this thing eventually. logging.info('App removed or otherwise not available: %s (%s)', app.itunes_id, app.bundle_id) return try: update_app_info_with_fetched_data(app, fetched_app_info) except InternalError as e: logging.info('Could not update app info: %s app info: %s', e, fetched_app_info.__dict__)
def summary_view(request, country=None, app_id=None): app_info = appstore_fetch.app_info_with_id(app_id, country) if not app_info: return not_found() try: related_app_infos = appstore_fetch.related_app_infos_with_developer_id(app_info.developer_id, country) except: logging.exception('Problem fetching related app info') related_app_infos = [] return api_response({ 'app': app_info.to_dict(), 'related': [ai.to_tiny_dict() for ai in related_app_infos if ai.itunes_id != app_info.itunes_id], })
def example_from_itunes_id(itunes_id, country): info = appstore_fetch.app_info_with_id(itunes_id, country) app_name, app_tagline = text.app_name_tagline(info.name) example_website = { 'id': 'example', 'appName': app_name, 'tagline': app_tagline, 'longDescription': info.description, 'shortDescription': _short_description(info.description), 'itunesId': info.itunes_id, 'images': { 'screenshots': {'iPhone': [{'url': screenshot} for screenshot in info.screenshots]}, 'icon': {'url': info.icon_512}, } } return example_website
def summary_view(request, country=None, app_id=None): app_info = appstore_fetch.app_info_with_id(app_id, country) if not app_info: return not_found() try: related_app_infos = appstore_fetch.related_app_infos_with_developer_id( app_info.developer_id, country) except: logging.exception('Problem fetching related app info') related_app_infos = [] return api_response({ 'app': app_info.to_dict(), 'related': [ ai.to_tiny_dict() for ai in related_app_infos if ai.itunes_id != app_info.itunes_id ], })
def get_app_and_related_by_itunes_id(itunes_id, country): app_info = appstore_fetch.app_info_with_id(itunes_id, country) if not app_info: return None app_infos = appstore_fetch.related_app_infos_with_developer_id( app_info.developer_id, country) app_infos_by_itunes_id = dict((a.itunes_id, a) for a in app_infos) existing_app_ids = AppStoreApp.objects.filter( itunes_id__in=app_infos_by_itunes_id.keys()).values_list('itunes_id', flat=True) existing_app_ids = set(long(i) for i in existing_app_ids) apps_to_insert = [ AppStoreApp(itunes_id=a.itunes_id, bundle_id=a.bundle_id) for a in app_infos if long(a.itunes_id) not in existing_app_ids ] if apps_to_insert: AppStoreApp.objects.bulk_create(apps_to_insert) fetched_apps = list( AppStoreApp.objects.filter( itunes_id__in=[str(i) for i in app_infos_by_itunes_id])) for app in fetched_apps: app_info = app_infos_by_itunes_id[long(app.itunes_id)] if not app.app_info_countries: app.app_info_countries = [country] else: app.app_info_countries.append(country) app.save() appstore_app_info.mark_app_needs_info_ingestion(app) appstore_app_info.update_app_info_with_fetched_data(app, app_info) appstore_app_info.decorate_app(app, country) return fetched_apps
def example_from_itunes_id(itunes_id, country): info = appstore_fetch.app_info_with_id(itunes_id, country) app_name, app_tagline = text.app_name_tagline(info.name) example_website = { 'id': 'example', 'appName': app_name, 'tagline': app_tagline, 'longDescription': info.description, 'shortDescription': _short_description(info.description), 'itunesId': info.itunes_id, 'images': { 'screenshots': { 'iPhone': [{ 'url': screenshot } for screenshot in info.screenshots] }, 'icon': { 'url': info.icon_512 }, } } return example_website