• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python initiators.query函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中asq.initiators.query函数的典型用法代码示例。如果您正苦于以下问题:Python query函数的具体用法?Python query怎么用?Python query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了query函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: search

    def search(self, term=None):
        if (term is None):
            template = Template(filename=TEMPLATE_BASE + "search.html")
            return template.render(model=None, title="Enter a Hostname, Location or Channel")
        else:
            print("Searching for {0}".format(term))
            repo = Repository()
            allchannels = repo.GetAllChannels()
            servers = query(allchannels).where(lambda x: x['Hostname'] == term).to_list()
            locations = query(allchannels).where(lambda x: x['Location'] == term).to_list()
            channels = query(allchannels).where(lambda x: x['Channel'] == term).to_list()
            template = Template(filename=TEMPLATE_BASE + "search.html")

            if (len(servers) > 0):
                to_return = servers
                title = "Found Server(s)"
            elif (len(locations) > 0):
                to_return = locations
                title = "Found Location(s)"
            elif (len(channels) > 0):
                to_return = channels
                title = "Found Channel(s)"
            else:
                to_return = []
                title = "Did not find any matches"

            if (to_return is not None):
               for row in to_return:
                   row.setdefault('URL', "/server?{0}".format(urlencode({'name':row['IPAddress']})))
            return template.render(model=to_return, title=title)
开发者ID:ariscn,项目名称:ingest-monitor,代码行数:30,代码来源:monitor.py


示例2: put

    def put(self, plan_id, item_id, **kwargs):
        user = kwargs['user']
        json = request.json
        new_item = Item.from_json(json)

        if new_item.id != item_id:
            on_error(error_message="Could not update item, ids do not match")

        plan = query(self.plan_repository.get(user_id=user.id, id=plan_id)).single_or_default(
            default=None)
        if not plan:
            abort(404, message="This plan does not exist")

        old_item = query(plan.items).where(lambda i: i.id ==
                                                 item_id).single_or_default(default=None)
        if not old_item:
            abort(404, message="This item does not exist")

        result = self.item_repository.add_or_update(new_item)

        if not result.success():
            on_error(error_message="Could not update item", result=result)

        self.item_repository.save_changes()
        return new_item
开发者ID:abettadapur,项目名称:Planr,代码行数:25,代码来源:api.py


示例3: affinities_by_school

def affinities_by_school(school_id):
    """return affinities got from that school"""
    school_ = api.data.schools.get(school_id)
    if not school_:
        return []

    ret_ = []
    ranks_ = query(api.character.rankadv.get_all()).where(
        lambda x: x.school == school_id and len(x.affinities) > 0).to_list()
    for r in ranks_:
        ret_ += r.affinities

    # special affinities
    if school_id == 'scorpion_yogo_wardmaster_school':
        ret_.append('wards')

    is_phoenix_embrace_the_elements = query(school_.techs).where(
        lambda x: x.id == 'phoenix_embrace_the_elements').count() > 0
    if is_phoenix_embrace_the_elements:
        affinity_, deficiencies_ = phoenix_embrace_the_elements()
        ret_.append(affinity_)

    is_mantis_favor_of_the_sun = query(school_.techs).where(lambda x: x.id == 'mantis_favor_of_the_sun').count() > 0
    if is_mantis_favor_of_the_sun:
        ret_.append('fire')

    return ret_
开发者ID:Kaniabi,项目名称:l5r-character-manager-3,代码行数:27,代码来源:spells.py


示例4: get_yelp_item

def get_yelp_item(coordinate, category, strategy=DistanceStrategy()):
    extra_yelp_params = {}
    yelp_item_repository = YelpItemRepository()

    # for these strategies, use YelpAPI
    # then reset strategy_name so that we can still call strategy module below
    extra_yelp_params['radius_filters'] = 7500

    if strategy.type == StrategyType.popularity:
        extra_yelp_params['sort'] = 2
        strategy = FirstStrategy()
    elif strategy.type == StrategyType.distance:
        extra_yelp_params['sort'] = 1
        strategy = FirstRandomStrategy()

    try:
        search_results = query(yelpapi.search(coordinate.latitude,
                                              coordinate.longitude,
                                              category.search_term,
                                              query(category.search_filters).select(lambda f: f.filter).to_list(),
                                              **extra_yelp_params)).where(
            lambda r: ['Food Trucks', 'foodtrucks'] not in r['categories'])
        yelp_items = [YelpItem.create_from_dict(result) for result in search_results]
        yelp_item = strategy.run_strategy(yelp_items)
        yelp_item = yelp_item_repository.get_or_insert(yelp_item)
        yelp_item_repository.save_changes()
        return yelp_item
    except:
        return None
开发者ID:abettadapur,项目名称:Planr,代码行数:29,代码来源:generation.py


示例5: get_paths_with_rank

def get_paths_with_rank(rank):
    """returns alternate schools list with rank equal to `rank`"""

    return query(__api.ds.schools) \
        .where(lambda x: 'alternate' in x.tags) \
        .where(lambda x: query(x.techs).select(a_('rank')).first_or_default(0) == rank) \
        .to_list()
开发者ID:OpenNingia,项目名称:l5r-character-manager-3,代码行数:7,代码来源:schools.py


示例6: post

    def post(self, plan_id, **kwargs):
        plan = query(self.plan_repository.get(user_id=kwargs['user'].id, id=plan_id)).single_or_default(
            default=None)
        if not plan:
            abort(404, message="This plan does not exist")

        post_body = request.json
        if type(post_body) is not list:
            on_error(error_message="Invalid post body")

        result = ChangeResult()
        try:
            shares = query(post_body)
            for shared_user in plan.shared_users:
                if not shares.contains(shared_user, lambda lhs, rhs: rhs['user_id'] == lhs.id):
                    result.add_child_result(
                        self.plan_repository.unshare(plan, shared_user.id))

            for share in post_body:
                user_id = share['user_id']
                permission = share['permission']
                result.add_child_result(
                    self.plan_repository.share(plan, user_id, permission))

        except KeyError as ke:
            on_error(error_message="Invalid post body")

        if not result.success():
            on_error(error_message="Could not share plan", result=result)

        self.plan_repository.save_changes()
        return plan
开发者ID:abettadapur,项目名称:Planr,代码行数:32,代码来源:api.py


示例7: get_school_rank

def get_school_rank(sid):
    """return the school rank"""

    if api.data.schools.is_path(sid):
        return query(api.data.schools.get(sid).techs).select(a_('rank')).first_or_default(1)
    return query(api.character.rankadv.get_all()).where(
            lambda x: x.school == sid or x.replaced == sid).count()
开发者ID:OpenNingia,项目名称:l5r-character-manager-3,代码行数:7,代码来源:schools.py


示例8: get_tech_by_rank

def get_tech_by_rank(rank):
    """returns the technique learned at the given insight rank, or None"""

    # get the school rank at that insight rank
    rank_ = query(api.character.rankadv.get_all()).where(
        lambda x: x.rank == rank).to_list()

    if not rank_:
        #log.api.error(u"get_tech_by_rank. rank advancement not found: %d", rank)
        return None


    school_id = rank_[0].school
    if len(rank_) > 1:        
        # find a replacement
        replacement_ = query(rank_).where(lambda x: x.replaced == school_id).first_or_default(None)
        if replacement_:
            school_id = replacement_.school

    school_ = api.data.schools.get(school_id)

    if not school_:
        return None

    return query(school_.techs).where(lambda x: x.rank == rank).select(a_('id')).first_or_default(None)
开发者ID:OpenNingia,项目名称:l5r-character-manager-3,代码行数:25,代码来源:schools.py


示例9: getThemeInstances

def getThemeInstances(theme, pages):
    print "instanceOf::Theme:" + theme
    instances = query(pages).where(lambda p: ("instanceOf" in p)).to_list()
    insts = (
        query(instances).where(lambda p: any(filter(lambda i: "n" in i and i["n"] == theme, p["instanceOf"]))).to_list()
    )
    print insts
    return insts
开发者ID:GitHubTianPeng,项目名称:101worker,代码行数:8,代码来源:program.py


示例10: get

 def get(self, plan_id, item_id, **kwargs):
     user = kwargs['user']
     plan = query(self.plan_repository.get(user_id=user.id, id=plan_id)).single_or_default(
         default=None)
     if not plan:
         abort(404, message="This plan does not exist")
     item = query(plan.items).where(lambda i: i.id ==
                                              item_id).single_or_default(default=None)
     if not item:
         abort(404, message="This item does not exist")
     return item
开发者ID:abettadapur,项目名称:Planr,代码行数:11,代码来源:api.py


示例11: load_families

    def load_families(self, clanid=None):
        self.cb_family.blockSignals(True)
        self.cb_family.clear()

        if clanid:
            family_list = query(api.data.families.get_all()).where(lambda x: x.clanid == clanid).order_by(a_('name'))
        else:
            family_list = query(api.data.families.get_all()).order_by(a_('name'))

        for f in family_list:
            self.cb_family.addItem(f.name, f.id)
        self.cb_family.blockSignals(False)

        # select first family
        self.on_family_changed(0)
开发者ID:OpenNingia,项目名称:l5r-character-manager-3,代码行数:15,代码来源:familychooser.py


示例12: mandelbrot

def mandelbrot():
    MaxIterations = 200
    SampleWidth = 3.2
    SampleHeight = 2.5
    OffsetX = -2.1
    OffsetY = -1.25

    ImageWidth = 480
    ImageHeight = int(SampleHeight * ImageWidth / SampleWidth)

    query = integers(0, ImageHeight).select(lambda y: (y * SampleHeight) / ImageHeight + OffsetY) \
            .select_many_with_correspondence(
                lambda y: integers(0, ImageWidth).select(lambda x: (x * SampleWidth) / ImageWidth + OffsetX),
                lambda y, x: (x, y)) \
            .select(lambda real_imag: complex(*real_imag)) \
            .select(lambda c: query(generate(c, lambda x: x * x + c))
                              .take_while(lambda x: x.real ** 2 + x.imag ** 2 < 4)
                              .take(MaxIterations)
                              .count()) \
            .select(lambda c: ((c * 7) % 255, (c * 5) % 255, (c * 11) % 255) if c != MaxIterations else (0, 0, 0))

    data = q.to_list()

    image = Image.new("RGB", (ImageWidth, ImageHeight))
    image.putdata(data)
    image.show()
开发者ID:Dror-LightCyber,项目名称:asq,代码行数:26,代码来源:mandelbrot.py


示例13: createTable

	def createTable(resource, contribs, classification, classname):
		classificationBase = root + "/" + classification + '/'
		logging.info(classificationBase)
		classBase = classificationBase + classname.replace('_',' ')
		if not os.path.exists(classificationBase):
			os.makedirs(classificationBase)
		if not os.path.exists(classBase):
			os.makedirs(classBase)
		if not os.path.exists(classBase + "/" + resource):
			os.makedirs(classBase + "/" + resource)
		level0Links = {}
		level1Links = {}
		for contribName in sorted(contribs.keys()):
			logging.info('Checking' + contribName + '...')
			clevel0Links = contribs[contribName]
			level0Links[contribName] = clevel0Links
			clevel1Links = []
			logging.info('' + str(len(clevel0Links)) + 'level 0 links found.')
			logging.info(' Finding level 1 links...')
			for rawlink in clevel0Links:
				split = rawlink.split('::')[-1].replace('_',' ').split(':')
				n = split[-1]
				p = split[0].title() if len(split) > 1 else ''
				ls = query(pages).where(lambda page: handlePrefix(page['p']).lower() == p.lower() and page['n'].lower() == n.lower() and 'internal_links' in page).select(lambda page: map(lambda l: l.split('::')[-1].lower(),page['internal_links'])).to_list()
				clevel1Links.extend(filter(lambda l: l not in clevel0Links, ls[0]) if ls else [])
			level1Links[contribName] = clevel1Links
			logging.info(''+ str(len(clevel1Links))+ 'level 1 links found.')
		flipped = {}
		for contribName in sorted(level0Links.keys()):
			logging.info(contribName)
			for term in level0Links[contribName]:
				term = term.encode('utf-8')
				logging.info(term)
				if term in flipped:
					flipped[term].append(contribName)
				else:
					flipped[term] = [contribName]
		uniqueLevel0 = {}
		lowerMappedTerms = set(map(lambda r: r.lower(), mappedTerms))
		for term in flipped:
			for contribName in sorted(contribs.keys()):
				if not contribName in uniqueLevel0:
					uniqueLevel0[contribName] = []
				if contribName in flipped[term] and len(flipped[term]) == 1:
					if contribName in uniqueLevel0:
						if term in lowerMappedTerms:
							logging.info(contribName + "-> " + term)
							uniqueLevel0[contribName].append(term)
		mytemplate = Template(filename='templates/coverageTemplate.txt')
		table = mytemplate.render(mappedTerms=mappedTerms, contribs=contribs.keys(), level0Links = level0Links, level1Links=level1Links, uniqueLevel0=uniqueLevel0)
		logging.info( "Creating " + classBase + "/" + resource + '/coverage.html')
		with open(classBase + "/" + resource + '/coverage.html', 'write') as tablef:
			tablef.write(table)
		coverage = {}
		for term in mappedTerms:
			coverage[term] = {}
			coverage[term]['level0'] = filter(lambda c: term.lower() in map(lambda t: t.lower(), level0Links[c]), contribs)
			coverage[term]['level1'] = filter(lambda c: term.lower() in map(lambda t: t.lower(), level1Links[c]) and not c in coverage[term]['level0'], contribs)
		with open(classBase + "/" + resource + '/coverage.json', 'write') as tablefjson:
			json.dump(coverage, tablefjson,indent=4 )
开发者ID:101companies,项目名称:101integrate,代码行数:60,代码来源:termsCoverage.py


示例14: get_requirements

def get_requirements(sid):
    """returns the requirements to join the given school"""
    school_ = get(sid)
    if not school_:
        log.api.error(u"school not found: %s", sid)
        return []

    requirements_by_data_ = school_.require

    # fixme. since i can't rewrite all alternate path
    # I decided to patch these requirement by code

    import l5r.api.character.schools
    from l5rdal.requirements import Requirement
    coded_requirements_ = []

    if is_path(sid):
        # An alternate path can only be joined
        # on the same school rank that its technique replaces

        path_rank_ = query(school_.techs).select(a_('rank')).first_or_default(0)

        if path_rank_ > 0:

            r = Requirement()
            r.field = api.character.schools.get_current()
            r.type = 'school'
            r.min = path_rank_ - 1
            r.max = path_rank_ - 1
            r.trg = None
            r.text = __api.tr("Replaces School Rank: {0}").format(path_rank_)

            coded_requirements_.append(r)

    return requirements_by_data_ + coded_requirements_
开发者ID:OpenNingia,项目名称:l5r-character-manager-3,代码行数:35,代码来源:schools.py


示例15: delete

    def delete(self, plan_id, item_id, **kwargs):
        user = kwargs['user']
        plan = query(self.plan_repository.get(user_id=user.id, id=plan_id)).single_or_default(
            default=None)
        if not plan:
            abort(404, message="This plan does not exist")

        item = query(plan.items).where(lambda i: i.id ==
                                                 item_id).single_or_default(default=None)
        if not item:
            abort(404, message="This item does not exist")

        plan.remove_item(item)
        self.item_repository.delete(id)
        self.item_repository.save_changes()
        return {"message": "Deleted item"}
开发者ID:abettadapur,项目名称:Planr,代码行数:16,代码来源:api.py


示例16: get_longpoll_collision

    def get_longpoll_collision(self):
        def common(l1, l2):
            return list(set(l1).intersection(l2))

        # glc str is laik '
        # {"ts":1814582040,"pts":1707239,"updates":[[61,275403018,1],[8,-262426908,4],[61,275403018,1]]};
        # {"ts":1801587829,"pts":1333083,"updates":[[9,-7837569,1]]};
        # {"ts":1654083789,"pts":284006,"updates":[[8,-229675882,4]]};
        # {"ts":1654083793,"pts":284006,"updates":[[8,-15683318,7]]};
        # {"ts":1814582464,"pts":1707465,"updates":[[8,-180240104,4]]}'
        with open(ARGS.glc) as f:
            updates_input = f.read()

        updates = query(updates_input.splitlines()) \
            .select(lambda x: json.loads(x)) \
            .select_many(lambda x: x['updates']) \
            .where(lambda x: x[0] == 9 or x[0] == 8) \
            .select(lambda x: abs(x[1])) \
            .to_list()

        possible_user = self.api.friends.get(user_id=updates[0])
        updates = updates[1:]
        for id in updates:
            friends = self.api.friends.get(user_id=id)
            new_possible_user = common(possible_user, friends)
            print('checked: ' + str(id))
            if len(new_possible_user) != 0:
                possible_user = new_possible_user
                # if len(new_possible_user) == 1:
                #     break
        print(possible_user)
开发者ID:maxus0089,项目名称:vktooklit,代码行数:31,代码来源:VKHackaFucka.py


示例17: get_school_by_rank

def get_school_by_rank(rank):
    """returns the school joined at the given insight rank, considering alternate paths"""
    rank_ = query(api.character.rankadv.get_all()).where(lambda x: x.rank == rank).first_or_default(None)
    if not rank_:
        log.api.error(u"get_school_by_rank. rank advancement not found: %d", rank)
        return None
    return rank_.school
开发者ID:OpenNingia,项目名称:l5r-character-manager-3,代码行数:7,代码来源:schools.py


示例18: get_skill_rank

def get_skill_rank(skill_id):
    """return the character skill rank"""
    if not __api.pc:
        return 0

    sk_rank_ = 0
    for r in api.character.rankadv.get_all():
        sk_rank_ += query(r.skills).where(lambda x: x == skill_id).count()

    sk_rank_ += query(__api.pc.advans).where(
        lambda x: x.type == 'skill' and x.skill == skill_id).count()

    if skill_id in get_acquired():
        sk_rank_ += 1

    return sk_rank_
开发者ID:Kaniabi,项目名称:l5r-character-manager-3,代码行数:16,代码来源:skills.py


示例19: get_learned

def get_learned():
    """return all the learned ( not starting ) skills"""
    if not __api.pc:
        return []
    return query(__api.pc.advans).where(
        lambda x: x.type == 'skill').select(
        lambda x: x.skill).distinct().to_list()
开发者ID:Kaniabi,项目名称:l5r-character-manager-3,代码行数:7,代码来源:skills.py


示例20: get_filtered_clan_list

    def get_filtered_clan_list(self):
        schools = self.get_filtered_school_list()
        clanids = query(schools) \
            .distinct(a_('clanid')) \
            .select(a_('clanid')) \
            .to_list()

        return [api.data.clans.get(x) for x in clanids]
开发者ID:OpenNingia,项目名称:l5r-character-manager-3,代码行数:8,代码来源:schoolchooser.py



注:本文中的asq.initiators.query函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python queryables.Queryable类代码示例发布时间:2022-05-24
下一篇:
Python storage.Folder类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap