当前位置: 首页>>代码示例>>Python>>正文


Python models.Domain类代码示例

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


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

示例1: save_request

    def save_request(self, url, response):
        if not response:
            return

        request_time = response.request_time
        effective_url = response.effective_url
        status_code = response.status_code

        if self.domain_name not in Domain.get_domain_names(self.db):
            return

        req = Request(
            domain_name=self.domain_name,
            url=url,
            effective_url=effective_url,
            status_code=int(status_code),
            response_time=request_time,
            completed_date=datetime.now().date(),
            review_url=self.page_url
        )

        self.db.add(req)

        url = url.encode('utf-8')

        self.publish(dumps({
            'type': 'new-request',
            'url': str(url)
        }))
开发者ID:marcelometal,项目名称:holmes-api,代码行数:29,代码来源:reviewer.py

示例2: get

    def get(self, domain_name):
        domain = Domain.get_domain_by_name(domain_name, self.db)

        if not domain:
            self.set_status(404, 'Domain %s not found' % domain_name)
            return

        violation_defs = self.application.violation_definitions

        grouped_violations = self.girl.get('violation_count_by_category_for_domains')

        total = 0
        violations = []

        for item in grouped_violations.get(domain.id, []):
            key_name, key_category_id, count = item['key_name'], item['category_id'], item['violation_count']
            violations.append({
                'categoryId': key_category_id,
                'categoryName': violation_defs[key_name]['category'],
                'count': count
            })
            total += count

        result = {
            "domainId": domain.id,
            'domainName': domain.name,
            'domainURL': domain.url,
            'total': total,
            'violations': violations
        }

        self.write_json(result)
开发者ID:ricardodani,项目名称:holmes-api,代码行数:32,代码来源:domains.py

示例3: get_count

    def get_count(self, key, domain_name, expiration, get_count_method):
        cache_key = '%s-%s' % (self.get_domain_name(domain_name), key)

        count = self.redis.get(cache_key)

        if count is not None:
            return int(count)

        domain = domain_name
        if domain and not isinstance(domain, Domain):
            domain = Domain.get_domain_by_name(domain_name, self.db)

        if domain is None:
            count = Page.get_page_count(self.db)
        else:
            count = get_count_method(domain)

        cache_key = '%s-%s' % (self.get_domain_name(domain), key)

        self.redis.setex(
            cache_key,
            expiration,
            value=int(count)
        )

        return int(count)
开发者ID:ricardodani,项目名称:holmes-api,代码行数:26,代码来源:cache.py

示例4: get

    def get(self, domain_name):
        domain = Domain.get_domain_by_name(domain_name, self.db)

        if not domain:
            self.set_status(404, self._('Domain %s not found') % domain_name)
            return

        prefs = DomainsViolationsPrefs.get_domains_violations_prefs_by_domain(
            self.db, domain.name
        )

        violation_defs = self.application.violation_definitions

        result = []

        for pref in prefs:
            key = violation_defs.get(pref.get('key'))

            if key is None:
                continue

            result.append({
                'key': pref.get('key'),
                'title': key.get('default_value_description', None),
                'category': key.get('category', None),
                'value': pref.get('value'),
                'default_value': key.get('default_value', None),
                'unit': key.get('unit', None)
            })

        self.write_json(result)
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:31,代码来源:domains_violations_prefs.py

示例5: save_request

    def save_request(self, url, response):
        if not response:
            return

        request_time = response.request_time
        effective_url = response.effective_url
        status_code = response.status_code

        domain_name, domain_url = get_domain_from_url(url)
        if domain_name not in Domain.get_domain_names(self.db):
            return

        req = Request(
            domain_name=domain_name,
            url=url,
            effective_url=effective_url,
            status_code=int(status_code),
            response_time=request_time,
            completed_date=datetime.now().date(),
            review_url=self.page_url
        )

        self.db.add(req)

        self.cache.increment_requests_count()

        self.publish(dumps({
            'type': 'new-request',
            'url': str(url)
        }))
开发者ID:pombredanne,项目名称:holmes-api,代码行数:30,代码来源:reviewer.py

示例6: post

    def post(self, domain_name):
        domain = Domain.get_domain_by_name(domain_name, self.db)

        if not domain:
            self.set_status(404, 'Domain %s not found' % domain_name)
            return

        domain.is_active = not domain.is_active
开发者ID:ricardodani,项目名称:holmes-api,代码行数:8,代码来源:domains.py

示例7: test_can_get_active_domains

    def test_can_get_active_domains(self):
        self.db.query(Domain).delete()

        domain = DomainFactory(is_active=True)
        DomainFactory(is_active=False)

        domains = Domain.get_active_domains(self.db)

        expect(domains).to_length(1)
        expect(domains[0].id).to_equal(domain.id)
开发者ID:ricardodani,项目名称:holmes-api,代码行数:10,代码来源:test_domain.py

示例8: test_can_set_domain_to_inactive

    def test_can_set_domain_to_inactive(self):
        domain = DomainFactory.create(url="http://www.domain.com", name="domain.com", is_active=True)

        response = yield self.authenticated_fetch(
            '/domains/%s/change-status/' % domain.name,
            method='POST',
            body=''
        )
        expect(response.code).to_equal(200)
        domain_from_db = Domain.get_domain_by_name(domain.name, self.db)
        expect(domain_from_db.is_active).to_be_false()
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:11,代码来源:test_domains.py

示例9: test_can_set_domain_to_active

    def test_can_set_domain_to_active(self):
        domain = DomainFactory.create(url="http://www.domain.com", name="domain.com", is_active=False)

        response = yield self.http_client.fetch(
            self.get_url(r'/domains/%s/change-status/' % domain.name),
            method='POST',
            body=''
        )
        expect(response.code).to_equal(200)
        domain_from_db = Domain.get_domain_by_name(domain.name, self.db)
        expect(domain_from_db.is_active).to_be_true()
开发者ID:ricardodani,项目名称:holmes-api,代码行数:11,代码来源:test_domains.py

示例10: get_next_jobs_count

    def get_next_jobs_count(cls, db, config):
        from holmes.models import Domain

        active_domains = Domain.get_active_domains(db)
        active_domains_ids = [item.id for item in active_domains]

        return db \
                .query(
                    sa.func.count(Page.id)
                ) \
                .filter(Page.domain_id.in_(active_domains_ids)) \
                .scalar()
开发者ID:ricardodani,项目名称:holmes-api,代码行数:12,代码来源:page.py

示例11: test_get_domain_names

    def test_get_domain_names(self):
        self.db.query(Domain).delete()

        DomainFactory.create(name="g1.globo.com")
        DomainFactory.create(name="globoesporte.globo.com")

        domain_names = Domain.get_domain_names(self.db)

        expect(domain_names).to_be_like([
            'g1.globo.com',
            'globoesporte.globo.com'
        ])
开发者ID:pombredanne,项目名称:holmes-api,代码行数:12,代码来源:test_domain.py

示例12: test_can_get_domains_details

    def test_can_get_domains_details(self):
        self.db.query(Domain).delete()

        details = Domain.get_domains_details(self.db)

        expect(details).to_length(0)

        domain = DomainFactory.create(name='domain-1.com', url='http://domain-1.com/')
        domain2 = DomainFactory.create(name='domain-2.com', url='http://domain-2.com/')
        DomainFactory.create()

        page = PageFactory.create(domain=domain)
        page2 = PageFactory.create(domain=domain)
        page3 = PageFactory.create(domain=domain2)

        ReviewFactory.create(domain=domain, page=page, is_active=True, number_of_violations=20)
        ReviewFactory.create(domain=domain, page=page2, is_active=True, number_of_violations=10)
        ReviewFactory.create(domain=domain2, page=page3, is_active=True, number_of_violations=30)

        RequestFactory.create(status_code=200, domain_name=domain.name, response_time=0.25)
        RequestFactory.create(status_code=304, domain_name=domain.name, response_time=0.35)
        RequestFactory.create(status_code=400, domain_name=domain.name, response_time=0.25)
        RequestFactory.create(status_code=403, domain_name=domain.name, response_time=0.35)
        RequestFactory.create(status_code=404, domain_name=domain.name, response_time=0.25)

        details = Domain.get_domains_details(self.db)

        expect(details).to_length(3)
        expect(details[0]).to_length(10)
        expect(details[0]['url']).to_equal('http://domain-1.com/')
        expect(details[0]['name']).to_equal('domain-1.com')
        expect(details[0]['violationCount']).to_equal(30)
        expect(details[0]['pageCount']).to_equal(2)
        expect(details[0]['reviewCount']).to_equal(2)
        expect(details[0]['reviewPercentage']).to_equal(100.0)
        expect(details[0]['errorPercentage']).to_equal(60.0)
        expect(details[0]['is_active']).to_be_true()
        expect(details[0]['averageResponseTime']).to_equal(0.3)
开发者ID:ricardodani,项目名称:holmes-api,代码行数:38,代码来源:test_domain.py

示例13: handle

        def handle(has_key):
            domain = domain_name
            if domain and not isinstance(domain, Domain):
                domain = Domain.get_domain_by_name(domain_name, self.db)

            if has_key:
                self.redis.incrby(key, increment, callback=callback)
            else:
                if domain is None:
                    value = Page.get_page_count(self.db) + increment - 1
                else:
                    value = get_default_method(domain) + increment - 1

                self.redis.set(key, value, callback=callback)
开发者ID:marcelometal,项目名称:holmes-api,代码行数:14,代码来源:cache.py

示例14: test_can_get_pages_per_domain

    def test_can_get_pages_per_domain(self):
        domain = DomainFactory.create()
        domain2 = DomainFactory.create()
        DomainFactory.create()

        PageFactory.create(domain=domain)
        PageFactory.create(domain=domain)
        PageFactory.create(domain=domain2)
        PageFactory.create(domain=domain2)
        PageFactory.create(domain=domain2)

        pages_per_domain = Domain.get_pages_per_domain(self.db)

        expect(pages_per_domain).to_be_like({
            domain.id: 2,
            domain2.id: 3
        })
开发者ID:pombredanne,项目名称:holmes-api,代码行数:17,代码来源:test_domain.py

示例15: increment_count

    def increment_count(self, key, domain_name, get_default_method, increment=1):
        key = '%s-%s' % (self.get_domain_name(domain_name), key)

        has_key = self.has_key(key)

        domain = domain_name
        if domain and not isinstance(domain, Domain):
            domain = Domain.get_domain_by_name(domain_name, self.db)

        if has_key:
            self.redis.incrby(key, increment)
        else:
            if domain is None:
                value = Page.get_page_count(self.db) + increment - 1
            else:
                value = get_default_method(domain) + increment - 1

            self.redis.set(key, value)
开发者ID:ricardodani,项目名称:holmes-api,代码行数:18,代码来源:cache.py


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