<commit_before>from fractions import Fraction
from cStringIO import StringIO

from PIL import Image, ImageDraw, ImageFont
import qrcode
import requests


museo = ImageFont.truetype('Museo500-Regular.otf', 424)
badge_back = Image.open('badge-back.png')
logo_stamp = Image.open('logo-stamp.png')

qr_size = 975, 975
qr_offset = 75, 75
name_color = 6, 155, 192
text_bounds = 735, 125
text_offset = 365, 1155
avatar_bounds = 282, 282
avatar_offset = 49, 1131


class AvatarFetchError(Exception):
    pass


def draw_text(text, color, fit_size):
    text_size = museo.getsize(text)
    img = Image.new('RGBA', text_size, color + (0,))
    draw = ImageDraw.Draw(img)
    draw.text((0, 0), text, color + (255,), font=museo)
    width, height = img.size
    fit_width, fit_height = fit_size

    width_ratio = Fraction(width, fit_width)
    height_ratio = Fraction(height, fit_height)
    if width_ratio > height_ratio:
        new_size = fit_width, int(height / width_ratio)
    else:
        new_size = int(width / height_ratio), fit_height

    return img.resize(new_size, Image.ANTIALIAS)

def center(size, fit_size, offset):
    w, h = size
    fw, fh = fit_size
    x, y = offset
    return x + (fw - w) // 2, y + (fh - h) // 2

logo_pos = center(logo_stamp.size, qr_size, qr_offset)

def weasyl_badge(username, avatar_resizing=Image.ANTIALIAS):
    r = requests.get(
        'https://www.weasyl.com/api/useravatar', params={'username': username})
    resp = r.json()
    if resp['error']['code'] != 0:
        raise AvatarFetchError(resp['error'])

    back = badge_back.copy()
    qr = qrcode.QRCode(
        error_correction=qrcode.constants.ERROR_CORRECT_H, border=1)
    qr.add_data('https://weasyl.com/~%s' % (username,))<commit_msg>Normalize the weasyl link.<commit_after>from fractions import Fraction
from cStringIO import StringIO

from PIL import Image, ImageDraw, ImageFont
import qrcode
import requests


museo = ImageFont.truetype('Museo500-Regular.otf', 424)
badge_back = Image.open('badge-back.png')
logo_stamp = Image.open('logo-stamp.png')

qr_size = 975, 975
qr_offset = 75, 75
name_color = 6, 155, 192
text_bounds = 735, 125
text_offset = 365, 1155
avatar_bounds = 282, 282
avatar_offset = 49, 1131


class AvatarFetchError(Exception):
    pass


def draw_text(text, color, fit_size):
    text_size = museo.getsize(text)
    img = Image.new('RGBA', text_size, color + (0,))
    draw = ImageDraw.Draw(img)
    draw.text((0, 0), text, color + (255,), font=museo)
    width, height = img.size
    fit_width, fit_height = fit_size

    width_ratio = Fraction(width, fit_width)
    height_ratio = Fraction(height, fit_height)
    if width_ratio > height_ratio:
        new_size = fit_width, int(height / width_ratio)
    else:
        new_size = int(width / height_ratio), fit_height

    return img.resize(new_size, Image.ANTIALIAS)

def center(size, fit_size, offset):
    w, h = size
    fw, fh = fit_size
    x, y = offset
    return x + (fw - w) // 2, y + (fh - h) // 2

logo_pos = center(logo_stamp.size, qr_size, qr_offset)

def weasyl_sysname(target):
  return ''.join(i for i in target if i.isalnum()).lower()

def weasyl_badge(username, avatar_resizing=Image.ANTIALIAS):
    r = requests.get(
        'https://www.weasyl.com/api/useravatar', params={'username': username})
    resp = r.json()
    if resp['error']['code'] != 0:
        raise AvatarFetchError(resp['error'])

    back = badge_back.copy()
    qr = qrcode.QRCode(
        error_correction=qrcode.constants.ERROR_CORRECT_H, border=1)
    qr.add_data('https://weasyl.com/~%s' % (weasyl_sysname(username),))
{'fraction_non_alphanumeric': 0.12949039264828738, 'fraction_numerical': 0.03230297967140072, 'mean_word_length': 3.7325428194993413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '558156', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1302, 'n_words': 302}