-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path19-bin.py
31 lines (22 loc) · 1 KB
/
19-bin.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/hex/bin.html
from auth import get_nth_comment
import email
import io
import wave
url = "http://www.pythonchallenge.com/pc/hex/bin.html"
page_data = get_nth_comment(url, 1).strip()
email_message = email.message_from_string(page_data)
payload = email_message.get_payload()[0].get_payload(decode=True)
with wave.open(io.BytesIO(payload)) as in_wav, wave.open("19-bin.wav", "wb") as out_wav:
out_wav.setnchannels(in_wav.getnchannels())
out_wav.setsampwidth(in_wav.getsampwidth())
out_wav.setframerate(in_wav.getframerate())
out_wav.writeframesraw(b"@" + in_wav.readframes(in_wav.getnframes()))
print("Open 19-bin.wav only to listen the word “idiot”")