Example #1
0
def test_list_endpoint():
    assert (
        BaseAPI.join_base_and_endpoint("https://example.com/v1/", ["test", "def"]) == "https://example.com/v1/test/def"
    )
    assert (
        BaseAPI.join_base_and_endpoint("https://example.com/v1", ["test", "def"]) == "https://example.com/v1/test/def"
    )
Example #2
0
def download_logo(twitch_helix_api, streamer, streamer_id):
    logo_url = twitch_helix_api.get_profile_image_url(streamer_id)

    logo_raw_path = f"static/images/logo_{streamer}.png"

    # returns bytes
    logo_image_bytes = BaseAPI(None).get_binary(logo_url)

    # write full-size image...
    with open(logo_raw_path, "wb") as logo_raw_file:
        logo_raw_file.write(logo_image_bytes)
Example #3
0
def download_sub_badge(twitch_badges_api, streamer, streamer_id,
                       subscriber_badge_version):
    try:
        subscriber_badge = twitch_badges_api.get_channel_subscriber_badge(
            streamer_id, subscriber_badge_version)
    except BadgeNotFoundError as e:
        log.warn(f"Unable to download subscriber badge: {e}")
        return

    subscriber_badge_path = f"static/images/badge_sub_{streamer}.png"

    # returns bytes
    subscriber_badge_bytes = BaseAPI(None).get_binary(
        subscriber_badge.image_url_1x)

    # write image...
    with open(subscriber_badge_path, "wb") as subscriber_badge_file:
        subscriber_badge_file.write(subscriber_badge_bytes)
Example #4
0
def download_logo(twitch_helix_api: TwitchHelixAPI,
                  streamer: UserBasics) -> None:
    logo_url = twitch_helix_api.get_profile_image_url(streamer.id)

    if logo_url is None:
        log.warn(
            f"Failed to query Twitch API for the profile image url of streamer {streamer.login}"
        )
        return

    logo_raw_path = f"static/images/logo_{streamer.login}.png"

    # returns bytes
    logo_image_bytes = BaseAPI(None).get_binary(logo_url)

    # write full-size image...
    with open(logo_raw_path, "wb") as logo_raw_file:
        logo_raw_file.write(logo_image_bytes)
Example #5
0
def download_logo(twitch_helix_api, streamer, streamer_id):
    logo_url = twitch_helix_api.get_profile_image_url(streamer_id)

    logo_raw_path = f"static/images/logo_{streamer}.png"
    logo_tn_path = f"static/images/logo_{streamer}_tn.png"

    # returns bytes
    logo_image_bytes = BaseAPI(None).get_binary(logo_url)

    # write full-size image...
    with open(logo_raw_path, "wb") as logo_raw_file:
        logo_raw_file.write(logo_image_bytes)

    # decode downloaded image
    read_stream = BytesIO(logo_image_bytes)
    pil_image = Image.open(read_stream)

    # downscale and save the thumbnail
    pil_image.thumbnail((64, 64), Image.ANTIALIAS)
    pil_image.save(logo_tn_path, "png")
Example #6
0
 def __init__(self, created_at, **options):
     self.id = None
     self.title = options.get("title", "NO TITLE")
     self.stream_start = BaseAPI.parse_datetime(created_at)
     self.stream_end = None
     self.ended = False
Example #7
0
def test_list_endpoint_escaping():
    assert (
        BaseAPI.join_base_and_endpoint("https://example.com/v1/", ["test", "/some Data/"])
        == "https://example.com/v1/test/%2Fsome%20Data%2F"
    )
Example #8
0
def test_string_endpoint_no_leading_slash():
    assert BaseAPI.join_base_and_endpoint("https://example.com/v1/", "test/def") == "https://example.com/v1/test/def"
    assert BaseAPI.join_base_and_endpoint("https://example.com/v1/", "/test/def") == "https://example.com/v1/test/def"
    assert BaseAPI.join_base_and_endpoint("https://example.com/v1", "test/def") == "https://example.com/v1/test/def"
    assert BaseAPI.join_base_and_endpoint("https://example.com/v1", "/test/def") == "https://example.com/v1/test/def"
Example #9
0
def test_safebrowsing():
    assert (
        BaseAPI.join_base_and_endpoint("https://safebrowsing.googleapis.com/v4/", "/threatMatches:find")
        == "https://safebrowsing.googleapis.com/v4/threatMatches:find"
    )
Example #10
0
def test_list_endpoint_with_int_path_segment():
    assert (
        BaseAPI.join_base_and_endpoint("https://example.com/v1", ["test", 1234]) == "https://example.com/v1/test/1234"
    )
Example #11
0
def test_respects_passed_scheme():
    assert BaseAPI.fill_in_url_scheme("//example.com",
                                      "wss") == "wss://example.com"
Example #12
0
def test_fills_in_relative_url():
    assert BaseAPI.fill_in_url_scheme("//example.com") == "https://example.com"
Example #13
0
def test_does_not_change_non_relative_urls():
    assert BaseAPI.fill_in_url_scheme(
        "http://example.com") == "http://example.com"