<commit_before># -*- coding: utf-8 -*-

import random
from requests_oauthlib import OAuth1Session
from ga import settings


class BossImage(object):

    def __init__(self, obj):
        self.url = obj['url']
        self.width = int(obj['width'])
        self.height = int(obj['height'])


def image_url_for_term(term, minimum_side=settings.IMAGE_SIDE):
    boss = OAuth1Session(settings.BOSS_KEY, client_secret=settings.BOSS_SECRET)

    params = {'q': term, 'dimensions': 'large'}
    response = boss.get(settings.BOSS_IMAGE_URL, params=params).json()
    results = response['bossresponse']['images']['results']

    def is_valid(i):
        return i.width >= minimum_side and i.height >= minimum_side

    images = [BossImage(r) for r in results]
    choice = random.choice([i for i in images if is_valid(i)])
    return choice.url if choice else None
<commit_msg>Filter by file format from Boss<commit_after># -*- coding: utf-8 -*-

import random
from requests_oauthlib import OAuth1Session
from ga import settings


class BossImage(object):

    def __init__(self, obj):
        self.url = obj['url']
        self.width = int(obj['width'])
        self.height = int(obj['height'])
        self.format = obj['format']


def image_url_for_term(term, minimum_side=settings.IMAGE_SIDE):
    boss = OAuth1Session(settings.BOSS_KEY, client_secret=settings.BOSS_SECRET)

    params = {'q': term, 'dimensions': 'large'}
    response = boss.get(settings.BOSS_IMAGE_URL, params=params).json()
    results = response['bossresponse']['images']['results']

    def is_valid(i):
        return (i.width >= minimum_side and
                i.height >= minimum_side and
                i.format in ['jpeg','jpg'])

    images = [BossImage(r) for r in results]
    choice = random.choice([i for i in images if is_valid(i)])
    return choice.url if choice else None

{'fraction_non_alphanumeric': 0.1293800539083558, 'fraction_numerical': 0.003234501347708895, 'mean_word_length': 3.56019656019656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5025520', 'n_tokens_mistral': 589, 'n_tokens_neox': 572, 'n_words': 147}