def gen(cls, self_data, friend_data): phrases = [status['message'] for status in get_paged_data(friend_data, 'statuses')] phrases.extend(get_captions(get_paged_data(friend_data, 'photos'))) # We deduplicate phrases because an album of pictures can produce # hundreds of the same exact caption. word_count = get_word_count(set(phrases)) del word_count[friend_data['first_name'].lower()] return cls(word_count)
def gen(cls, self_data, friend_data): tags = defaultdict(int) for photo in get_paged_data(friend_data, 'photos'): for tag in get_paged_data(photo, 'tags'): if 'id' not in tag: continue # Ignore tags of non-fb objects tags[tag['name']] += weight(photo) del tags[friend_data['name']] return cls(tags)
def gen(cls, self_data, friend_data): photos = get_paged_data(friend_data, 'photos') chosen_photo = get_geotagged_photo(photos) location = chosen_photo['place']['name'] all_locations = get_unique_locations( [photo for photo in photos if 'place' in photo] + [chosen_photo]) return cls(get_sized_photo(chosen_photo), [location], all_locations)
def gen(cls, self_data, friend_data): photos = get_paged_data(friend_data, 'photos') chosen_photo = get_geotagged_photo(photos) location = chosen_photo['place']['name'] all_locations = get_unique_locations( [photo for photo in photos if 'place' in photo] + [chosen_photo] ) return cls(get_sized_photo(chosen_photo), [location], all_locations)
def gen(cls, self_data, friend_data): photos = get_paged_data(friend_data, 'photos') photo = get_captioned_photo(photos) return cls( get_sized_photo(photo), [get_caption(photo)], get_captions(photos), )
def gen(cls, self_data, friend_data): photos = get_paged_data(friend_data, 'photos') photo = get_commented_photo(photos) return cls( get_sized_photo(photo), get_photo_comments(photo), get_all_comments(photos), )
def get_liked_and_unliked_statuses(self_data, friend_id): self_statuses_data = get_paged_data(self_data, 'statuses') status_data = dict() for status in self_statuses_data: if 'likes' in status: status_data[status['message']] = get_paged_data(status, 'likes') liked_statuses = set() unliked_statuses = set() for key, val in status_data.iteritems(): for v in val: if v['id'] == friend_id: liked_statuses.add(key) else: unliked_statuses.add(key) return list(liked_statuses), list(unliked_statuses)
def gen(cls, self_data, friend_data): mutual_friends = [ context['name'] for context in get_context_data(friend_data, 'context') ] non_mutual_friends = [ friends['name'] for friends in get_paged_data(self_data, 'friends') ] results = [] for friend in non_mutual_friends: if not friend in mutual_friends and friend != friend_data['name']: results.append(friend) return cls(results, mutual_friends)
def gen(cls, self_data, friend_data): likes = [like['name'] for like in get_paged_data(friend_data, 'likes')] fake_likes = [ fake_like for fake_like in FAKE_LIKES if fake_like not in likes ] return cls(fake_likes, likes)
def gen(cls, self_data, friend_data): time_start = time() photos = get_paged_data(friend_data, 'photos') photos = get_photo_arr_with_tags(photos, friend_data['id']) length = min(len(photos), NUM_PICTURES) #Pull down photos photo_arr = get_photos_threaded(photos[:length]) photo_arr = sorted(photo_arr) #Grab skin color and shirt_color skin_color_arr = [] shirt_color_arr = [] for photo, tag_coords in photo_arr: #Get Skin Color in a "Plus" Pattern for n in range(-1, 2): color = get_color_avg(photo, tag_coords, 0, float(n) * CROSS_RAD) if color: skin_color_arr.append(color) for n in range(-1, 2): if n == 0: continue color = get_color_avg(photo, tag_coords, float(n) * CROSS_RAD, 0) if color: skin_color_arr.append(color) #Get Shirt Color in a "Plus" Pattern Y_OFFSET_PERCENT = 20.0 for n in range(-1, 2): color = get_color_avg(photo, tag_coords, 0, Y_OFFSET_PERCENT + float(n) * CROSS_RAD) if color: shirt_color_arr.append(color) for n in range(-1, 2): if n == 0: continue color = get_color_avg(photo, tag_coords, float(n) * CROSS_RAD, Y_OFFSET_PERCENT) if color: shirt_color_arr.append(color) #Get average skin color of the person skin_color, scores = point_cluster.cluster(skin_color_arr, 5) maxindex_skin = scores.index(max(scores)) #Get average shirt colors, remove color that is closest to skin color shirt_color, scores = point_cluster.cluster(shirt_color_arr, 5) shirt_color, index = point_cluster.removeClosestColor(shirt_color, skin_color[maxindex_skin]) scores = scores[:index] + scores[index+1 :] #Update score array w/removed color maxindex_shirt = scores.index(max(scores)) #Get correct and incorrect answers correct_answer = shirt_color[maxindex_shirt] shirt_color.remove(correct_answer) incorrect_answers = shirt_color logger.debug("TIME: Pictures fetch: %sms", round(1000 * (time() - time_start))) return cls( [correct_answer], incorrect_answers, )
def gen(cls, self_data, friend_data): statuses = [ status['message'] for status in get_paged_data(friend_data, 'statuses') ] return cls(FAKE_STATUSES, statuses)