import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'edurepo.settings')

import sys
sys.path.append('.')

import datetime
from django.contrib.auth.models import User
from teachers.models import Entry, Teacher, TeacherClass


def create_pretend_teacher(base_api_url, noisy=True):
    teacher_data = ('ms.teacher@example.edu', 'testuser', 'Ms. Teacher', 'AL-G5-SCIENCE', '5th grade science',
                    ['AL-G5-SCIENCE-05A', 'AL-G5-SCIENCE-05A', 'AL-G5-SCIENCE-05B', 'AL-G5-SCIENCE-05D',
                     'AL-G5-SCIENCE-05D'])
    users = User.objects.filter(username=teacher_data[1])
    if users:
        u = users[0]
    else:
        if noisy:
            print '%s does not exist, creating...' % teacher_data[1]
        u = User.objects.create_user(teacher_data[1], email=teacher_data[0])
    Teacher.objects.filter(email=teacher_data[0]).delete()
    t = Teacher(email=teacher_data[0], user=u, name=teacher_data[2])
    t.save()
    c = TeacherClass(teacher=t, course_id=teacher_data[3], name=teacher_data[4],
                     repo_provider=base_api_url)
    c.save()

    today = datetime.date.today()
    cur_day = today - datetime.timedelta(days=today.weekday())
    for objective in teacher_data[5]:
        e = Entry(teacher=t, teacher_class=c, date=cur_day, objective=objective)
        e.save()
        cur_day += datetime.timedelta(days=1)

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print >> sys.stderr, "one arg required: Base API URL"
        sys.exit(1)
    create_pretend_teacher(sys.argv[1])

@@ -1,12 +1,40 @@
+import argparse%0Aimport json%0A
 import os%0Aos
@@ -1401,111 +1401,408 @@
 1)%0A%0A
-if __name__ == '__main__':%0A    if len(sys.argv) != 2:%0A        print %3E%3E sys.stderr, %22one arg required: B
+%0Adef main():%0A    parser = argparse.ArgumentParser()%0A    group = parser.add_mutually_exclusive_group(required=True)%0A    group.add_argument('--from-json', type=argparse.FileType('r'), default=None,%0A                       help='name of file with JSON-formatted base API URL')%0A    group.add_argument('base_api_url', type=str, default=None,%0A                       nargs='?',%0A                       help='b
 ase 
@@ -1812,66 +1812,262 @@
  URL
-%22
+')
 %0A    
-    sys.exit(1)%0A    create_pretend_teacher(sys.argv%5B1%5D
+args = parser.parse_args()%0A%0A    if args.from_json:%0A        url = json.load(args.from_json)%5B'base_api_url'%5D%0A        args.from_json.close()%0A    else:%0A        url = args.base_api_url%0A    create_pretend_teacher(url)%0A%0Aif __name__ == '__main__':%0A    main(
 )%0A

allow base API URL to be specified by pointing to the .json file which contains it