Beispiel #1
0
def getAppAndCommunity(message, user):
    if message.team_key:
        community = Community.getCommunityFromTeamKey(team_key=message.team_key)
        appinfo = getAppInfo(community.key.id())

    elif message.app_name:
        appinfo = AppInfo.get(name=message.app_name, platform=message.platform_type)
        community = None

        if appinfo is None:
            appInfoMessage = AppInfoMessage(name=message.app_name, version=message.app_version,
                                            platform=message.platform_type)
            appinfo = AppInfo.insert(appInfoMessage)
        else:
            app_community = getCommunityForApp(id=appinfo.key.id())
            if app_community and isMember(app_community, user):
                community = app_community

    elif message.community_name:
        community_id = Community.getCommunity(community_name=message.community_name).id
        community = Community.get_by_id(community_id)
        appinfo = getAppInfo(community_id)

    else:
        raise endpoints.BadRequestException("Please specify a community or app")

    return appinfo, community
Beispiel #2
0
	def _process_store_data(cls, data, update=True):
		'''
		Internal, parse the Query data
		and populate the database, for Play Store only
		'''
		parser = GooglePlayStoreScraper()

		if data:
			parser.feed(data.decode('utf-8'))
			apps = parser.apps
		else:
			apps = []

		for app in apps:
			entity = AppInfo(
				name=app.get('name'),
				bundleid=app.get('docid'),
				icon=None,
				icon_url=app.get('image-small'),
				description=app.get('description'),
				version=None,
				developer=app.get('developer'),
				company_name=app.get('developer'),
				app_url=app.get('link'),
				platform=PlatformType.ANDROID
			)
			if update: AppInfo.update(entity)

		logging.getLogger().debug("Inserted %s successfully", len(apps))
		return apps
Beispiel #3
0
	def app_store_search(cls, update=True, **parameters):
		'''
		Run the Search Query on the Apple App Store
		and thereafter populate the database
		'''
		apps = iTunesAppStoreRSSAndSearch.search(**parameters)
		if apps:
			apps = json.loads(apps)
		else:
			return []

		for app in apps.get('results', []):
			entity = AppInfo(
				name=app.get('trackName'),
				bundleid=app.get('bundleId'),
				icon=None,
				icon_url=app.get('artworkUrl60'),
				description=app.get('description'),
				version=None,
				developer=app.get('artistName'),
				company_name=app.get('artistName'),
				app_url=app.get('trackViewUrl'),
				platform=PlatformType.IOS
			)
			if update: AppInfo.update(entity)

		return apps.get('results', [])
Beispiel #4
0
	def app_store_fetch(cls, **parameters):
		'''
		Run the Fetch Query on the Apple App Store
		and thereafter populate the database
		'''
		data = iTunesAppStoreRSSAndSearch.fetch(**parameters)
		if data:
			apps = iTunesAppStoreRSSAndSearch.parse_xml(data)
		else:
			apps = []
		for app in apps:
			entity = AppInfo(
				name=app.get('name'),
				bundleid=app.get('bundleid'),
				icon=None,
				icon_url=app.get('image53'),
				description=app.get('summary'),
				version=None,
				developer=app.get('artist'),
				company_name=app.get('artist'),
				app_url=app.get('link'),
				platform=PlatformType.IOS
			)
			AppInfo.update(entity)

		logging.getLogger().debug("Inserted %s successfully", len(apps))
		return apps
def create_teams():
    team_key = ""
    app_name = ""
    community_name = ""
    admin_user_email = ""
    other_users_email = []

    app = AppInfo.query().filter(AppInfo.lc_name == app_name.lower()).get()
    if not app:
        appinfo_message = AppInfoMessage()
        appinfo_message.name = app_name
        app = AppInfo.insert(appinfo_message)

    community = Community.getCommunityFromTeamKey(team_key=team_key)
    if not community:
        community_message = CommunityMessage(name=community_name,
                                             team_key=team_key,
                                             team_secret=md5(community_name.lower()))
        community_message.user = UserMessage(user_email=admin_user_email)
        Community.insert(community_message)
        community = Community.getCommunityFromTeamKey(team_key=team_key)

    if community and app:
        if not app.key in community.apps:
            community.apps.append(app.key)
            community.put()

    for user_email in other_users_email:
        user = User.find_user_by_email(email=user_email, team_key=team_key)
        if not user:
            user = User.insert_user(user_email, account_type=team_key, image_url="")
        userrole = UserRole.insert(user, community)
Beispiel #6
0
def getCommunityForApp(id=None, app_name=None):
    if id:
        app = AppInfo.get_by_id(id)
    elif app_name:
        app = AppInfo.get(name=app_name)

    app_community = None
    if app:
        communities = Community.query().fetch()
        for community in communities:
            if app.key in community.apps:
                app_community = community
                break

    return app_community
Beispiel #7
0
def getAppInfo(community_id=None, team_key=None):
    community_apps = getCommunityApps(community_id, team_key, app_count=1)
    if len(community_apps):
        appinfo = AppInfo.get_by_id(community_apps[0].id())
    else:
        raise endpoints.NotFoundException("Selected community doesn't have any app associated with it. Please select another option.")
    return appinfo
Beispiel #8
0
	def scan_for_unknown_apps(cls, platforms=[StoreTypeEnum.PLAY_STORE, StoreTypeEnum.APP_STORE], auto_update=True):
		apps = AppInfo.get_unknown()
		all_apps = []
		for app in apps:
			if StoreTypeEnum.PLAY_STORE in platforms:
				# Search the Play Store, this update any matched items in the database
				play_store_apps = AppInfoPopulate.play_store_search(term=app.name, update=auto_update)
				# Only if the first app is an exact match
				if len(play_store_apps) > 0:
					first_app = play_store_apps[0]
					if first_app.get('name') == app.name:
						# we have a match
						# Nothing to do this has already probably merged
						pass
					all_apps += play_store_apps

			if StoreTypeEnum.APP_STORE in platforms:
				# Search the App Store
				# This will update any matched items in the database
				app_store_apps = AppInfoPopulate.app_store_search(term=app.name, update=auto_update)
				print app_store_apps
				if len(app_store_apps) > 0:
					first_app = app_store_apps[0]
					if first_app.get('name') == app.name:
						# we have a match
						# Nothing to do this has already probably merged
						pass
					all_apps += app_store_apps

		return all_apps
Beispiel #9
0
    def generate_appkey(self, request):
        """
        Exposes an API endpoint to generate an app key for a register 3rd-party app developer.
        """
        app_name = request.app_name
        if is_empty_string(app_name):
            raise endpoints.BadRequestException('app_name is required.')
        company_name = request.company_name
        if is_empty_string(company_name):
            raise endpoints.BadRequestException('company_name is required.')

        appinfo = AppInfo.get_appinfo(request)
        exists = (appinfo is not None)
        if not exists:
            appinfo = AppInfo.insert_appinfo(request)
        appinfo_message = appinfo.to_message()
        appinfo_message.is_registered = exists
        return appinfo_message
def migrate_photo_time_annos(cursor=None):
    team_key = 'us.orbe.Reko-Album'
    phototime_app = AppInfo.query().filter(AppInfo.lc_name == 'phototime').get()
    phototime_community = Community.getCommunityFromTeamKey(team_key=team_key)
    anno_list = Anno.query().filter(Anno.app == phototime_app.key).fetch()

    for anno in anno_list:
        anno.community = phototime_community.key
        user_email = anno.creator.get().user_email
        anno.creator = User.find_user_by_email(email=user_email, team_key=team_key).key
        anno.put()
Beispiel #11
0
    def addApp(cls, request):
        entity = None
        community_id = request.community.id
        appinfo_id = request.app.id
        community = cls.get_by_id(community_id) if community_id else None
        app = AppInfo.get_by_id(appinfo_id) if appinfo_id else None

        if community and app:
            if not app.key in community.apps:
                community.apps.append(app.key)
                entity = community.put()
        return entity
def add_lowercase_appname(cursor=None):
    appinfo_list, cursor, more = AppInfo.query().fetch_page(BATCH_SIZE, start_cursor=cursor)

    appinfo_update_list = []
    for appinfo in appinfo_list:
        if not appinfo.lc_name:
            appinfo.lc_name = appinfo.name.lower()
            appinfo_update_list.append(appinfo)

    if len(appinfo_update_list):
        ndb.put_multi(appinfo_update_list)

    if more:
        add_lowercase_appname(cursor=cursor)
Beispiel #13
0
    def anno_list(self, request):
        """
        Exposes an API endpoint to retrieve a list of anno.
        """
        user = auth_user(self.request_state.headers)

        limit = 10
        if request.limit is not None:
            limit = request.limit

        is_plugin = request.is_plugin or False

        curs = None
        if request.cursor is not None:
            try:
                curs = Cursor(urlsafe=request.cursor)
            except BadValueError:
                raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor)

        select_projection = None
        if request.select is not None:
            select_projection = request.select.split(',')

        if request.query_type == AnnoQueryType.CREATED:
            return Anno.query_by_app_by_created(request.app, limit, select_projection, curs, user)
        elif request.query_type == AnnoQueryType.VOTE_COUNT:
            return Anno.query_by_vote_count(request.app, user)
        elif request.query_type == AnnoQueryType.FLAG_COUNT:
            return Anno.query_by_flag_count(request.app, user)
        elif request.query_type == AnnoQueryType.ACTIVITY_COUNT:
            return Anno.query_by_activity_count(request.app, user)
        elif request.query_type == AnnoQueryType.LAST_ACTIVITY:
            return Anno.query_by_last_activity(request.app, user)
        elif request.query_type == AnnoQueryType.COUNTRY:
            return Anno.query_by_country(request.app, user)
        elif request.query_type == AnnoQueryType.COMMUNITY:
            community = Community.get_by_id(request.community)
            return Anno.query_by_community(community, limit, select_projection, curs, user)
        elif request.query_type == AnnoQueryType.APP:
            app = AppInfo.get(request.app)
            return Anno.query_by_app(app, limit, select_projection, curs, user)
        else:
            return Anno.query_by_page(limit, select_projection, curs, user, is_plugin)
Beispiel #14
0
    def create_sdk_team(cls, message, pricing_plan=False, stripe_token=None):
        team_key = message.team_key
        app_name = message.app.name
        community_name = message.community_name or app_name
        plan = message.plan or PlanType.BASIC

        app = AppInfo.query().filter(AppInfo.lc_name == app_name.lower()).get()
        if not app:
            appinfo_message = AppInfoMessage()
            appinfo_message.name = app_name
            appinfo_message.icon_url = message.app.icon_url
            appinfo_message.version = message.app.version
            app = AppInfo.insert(appinfo_message)

        from helper.utils import md5
        community_message = CommunityMessage(name=community_name,
                                             team_key=team_key,
                                             team_secret=md5(community_name.lower()),
                                             plan=plan)
        community_message.user = UserMessage(user_email=message.admin_user.user_email,
                                             display_name=message.admin_user.display_name,
                                             password=message.admin_user.password)
        community, user = cls.insert(community_message, getCommunity=True)

        communities_message = []
        if community and app:
            if not app.key in community.apps:
                community.apps.append(app.key)
                community.put()

            # response message
            community_message = CommunityAdminMasterMessage()
            community_message.community_name = community.name
            community_message.team_key = community.team_key
            community_message.team_secret = community.team_secret
            # community_message.team_hash = community.team_hash
            community_message.app_name = app.name
            community_message.app_icon = app.icon_url

            community_message.users = []
            from model.userrole import UserRole

            user_message = UserAdminMasterMessage()
            user_message.display_name = user.display_name
            user_message.user_email = user.user_email
            user_message.password_present = True if user.password else False
            user_message.role = UserRole.getRole(user, community)
            user_message.image_url = user.image_url

            if community.circles:
                user_message.circle = community.circles.get(str(UserRole.getCircleLevel(user, community)))

            community_message.users.append(user_message)
            communities_message.append(community_message)
            registration_successful = True

            if pricing_plan:
                if stripe_token:
                    payment_success = StripePayment.create_charge(stripe_token, community.key, plan)
                    if not payment_success:
                        registration_successful = False
                else:
                    registration_successful = False

            if registration_successful:
                from helper.utils import send_created_team_email
                from helper.utils import send_access_team_email
                send_created_team_email(community.name, user.display_name)
                send_access_team_email(user.user_email, community.team_hash,
                                       community.name, community.team_key,
                                       community.team_secret)
            else:
                community.key.delete()
                communities_message = []

        return communities_message
Beispiel #15
0
 def update_appinfo(self, request):
     resp = AppInfo.update(request)
     return ResponseMessage(success=True if resp else None)
Beispiel #16
0
 def insert_appinfo(self, request):
     resp = AppInfo.insert(request)
     return ResponseMessage(success=True if resp else None)