#!/usr/local/bin/python3

"""
created_by:         Ebube Chuba
created_date:       3/4/2015
last_modified_by:   Ebube Chuba
last_modified date: 3/6/2015
"""

# imports
import json
import utils
from sql.user import User
from sql.question import Question
from sql.topic import Topic

# Format of JSON - EC
# requestType: getQuestion
# session: "string"
# topics: "string"
# difficulty: integer

def iChooseU(form):
    thisUser = utils.findUser(form)
    
    topic = form.getlist("topic")[0]
    difficulty = form.getlist("difficulty")[0]

    complete = []
    count = 0

    if not topic == "":
        complete += Question.get(0, Topic.get(topic)[0])
        count += 1
    if not difficulty == 0:
        complete += Question.get(0, difficulty)
        count += 1

    collect = []
    intersect = []

    for response in complete:
        if collect.count(response) < count:
            collect.append(response)
        else:
            intersect.add(response)

    out = {}
    out["questionList"] = intersect
    out["sessionID"] = form.getlist("session")[0]
    
    return json.dumps(out)

@@ -479,19 +479,16 @@
 %22topic%22)
-%5B0%5D
 %0A    dif
@@ -523,19 +523,16 @@
 iculty%22)
-%5B0%5D
 %0A%0A    co
@@ -569,23 +569,23 @@
  if 
-not 
+len(
 topic
- == %22%22
+) != 0
 :%0A  
@@ -633,16 +633,19 @@
 et(topic
+%5B0%5D
 )%5B0%5D)%0A  
@@ -672,12 +672,12 @@
  if 
-not 
+len(
 diff
@@ -682,18 +682,19 @@
 fficulty
- =
+) !
 = 0:%0A   
@@ -736,16 +736,19 @@
 fficulty
+%5B0%5D
 )%0A      

fix git question