from celery.task import task
from namelist.scrape import get_user_profile_id, scrape_profile, NotFound
from namelist.models import Player, Category

@task()
def import_user(user, profile_name_or_id, category=None):
    if isinstance(profile_name_or_id, basestring):
        try:
            profile_id = get_user_profile_id(profile_name_or_id)
        except NotFound:
            user.message_set.create(message="Couldn't create {0}".format(profile_name_or_id))
            return
    else:
        profile_id = profile_name_or_id
        
    info = scrape_profile(profile_id)

    player = Player.objects.get_or_create(name=info[0], group_name=info[1], profile_id=profile_id)
    if player[1]:
        player[0].category = category
        player[0].save()

@@ -170,14 +170,8 @@
 ser(
-user, 
 prof
@@ -199,16 +199,27 @@
 ory=None
+, user=None
 ):%0A    i
@@ -367,16 +367,41 @@
 tFound:%0A
+            if user:%0A    
         
@@ -613,16 +613,25 @@
   player
+, created
  = Playe
@@ -658,42 +658,8 @@
 ate(
-name=info%5B0%5D, group_name=info%5B1%5D, 
 prof
@@ -733,24 +733,88 @@
 ategory%0A    
+    player%5B0%5D.name = info%5B0%5D%0A    player%5B0%5D.group_name = info%5B1%5D%0A
     player%5B0

Fix duplicate profile key errors with a less specific query.