示例#1
0
class Capturator(Thread):

    def __init__(self, config):
        Thread.__init__(self)
        self.config = config
        self.store = None
        self.cli = Client(config['host'],self.config['port'])
        self.start()
                
    def run(self):
        while True:
            data = self.cli.recv()
            if(data is None):
                self.cli = Client(self.config['host'], self.config['port'])
            else:
                num_cont = Cont().get_cont(self.config['counter'])
                data = data.decode('utf-8').replace('\n','') + '\n'
                Log().save_line(self.config['file_name'], 'acum', data)
                regs_store = {"id": num_cont, "data": data} # creando el diccionario con los datos recibidos

                while self.store == None:
                    print("Capture:\tConectando a MongoDB")
                    self.store = DB().connect(self.config['db_host'], self.config['db_name'], self.config['client_name'])
                    time.sleep(1)

                try:
                    self.store.insert(regs_store)
                    print('Capture:\t['+self.config['client_name']+'] -> '+num_cont + ' - ' +data)
                except:
                    print('Capture:\tError en MongoDB, reintentando...')
                    time.sleep(0)
示例#2
0
class Sender(Thread):

    def __init__(self, config):
        Thread.__init__(self)
        self.config = config
        self.store = None
        self.start()
                
    def run(self):
        while True:
            while self.store == None:
                print("Sender:\t\tConectando a MongoDB")
                self.store = DB().connect(self.config['db_host'], self.config['db_name'], self.config['client_name'])
                time.sleep(1)      

            try:
                reg = self.store.find_one()
                if reg != None:
                    self.cli = Client(self.config['sender_host'], self.config['sender_port'])
                    self.cli.send(reg['data'])
                    print('Sender:\t\t['+self.config['client_name']+'] -> '+ reg['id'] + ' - ' + reg['data'])
                    self.store.remove(reg)
            except:
                print('Sender:\t\tError en MongoDB, reintentando...')
                time.sleep(1)
def authenticate(email, password):
    if email is None:
       raise(NoEmailException() ) 
    if password is None:
       raise(NoPasswordException() ) 

    db = DB()
    users = db.get_user_by_email(email)
    if not users:
        raise(InvalidCredentialsException() )

    # constrains garantees that email is unique
    user = users[0]

    if user[ACTIVATED] is None:
        raise(InactiveAccountException() )

    if user[TRIES] >= settings.MAX_PWD_TRIES:
        raise(MaxTriesException() )
        
    m = sha1()
    m.update(user[SALT]+password)
     
    if m.hexdigest() == user[PASSWORD]:
        return db.successful_login(email)
    
    db.failed_login(email)
    raise(InvalidCredentialsException() )
示例#4
0
def authorize(auth_token):
    if auth_token is None:
        return False
    db = DB()
    users = db.get_user_by_auth_token(auth_token)
    if not users:
        return False

    return True
    # constrains garantees that email is unique
    user = users[0]
示例#5
0
def activate(token):
    db = DB()
    users = db.get_user_by_token(token)
    if not users:
        raise(UserNotFoundException() )

    # constrain garantees that token is unique
    user = users[0]
    if not user[ACTIVATED] is None:
        raise(UserAlreadyActivatedException() )

    if user[CREATED] < str(datetime.datetime.now() - timedelta(days=settings.DAYS_TO_ACTIVATE)):
        raise(UserExpiredException() )

    db.activate_user(token)
    return True    
示例#6
0
def cleanup():
    db = DB()
    db.decrease_pwd_tries()
    db.remove_inactive_users()
示例#7
0
    def get_json(self,url):
        req = requests.get(url,headers=self.headers)
        
        data_json = req.text
        #data_json = req.text.encode('utf-8').decode('unicode_escape')
        #print(data_json)
        dictjson = json.loads(data_json)
        if len(dictjson['data']) > 0 :
            if len(dictjson['data']['teams']) > 0:
                teams = dictjson['data']['teams'][0]
                
                rowguid = uuid.uuid1()
                checkin_rate = teams['checkin_rate']
                description = teams['description'].replace("\\","").translate(non_bmp_map)
                print (type(description))
                if "\"" in description:
                    description  = "too long"
                    
                    
                total_rank = teams['total_rank']
                quota = teams['quota']
                rank = teams['rank']
                create_time = teams['create_time']
                welcome_msg = teams['welcome_msg'].translate(non_bmp_map)
                if "\"" in welcome_msg or "\\" in welcome_msg:
                    welcome_msg  = "too long"
                motto = teams['motto']
                if "\"" in motto or "\\" in motto:
                    motto  = "too long"
                next_badge_points = teams['next_badge_points']
                team_type = teams['team_type']
                name = teams['name'].translate(non_bmp_map)
                if "\"" in name or "\\" in name:
                    name  = "too long"
                _id = teams['id']
                tags = teams['id']
                points = teams['points']
                size = teams['size']
                weekly_points = teams['weekly_points']
                leader_id = teams['leader']['id']
                belongteamguid = rowguid
                username = teams['leader']['username'].translate(non_bmp_map)
                if "\"" in  username:
                    username = "******"
                nickname = teams['leader']['nickname'].translate(non_bmp_map)
                if "\"" in nickname:
                    nickname  = "too long"
                timezone = teams['leader']['timezone']
                avatar = teams['leader']['avatar']

                singleTeam=(rowguid,checkin_rate,description,int(total_rank),int(quota),int(rank),
                                       welcome_msg,create_time,motto,int(next_badge_points),team_type,
                                       name,_id,tags,int(points),int(size),int(weekly_points),leader_id)
                leader = (belongteamguid,username,nickname,timezone,leader_id,avatar)
                db = DB()
                i = db.select_team(_id)
                if i < 1:
                    db.insert_team(singleTeam)
                j = db.select_leader(leader_id)
                if j< 1:
                    db.insert_leader(leader)