Exemplo n.º 1
0
 def test_add_many_rules_not_ok(self):
     try:
         rules_list = self._generate_rules_list()
         rules.add_rules(rules_list, config_file_path=test_utils.test_config_path)
     except RuleAddFailedException:
         return
     self.fail("Rule Add was supposed to fail and throw a RuleAddException")
Exemplo n.º 2
0
 def test_add_many_rules_not_ok(self):
     try:
         rules_list = self._generate_rules_list()
         rules.add_rules(rules_list,
                         config_file_path=test_utils.test_config_path)
     except RuleAddFailedException:
         return
     self.fail("Rule Add was supposed to fail and throw a RuleAddException")
Exemplo n.º 3
0
    def get(self):

        response = []

        dataset = self.request.get("dataset")[:-1]
        table = self.request.get("name")

        Utils.insert_table(dataset, table)
        TABLE_CACHE.clear()

        tag = Utils.make_tag(dataset, table)
        rule_list = self.request.get("rules")
        rule_list = [
            rules.build(s.strip(), tag) for s in rule_list.splitlines()
        ]

        params = GNIP_RULES_PARAMS
        params['tag'] = tag

        response = rules.add_rules(rule_list, **params)
        TABLE_CACHE.clear()

        print "ApiTableAdd", response

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(response))
Exemplo n.º 4
0
    def get(self, id):

        (project, dataset, table) = Utils.parse_bqid(id)
        query = USER_QUERY % (dataset, table)

        tag = Utils.make_tag(dataset, table)
        params = GNIP_RULES_PARAMS
        params['tag'] = tag

        results = Utils.get_bq().jobs().query(projectId=config.PROJECT_NUMBER,
                                              body={
                                                  'query': query
                                              }).execute()

        tweet_count = 0
        users = []
        if 'rows' in results:

            rules_list = []
            rule = ""
            clause_count = 0

            for row in results['rows']:

                for key, dict_list in row.iteritems():

                    user = dict_list[0]['v']

                    if user:
                        user = "******" % user
                        rule = "%s OR %s" % (user, rule)

                        clause_count = clause_count + 1
                        break

                if clause_count >= 30 or len(rule) > 1000:

                    rule = rule[:-4]
                    rules_list.append(rules.build(rule, tag))

                    rule = ""
                    clause_count = 0

            if len(rule) > 5:

                rule = rule[:-4]
                rules_list.append(rules.build(rule, tag))

        print rules_list
        response = rules.add_rules(rules_list, **params)

        print response

        response = {"rules": rules_list, "rule_count": len(rules_list)}

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(response))
Exemplo n.º 5
0
    def get(self, id):
        
        (project, dataset, table) = Utils.parse_bqid(id)
        query = USER_QUERY % (dataset, table)
        
        tag = Utils.make_tag(dataset, table)
        params = GNIP_RULES_PARAMS
        params['tag'] = tag
        
        results = Utils.get_bq().jobs().query(projectId=config.PROJECT_NUMBER, body={'query':query}).execute()
        
        tweet_count = 0
        users = []
        if 'rows' in results:
            
            rules_list = []
            rule = ""
            clause_count = 0
            
            for row in results['rows']:
                
                for key, dict_list in row.iteritems():
                    
                    user = dict_list[0]['v']
                    
                    if user:
                        user = "******" % user
                        rule = "%s OR %s" % (user, rule)
                        
                        clause_count = clause_count + 1
                        break

                if clause_count >= 30 or len(rule) > 1000:
                     
                    rule = rule[:-4]
                    rules_list.append(rules.build(rule, tag))
                     
                    rule = ""
                    clause_count = 0
                    
            if len(rule) > 5:
                
                rule = rule[:-4]
                rules_list.append(rules.build(rule, tag))
                
        print rules_list
        response = rules.add_rules(rules_list, **params)
        
        print response
                    
        response = {"rules": rules_list, "rule_count": len(rules_list) }

        self.response.headers['Content-Type'] = 'application/json'   
        self.response.out.write(json.dumps(response))  
Exemplo n.º 6
0
    def get(self):
        
        response = []

        dataset = self.request.get("dataset")[:-1]
        table = self.request.get("name")

        Utils.insert_table(dataset, table)
        TABLE_CACHE.clear()
            
        tag = Utils.make_tag(dataset, table)
        rule_list = self.request.get("rules")
        rule_list = [rules.build(s.strip(), tag) for s in rule_list.splitlines()]
        
        params = GNIP_RULES_PARAMS
        params['tag'] = tag

        response = rules.add_rules(rule_list, **params)
        TABLE_CACHE.clear()
        
        print "ApiTableAdd", response

        self.response.headers['Content-Type'] = 'application/json'   
        self.response.out.write(json.dumps(response)) 
Exemplo n.º 7
0
 def test_add_many_rules_ok(self):
     """ Add many rules. """
     rules_list = self._generate_rules_list()
     rules.add_rules(rules_list, config_file_path=test_utils.test_config_path)
Exemplo n.º 8
0
 def test_add_many_rules_ok(self):
     rules_list = self._generate_rules_list()
     rules.add_rules(rules_list,
                     config_file_path=test_utils.test_config_path)