--- /dev/null
+from django.core.management.base import BaseCommand, CommandError
+
+from contact.models import Contact
+from wtem.models import Submission
+
+
+class Command(BaseCommand):
+    help = 'Sends personalized links to WTEM contestants'
+
+    def handle(self, *args, **options):
+        new = 0
+        skipped = 0
+
+        for wtem_contact in Contact.objects.filter(form_tag = 'wtem'):
+            for student in wtem_contact.body['student']:
+                if not Submission.objects.filter(email = student['email']).exists():
+                    args = dict()
+                    for attr in ['first_name', 'last_name', 'email']:
+                        args[attr] = student[attr]
+                    args['contact'] = wtem_contact
+                    Submission.create(**args)
+                    new += 1
+                else:
+                    skipped += 1
+
+        self.stdout.write('New: ' + str(new) + ', skipped: ' + str(skipped))
 
         return key
 
     @classmethod
-    def create(cls, first_name, last_name, email, contact = None, key = None):
-        submissions = []
-
-        if contact:
-            students = contact['students']
-        else:
-            students = [dict(first_name = first_name, last_name = last_name, email = email)]
-        
-        if key is None:
-            key = Submission.generate_key()
-
-        for student in students:
-            submission = cls(
-                contact = contact,
-                key = key,
-                first_name = student['first_name'],
-                last_name = student['last_name'],
-                email = student['email']
-            )
-            submission.save()
-            submissions.append(submission)
-        return submissions
+    def create(cls, first_name, last_name, email, key = None, contact = None):
+        submission = cls(
+            contact = contact,
+            key = key if key else Submission.generate_key(),
+            first_name = first_name,
+            last_name = last_name,
+            email = email
+        )
+
+        submission.save()
+        return submission
 
 
 class Attachment(models.Model):
 
         submission = Submission.objects.get(key = key)
     except Submission.DoesNotExist:
         if settings.DEBUG and key == '12345':
-            submission = Submission.create(first_name = 'Debug', last_name = 'Debug', email = 'debug@debug.com', key = '12345')[0]
+            submission = Submission.create(first_name = 'Debug', last_name = 'Debug', email = 'debug@debug.com', key = '12345')
         else:
             raise Http404