예제 #1
0
def quick_create_users(emails, creating_user):
    users = []
    for email in emails:
        user = ChatUser(email=email, username=email)
        user.referral_user = creating_user
        user.save()
        users.append(user)
    return users
예제 #2
0
def quick_create_users(emails, creating_user):
    users = []
    for email in emails:
        user = ChatUser(email=email, username=email)
        user.referral_user = creating_user
        user.save()
        users.append(user)
    return users
예제 #3
0
    def handle(self, *args, **kwds):
        sc = SlackClient(settings.SLACK_BOT_TOKEN)
        self.verbose = kwds['verbose']

        users = sc.api_call('users.list')['members']

        for slack_user in users:
            slack_id = slack_user['id']
            self.log_progress('Checking "%s"...' % slack_user['name'])
            change_found = False

            # If it exists update it
            if ChatUser.objects.filter(user_id=slack_id).exists():
                self.log_progress('"%s" exists, checking fields...' % slack_user['name'])
                db_user = ChatUser.objects.get(user_id=slack_id)

                for field in self.UPDATE_FIELDS:
                    # Get the db value for the field
                    db_field = getattr(db_user, field)

                    # Get the slack API call value for the field
                    if field[:6] == 'image_':
                        user_field = slack_user['profile'][field]
                    else:
                        user_field = slack_user.get(field, None)

                    # Compare the fields and update if different
                    if user_field and db_field != user_field:
                        self.log_progress('Change Found: Updating "%s" from "%s" to "%s" for user "%s"' % (
                            field,
                            db_field,
                            user_field,
                            slack_user['name']
                        ))
                        change_found = True
                        setattr(db_user, field, user_field)

                if change_found:
                    db_user.save()
                    change_found = False

            # If not, add it
            else:
                self.log_progress('No user found. Adding "%s".' % slack_user['name'])
                user_data = {
                    'user_id': slack_id,
                    'name': slack_user.get('name', ''),
                    'real_name': slack_user.get('real_name', ''),
                    'image_24': slack_user['profile'].get('image_24', ''),
                    'image_32': slack_user['profile'].get('image_32', ''),
                    'image_48': slack_user['profile'].get('image_48', ''),
                    'image_72': slack_user['profile'].get('image_72', ''),
                    'image_192': slack_user['profile'].get('image_192', ''),
                }
                u = ChatUser(**user_data)
                u.save()
예제 #4
0
def ws_message(message):
    message_json = json.loads(message['text'])
    user_id = message_json['user_name']
    message_type = message_json['type']
    message.channel_session['user'] = user_id

    if message_type == 'connect':
        print('connect')
        ChatUser(user_id=user_id).save()

    Group("chat").send({"text": message['text']})
예제 #5
0
from chat.models import ChatUser

correct = False

while not correct:
    u_name = raw_input("username: "******"password: "******"username:"******"password:"******"y" == raw_input("correct? (y/n)")
try:
    user = ChatUser.objects.get(name=u_name)
    print "User exists -- username:"******"password", user.password
except:
    a = ChatUser.create(name=u_name, password=p_word)
    a.save()
    print "User created -- username:"******"password:", a.password
예제 #6
0
def save_profile_in_our_db(dict_profile_from_tpa):
    tpa = Tpa.objects.get(name=dict_profile_from_tpa['tpa'])
    u = ChatUser()
    u.user_id = dict_profile_from_tpa['user_id']
    u.name = dict_profile_from_tpa['name']
    u.birthday = dict_profile_from_tpa['birthday']
    u.country = dict_profile_from_tpa['country']
    u.city = dict_profile_from_tpa['city']
    u.culture = dict_profile_from_tpa['culture']
    u.profile_url = dict_profile_from_tpa['profile_url']
    u.image = dict_profile_from_tpa['image']
    u.gender = dict_profile_from_tpa['gender']
    u.tpa = tpa
    u.save()