-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path07-oxygen.py
31 lines (23 loc) · 970 Bytes
/
07-oxygen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of Python Challenge Solutions
# https://github.com/scorphus/PythonChallengeSolutions
# Licensed under the BSD-3-Clause license:
# https://opensource.org/licenses/BSD-3-Clause
# Copyright (c) 2018-2020, Pablo S. Blum de Aguiar <scorphus@gmail.com>
# http://www.pythonchallenge.com/pc/def/oxygen.html
from auth import get_last_src_url
from auth import read_url
from io import BytesIO
from itertools import islice
from itertools import takewhile
import png
url = "http://www.pythonchallenge.com/pc/def/oxygen.html"
png_content = read_url(get_last_src_url(url))
png_reader = png.Reader(BytesIO(png_content))
_, height, content, *_ = png_reader.read()
middle_row = next(islice(content, height // 2, height // 2 + 1))
message = "".join(
chr(n) for n in takewhile(lambda n: n != ord("]"), islice(middle_row, 5, None, 28))
)
print("".join(chr(int(d)) for d in message.split("[", 1)[-1].split(", ")))