Ejemplo n.º 1
0
def download_logo(streamer):
    import urllib
    from pajbot.apiwrappers import TwitchAPI

    twitchapi = TwitchAPI()
    try:
        data = twitchapi.get(['users', streamer], base='https://api.twitch.tv/kraken/')
        log.info(data)
        if data:
            logo_raw = 'static/images/logo_{}.png'.format(streamer)
            logo_tn = 'static/images/logo_{}_tn.png'.format(streamer)
            with urllib.request.urlopen(data['logo']) as response, open(logo_raw, 'wb') as out_file:
                data = response.read()
                out_file.write(data)
                try:
                    from PIL import Image
                    im = Image.open(logo_raw)
                    im.thumbnail((64, 64), Image.ANTIALIAS)
                    im.save(logo_tn, 'png')
                except:
                    log.exception('Unhandled exception in download_logo PIL shit')
            log.info('set logo')
            return True
    except:
        log.exception('Unhandled exception in download_logo')
    return False
Ejemplo n.º 2
0
def download_logo(client_id, streamer):
    import urllib
    from pajbot.apiwrappers import TwitchAPI

    twitchapi = TwitchAPI(client_id)
    try:
        data = twitchapi.get(["users", streamer],
                             base="{}/kraken/".format(
                                 os.environ.get("APIPROXY_HOST",
                                                "http://127.0.0.1:7221")))
        log.info(data)
        if data:
            logo_raw = "static/images/logo_{}.png".format(streamer)
            logo_tn = "static/images/logo_{}_tn.png".format(streamer)
            with urllib.request.urlopen(data["logo"]) as response, open(
                    logo_raw, "wb") as out_file:
                data = response.read()
                out_file.write(data)
                try:
                    from PIL import Image

                    im = Image.open(logo_raw)
                    im.thumbnail((64, 64), Image.ANTIALIAS)
                    im.save(logo_tn, "png")
                except:
                    log.exception(
                        "Unhandled exception in download_logo PIL shit")
            log.info("set logo")
            return True
    except:
        log.exception("Unhandled exception in download_logo")
    return False
Ejemplo n.º 3
0
if 'web' not in config:
    log.error('Missing [web] section in config.ini')
    sys.exit(1)

if 'pleblist_password_salt' not in config['web']:
    salt = generate_random_salt()
    config.set('web', 'pleblist_password_salt', salt.decode('utf-8'))

if 'secret_key' not in config['web']:
    salt = generate_random_salt()
    config.set('web', 'secret_key', salt.decode('utf-8'))

if 'logo' not in config['web']:
    twitchapi = TwitchAPI()
    try:
        data = twitchapi.get(['users', config['main']['streamer']], base='https://api.twitch.tv/kraken/')
        log.info(data)
        if data:
            logo_raw = 'static/images/logo_{}.png'.format(config['main']['streamer'])
            logo_tn = 'static/images/logo_{}_tn.png'.format(config['main']['streamer'])
            with urllib.request.urlopen(data['logo']) as response, open(logo_raw, 'wb') as out_file:
                data = response.read()
                out_file.write(data)
                try:
                    from PIL import Image
                    im = Image.open(logo_raw)
                    im.thumbnail((64, 64), Image.ANTIALIAS)
                    im.save(logo_tn, 'png')
                except:
                    pass
            config.set('web', 'logo', 'set')
Ejemplo n.º 4
0
if 'web' not in config:
    log.error('Missing [web] section in config.ini')
    sys.exit(1)

if 'pleblist_password_salt' not in config['web']:
    salt = generate_random_salt()
    config.set('web', 'pleblist_password_salt', salt.decode('utf-8'))

if 'secret_key' not in config['web']:
    salt = generate_random_salt()
    config.set('web', 'secret_key', salt.decode('utf-8'))

if 'logo' not in config['web']:
    twitchapi = TwitchAPI()
    try:
        data = twitchapi.get(['users', config['main']['streamer']], base='https://api.twitch.tv/kraken/')
        log.info(data)
        if data:
            logo_raw = 'static/images/logo_{}.png'.format(config['main']['streamer'])
            logo_tn = 'static/images/logo_{}_tn.png'.format(config['main']['streamer'])
            with urllib.request.urlopen(data['logo']) as response, open(logo_raw, 'wb') as out_file:
                data = response.read()
                out_file.write(data)
                try:
                    from PIL import Image
                    im = Image.open(logo_raw)
                    im.thumbnail((64, 64), Image.ANTIALIAS)
                    im.save(logo_tn, 'png')
                except:
                    pass
            config.set('web', 'logo', 'set')