Exemplo n.º 1
0
    def gen(cls, self_data, friend_data):
        college = get_college(friend_data['education'])
        if 'concentration' not in college:
            raise QuestionNotFeasibleException('No degree listed')
        degrees = college['concentration']
        if len(degrees) == 1:
            degree = degrees[0]['name']
        elif len(degrees) == 2:
            degree = '%s and %s' % (degrees[0]['name'], degrees[1]['name'])
        else:
            raise QuestionNotFeasibleException('More than 2 degrees')

        return cls(get_school_name(college), degree)
Exemplo n.º 2
0
 def gen(cls, self_data, friend_data):
     liked_statuses, unliked_statuses = \
         get_liked_and_unliked_statuses(self_data, friend_data['id'])
     if len(liked_statuses) == 0 or len(unliked_statuses) == 0:
         raise QuestionNotFeasibleException(
             'Not enough liked/unliked statuses')
     return cls(liked_statuses, unliked_statuses)
Exemplo n.º 3
0
def get_commented_photo(photos):
    for _ in range(100):
        photo = random.choice(photos)
        comments = get_photo_comments(photo)
        # We don't want photos with more than 4 comments because then they tend
        # to be conversational and perhaps unrelated to the picture.
        if comments and len(comments) <= 4:
            return photo
    raise QuestionNotFeasibleException()
Exemplo n.º 4
0
 def gen(cls, self_data, friend_data):
     try:
         born = datetime.strptime(friend_data['birthday'],
                                  '%m/%d/%Y').date()
     except ValueError:
         raise QuestionNotFeasibleException(
             'Birthday or year not provided.')
     today = date.today()
     age = (today.year - born.year - ((today.month, today.day) <
                                      (born.month, born.day)))
     fake_ages = [x for x in range(age - 3, age + 4) if x != age]
     return cls([age], fake_ages)
Exemplo n.º 5
0
 def __init__(self, correct_answers, wrong_answers):
     if type(correct_answers) is not list \
             and type(correct_answers) is not set:
         raise AssertionError("First argument must be list or set of " +
                              "correct answers; found %s." %
                              str(type(correct_answers)))
     wrong_answers = list(
         set([a for a in wrong_answers if a not in correct_answers]))
     if len(wrong_answers) < self.NUM_WRONG_ANSWERS:
         raise QuestionNotFeasibleException("Not enough wrong answers")
     self.checked = -1
     correct_answer = random.choice(tuple(correct_answers))
     self.correct_index = random.randint(0, self.NUM_WRONG_ANSWERS)
     self.responses = random.sample(wrong_answers, self.NUM_WRONG_ANSWERS)
     self.responses.insert(self.correct_index, correct_answer)
     self.name = 'Must set this field'
Exemplo n.º 6
0
def get_captioned_photo(photos):
    for _ in range(100):
        photo = random.choice(photos)
        if get_caption(photo):
            return photo
    raise QuestionNotFeasibleException()
Exemplo n.º 7
0
def get_geotagged_photo(photos):
    for _ in range(100):
        photo = random.choice(photos)
        if 'place' in photo and type(photo['place']['location']) is dict:
            return photo
    raise QuestionNotFeasibleException()
Exemplo n.º 8
0
def _get_education(ed_data, school_type):
    for school in ed_data:
        if school['type'] == school_type:
            return school
    raise QuestionNotFeasibleException('No %s listed.' % school_type)